Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

[java] AffineTransform Problem

Started by darkchrono4 Feb 1, 2007 at 9:10 PM 0 replies 700+ views
Original Post
darkchrono4
darkchrono4

                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.
CaptainJester
CaptainJester
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);}
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.