• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

David20321

Multiple Rotations Around X,Y,Z

12 posts in this topic

Ok here''s my problem, I have an xrotation,yrotation and zrotation for my object. The problem is if I rotate in any direction all the rotation axes change. If I do a 90 degree rotation on the x-axis, the z-axis becomes the y-axis and the y-axis becomes the z-axis, thus throwing off all my rotations. Is there any way to fix this? I don''t want to have to go through every vertex applying my custom rotation code because it would not be hardware accelerated (I think) -David-
0

Share this post


Link to post
Share on other sites
make sure you use glPushMatrix() and glPopMatrix() between rotations as well as glTranslatef()
0

Share this post


Link to post
Share on other sites
No, no, I don''t think that''s the problem, what I mean is that right now if I have a cube and I rotate it 45 degrees on the x axis and then 90 degrees on the y axis I want it to be the same as if I rotate it it -45 degrees on the x axis and then rotate it 180 degrees on the y axis. I want it to rotate around the global axes, not the local ones.

-David-
0

Share this post


Link to post
Share on other sites
the problem is called ''gimbal lock'' its caused by using eular angles to represent rotations.
use a different method to store rotations eg matrices or quaternions
0

Share this post


Link to post
Share on other sites
What you need to do is keep a rotation matrix for the object. When you want to rotate it, just convert your angle and axis (in normal form) of rotation to a quaternion, then convert that to a rotation matrix, then rotate your original rotation matrix by that rotation matrix.

When drawing the object, use glMultMatrix to muliply the current modelview matrix by your stored rotation matrix.

I think there is also a way to do it without converting to a quaternion first, but I''m not sure of the maths.

All of the operations described above can be found in the
Matrix and Quaternion FAQ.
0

Share this post


Link to post
Share on other sites
The key is to specify rotations in the local coordsys of the object. This is the way eg. 3dsMax solves the problem. Then you transform the object through it's local to world matrix. The whole thing can be multiplied into a single matrix, so you can get hw acceleration. If you absolutely want to specify rotations in world space, then you have to transform them back to the local coordsys first (using the inverse world matrix), but be sure to use the angle,axis representation otherwise you'll run into the gimbal lock again.

ben:
The code to directly create a matrix from an axis, angle and pivot is:


void mtx_AxisAnglePivotToMatrixH(fvector Axis, float angle, fvector Pivot, matrix4 M)
{
float s, t, c, sx, sy, sz, tx, ty;

c=cos(angle); s=sin(angle); t=1.0-c;
sx=s*Axis.x; sy=s*Axis.y; sz=s*Axis.z;
tx=t*Axis.x; ty=t*Axis.y;

M[0]=tx*Axis.x+c;
M[1]=tx*Axis.y-sz;
M[2]=tx*Axis.z+sy;

M[4]=tx*Axis.y+sz;
M[5]=ty*Axis.y+c;
M[6]=ty*Axis.z-sx;

M[8]=tx*Axis.z-sy;
M[9]=ty*Axis.z+sx;
M[10]=t*Axis.z*Axis.z+c;

M[12]=Pivot.x-M[0]*Pivot.x-M[4]*Pivot.y-M[8]*Pivot.z;
M[13]=Pivot.y-M[1]*Pivot.x-M[5]*Pivot.y-M[9]*Pivot.z;
M[14]=Pivot.z-M[2]*Pivot.x-M[6]*Pivot.y-M[10]*Pivot.z;

M[3]=M[7]=M[11]=0.0;
M[15]=1.0;
}


A.H aka Blueshift


Edited by - Blueshift on July 26, 2001 10:13:17 AM
0

Share this post


Link to post
Share on other sites
I don''t think hes talking about gimbal lock however, what i think the problem is is the order of rotations. It seems to me that glRotatef does not multiply the current matrix by the new matrix, but multiplies the rotation matrix by the current matrix.
i.e.
if R is the rotation matrix, and M is the current matrix (modelview or whatever ur using).
It seems glRotate does this M = RxM
NOT M=MxR as it says it does
(However this may be complete crap.)
This would explain why in all of the samples i''ve done you Translate then rotate which normally would cause a translation when you rotate as you are not rotating about the origin.

normally M = Rotation x Translation
{
glTranslate
glRotatef
}
| | |
| +---+ | +---+
| | | | | | |
+-----+ ---|-+-|--- ------+--|---|--
-----|--+--|--- ==> | | | ==> | | |
+--|--+ +---+ | +---+
| | |
| |
|

or M = Translation x Rotation
{
glRotatef
glTranslate
} |
| | +-+-+
| | | | |
| | | | |
+-----+ | +-----+ +-+-+
-----|--+--|--- ==> -----+--|-----|-- ==> |
+--|--+ | +-----+ -------+-------
| | |
| | |
| | |

Try reversing your rotation equations. It may work (or possibly your computer will just explode)
0

Share this post


Link to post
Share on other sites
Stinger:
No, glRotate is doing M = M * R.
The reason why everything seems reversed is in the nature of matrix math: The matrix that is multiplied _last_ will be applied _first_ to the object.

Eg.
M = S * R1 * T * R2

multiplying a vertex by this matrix will cause the following (in this order !):
- rotate the vertex by R2
- translate it by T
- rotate it by R1
- scale it by S

Everything is reversed. This behaviour is very important when doing object transformation hierarchies, this is where glPushMatrix and glPopMatrix are extremly usefull.

A.H aka Blueshift

0

Share this post


Link to post
Share on other sites
Blueshift:
what''s a pivot, and why is it needed? Surely just an angle and axis is enough to describe a rotation?
0

Share this post


Link to post
Share on other sites
ben:

>what''s a pivot, and why is it needed? Surely just an angle and axis is enough to describe a rotation?

Yes, angle and axis are enough to describe a rotation around an axis that goes through the origin. If you don''t want to rotate through the origin but through a certain point of rotation, then this point is a pivot.

It''s equivalent to:
glTranslate(Pivot.x, Pivot.y, Pivot.z)
glRotate(...)
glTranslate(-Pivot.x, -Pivot.y, -Pivot.z)

It is just convenient and faster to have it all in a single matrix, saves 2 matrix multiplies

Just set M12, M13 and M14 to 0, if you don''t like it.

A.H aka Blueshift
0

Share this post


Link to post
Share on other sites
Yeah i think it''s because i used to do my matricies differently using a column based thingy.

[ a b c d]
[ e f g h]
[ i j k l]
[ m n o p]

where
''x = ax + ey + iz + m
''y = bx + fy + jz + n
''z = cx + gy + kz + o
''w = dx + hy + lz + p


This way i think it works forward not backward. I hadn''t really thought about it going backward
0

Share this post


Link to post
Share on other sites
Yep, OpenGL uses row-major transformation matrices. You have to invert your multiplication order to get the same thing. The advantage is that you can directly load your own matrices with glLoadMatrix() or glMultMatrix() instead of converting first.
Don''t mix row- and column-based matrices, if you want to avoid nightlong bug-tracking sessions

A.H aka Blueshift
0

Share this post


Link to post
Share on other sites