Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 1252 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Posted 2005-10-29 23: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 Wizard


Medals: 50
Projects: 4


I always win!


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

Bump.

Found it out.

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

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2005-10-30 08: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 13: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 Wizard


Medals: 50
Projects: 4


I always win!


« Reply #4 - Posted 2005-10-30 16: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 20: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 20: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.

 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (18 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (70 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!