PDA

View Full Version : successive rotation

flashcs5
07-13-2012, 09:45 AM
hello,
i am kind of new to openGL,and i faced this biiig probleme

so let's say i rotate my cube arround X , when i rotate again on Y it ends up rotating arround Z :dejection:
i did some research andi found out that glrotatef rotate evrything including the axis

so basically what i want is a way to rotate arround a specific axis all the time (world axis in my case since i need to make a model for rubik's cube 3X3X3 )

thanks in advance

flashcs5
07-15-2012, 01:32 AM
is my question more than beginner level or what???????????

Dark Photon
07-15-2012, 06:26 AM
You need to do some basic reading on how coordinate frame transforms work. They are applied to the local (then-current) coordinate frame, not any given global coordinate frame.

The OpenGL Programming Guide has a good description of how to think about successive modeling transforms, among others.

flashcs5
07-15-2012, 08:06 AM
thank you for responding,but it would be helpfull if you give me more direct information or reading matrial
(btw I can have axess to almost any book so don't feel restrained when giving recomondation)

Dark Photon
07-15-2012, 12:46 PM
thank you for responding,but it would be helpfull if you give me more direct information or reading matrial
Sure thing.

OpenGL Programming Guide (http://www.amazon.com/OpenGL-Programming-Guide-Official-Learning/dp/0321773039/ref=sr_1_1?s=books&ie=UTF8&qid=1342382043&sr=1-1&keywords=opengl+programming+guide+8th+edition): "Viewing" chapter (Chapter 3 in my old 4th ed) -- focus particularly on the "Thinking about Transformations" section (A quick google will turn this up on-line. For instance here (http://fly.cc.fer.hr/%7Eunreal/theredbook/chapter03.html))

If you have any other transformation-related questions, look for the answers in there.

For a good on-line quick ref guide to OpenGL transforms:

OpenGL Transformation (http://www.songho.ca/opengl/gl_transform.html) (Song Ho Ahn)

Googling around, looks like:

3D Math Primer for Graphics and Game Development (http://my.safaribooksonline.com/book/programming/game-programming/9781556229114/matrices-and-linear-transformations/section_8.1[/url) may have some good stuff in Section 8.1

but don't have it handy here to read so I can't vouch for it.

Carmine
07-15-2012, 05:27 PM
...i rotate my cube arround X , when i rotate again on Y it ends up rotating arround Z This is a very common problem encountered by people new to OpenGL or computer graphics in general.
The easiest way to code up rotations is to do something like ..

glRotatef (xrot, 1,0,0);
glRotatef (yrot, 0,1,0);
glRotatef (zrot, 0,0,1);

Draw_Objects ();
This results in an Euler rotation sequence, where the successive rotations are not necessarily around body axes or world axes. Most of the time this is o.k., but in special cases (which yours seems to be), you may have to resort to something more involved. With the help of another contributor, I posted some OpenGL code that shows a way to do both world or object space rotations. If you take the time to look at it, you'll see that it is quite a bit more involved than the code above. Good luck ...

http://www.mfwerner.addr.com/OpenGL/Special_Rotations/Source.c

flashcs5
07-16-2012, 09:16 AM
thankx the both of you Carmine and Dark Photom
sound like i have alot of reading to do,and the code is exactly what i want to do (the screen space rotate part )