Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  Draw rotated 2D Sprite at position XY on screen  (Read 1640 times)
0 Members and 1 Guest are viewing this topic.
Offline jgf

Junior Newbie





« Posted 2012-08-05 20:32:45 »

Hi there,

I'm quite new to OpenGL programming (started yesterday) and I'm pretty sure this is a common problem. However I could not find a decent resource that explains it in detail. Most tutorial aim at 3D stuff - or as I'm new to this area I simply do not know the right words to feed to google.

So heres my problem. Drawing a 2D sprite at position x, y at the screen using OpenGL works pretty forward. But if I want to draw the same sprite rotated e.g. by angle 30* theres where the hassle starts.

Without rotation I'm using glTranslate to move position x,y and then start drawing stuff.

With rotation I tried using glRotate to rotate my sprite around the Z axis. Then I use glTranslate to move to my desired position and start drawing.
So the problem seems to be, that glRotate rotates the whole coordinate system, so my old position x,y is no longer at the same place on the screen.
This means I would have to transform x, y to new coordinates in the rotated coordinate system that match the old screen position.

This seems a bit awkward to me. So I'm wondering if this is the right thing to do or if there are easier/better ways to achieve this simple task of drawing a sprite at a certain position. How would an experienced OpenGL programmer solve my problem?
Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2012-08-05 20:46:41 »

Yes. Smiley

You nearly solved your problem.
The simple solution is: Try translating and THEN rotating. Wink

I think... there is nothing more to say, so... I'm pretty sure that works Cheesy

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline jgf

Junior Newbie





« Reply #2 - Posted 2012-08-05 20:54:02 »

Oh my god. I'm feeling really stupid now  persecutioncomplex. Looks like its time for a programming break Wink

Thanks never the less  Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2012-08-05 21:00:22 »

Oh my god. I'm feeling really stupid now  persecutioncomplex. Looks like its time for a programming break Wink

Thanks never the less  Grin

Nah.. You're not stupid. That is a very common mistake Wink
Rotating is the first very hard thing in OpenGL programming Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline sproingie
« Reply #4 - Posted 2012-08-05 23:24:45 »

You got the theory right: glRotate rotates the entire coordinate system.  That's hardly stupid if you figured that out independently. Smiley

Lots of smilies in this thread.  I like Smiley


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.

xsi3rr4x (32 views)
2014-04-15 18:08:23

BurntPizza (29 views)
2014-04-15 03:46:01

UprightPath (44 views)
2014-04-14 17:39:50

UprightPath (27 views)
2014-04-14 17:35:47

Porlus (44 views)
2014-04-14 15:48:38

tom_mai78101 (65 views)
2014-04-10 04:04:31

BurntPizza (125 views)
2014-04-08 23:06:04

tom_mai78101 (225 views)
2014-04-05 13:34:39

trollwarrior1 (190 views)
2014-04-04 12:06:45

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!