Jump to content
  • Advertisement
Sign in to follow this  
darkchrono4

[java] AffineTransform Problem

This topic is 4157 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

                AffineTransform saved = g2.getTransform();
		 
		AffineTransform xform = new AffineTransform();	
		
		for (int i=0; i<4; i++) {
			angle = Math.toRadians(i*90);
			g2.setColor(colors);
			xform.setTransform(saved);
			xform.translate(100, 100);
			g2.transform(xform);
			g2.fill(path);
			g2.setColor(Color.BLACK);			
			g2.draw(path);
		}
		
		g2.setTransform(saved);

I would think this code would draw my four shapes one on top of each other. What ends up happening is they seem to be 100 pixels apart from each other. As you can see I get the current matrix before I draw and reload it before I draw each shape so it should be a clear matrix each time. But it acts like its drawing the shape on top of the previous shape matrix.

Share this post


Link to post
Share on other sites
Advertisement
The transform object does not hold the state of the display. It just tells the display to do something. Since you were not resetting the display, you were transforming the display 4 times. Here is what you need.


Graphics2D g2 = (Graphics2D)g;
AffineTransform saved = g2.getTransform();

AffineTransform xform = AffineTransform.getTranslateInstance(100, 100);

for (int i=0; i<4; i++) {
angle = Math.toRadians(i*90);
g2.setColor(colors);
g2.transform(xform);
g2.fill(path);
g2.setColor(Color.BLACK);
g2.draw(path);
g2.setTransform(saved);
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!