Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  When calling rotate()...  (Read 1046 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Ninja


Medals: 35
Projects: 5


I always win!


« Posted 2005-10-30 01:05:37 »

What is rotate doing here?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
Graphics2D g = (Graphics2D)strategy.getDrawGraphics();

// paint background and other images
...

// Now paint a rotated image.
g.rotate(...);
g.drawImage(...);
g.rotate(...);


// Display results
strategy.show();


Is the first rotate() call rotating the whole screen that has been draw, then draw the image I want rotated, and then rotate the whole screen back?
Isn't this a big overhead? What's the best way just to rotate one picture?

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline appel

JGO Ninja


Medals: 35
Projects: 5


I always win!


« Reply #1 - Posted 2005-10-30 04:53:24 »

Bump.

Found it out.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #2 - Posted 2005-10-30 09:50:50 »

Would you like to explain what you found out, it might help others eventually Smiley

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #3 - Posted 2005-10-30 14:37:05 »

I'm not an expert here, but I believe it works as follows:

whenever an image is drawn, that drawing operation will take considerably more time because of the rotation. Setting the transform poses no considerable impact on rendering performance AFAIK. It is, however, wrong to rotate back after the image has been drawn. You should store the transform of the Graphics object before rotating, THEN rotate, draw, and SET the transform back to its initial state. Otherwise there may be floating point stuff which makes the whole screen SLIGHTLY rotated, and although that's probably not visible, it IS an error, and could degrade rendering performance considerably (since everything would still have to be rotated by a very small amount).
Offline appel

JGO Ninja


Medals: 35
Projects: 5


I always win!


« Reply #4 - Posted 2005-10-30 17:10:24 »

There's always a better way to do things, I guess Smiley


But, the rotate/draw/rotate works as follows:

1  
2  
3  
4  
5  
6  
7  
8  
rotate(Math.PI); // this sets the "rotation mode", that is, anything that is drawn
                  // after this will be drawn according to that rotation. It doesn't rotate the whole canvas as I thought.

drawImage(...); // this simply draws the image on the canvas, but since you've
             // set the rotation angle then it will be drawn according to that.

rotate(-Math.PI); // this is a negative operation of the first rotate() call, it cancels out whatever you defined previously,
              //and images drawn after this will be drawn with no rotation.



Personally I don't like this method. I'd like to apply some rotation-object when I draw a image, like: drawImage(image, angle);

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline g666

Junior Member





« Reply #5 - Posted 2005-10-30 21:14:55 »

You could use AffineTransform if you need to rotate the image around a specified point.

desperately seeking sanity
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #6 - Posted 2005-10-30 21:45:41 »

You could cast the Graphics object to java.awt.Graphics2D, then use

1  
drawImage(Image img, AffineTransform xform, ImageObserver obs)


Then you will just have to specify the desired position of the image through an affine transform, i.e. transform.translate(xPos, yPos);

I believe that the procedure described above would be equivalent in terms of efficiency. Like I said, rotating takes a lot of time while manipulating the AffineTransform (involving, like, 6 numbers) is negligible in comparison.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (121 views)
2013-05-17 21:29:12

alaslipknot (129 views)
2013-05-16 21:24:48

gouessej (159 views)
2013-05-16 00:53:38

gouessej (151 views)
2013-05-16 00:17:58

theagentd (164 views)
2013-05-15 15:01:13

theagentd (149 views)
2013-05-15 15:00:54

StreetDoggy (193 views)
2013-05-14 15:56:26

kutucuk (217 views)
2013-05-12 17:10:36

kutucuk (216 views)
2013-05-12 15:36:09

UnluckyDevil (219 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.114 seconds with 20 queries.