float XMatrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
float YMatrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
float ZMatrix[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
void Control() // called once every frame
{
if(keys[VK_LEFT])
{
xtheta ++;
}
if(keys[VK_RIGHT])
{
xtheta --;
}
if(keys[VK_DOWN])
{
ztheta --;
}
if(keys[VK_UP])
{
ztheta ++;
}
if(keys[''Z''])
{
ytheta --;
}
if(keys[''X''])
{
ytheta ++;
}
ZMatrix[0] = cos((ztheta) * (3.14159 / 180));
ZMatrix[1] = -sin((ztheta) * (3.14159 / 180));
ZMatrix[4] = sin((ztheta) * (3.14159 / 180));
ZMatrix[5] = cos((ztheta) * (3.14159 / 180));
YMatrix[0] = cos((ytheta) * (3.14159 / 180));
YMatrix[2] = sin((ytheta) * (3.14159 / 180));
YMatrix[8] = -sin((ytheta) * (3.14159 / 180));
YMatrix[10] = cos((ytheta) * (3.14159 / 180));
XMatrix[5] = cos((xtheta) * (3.14159 / 180));
XMatrix[6] = -sin((xtheta) * (3.14159 / 180));
XMatrix[9] = sin((xtheta) * (3.14159 / 180));
XMatrix[10] = cos((xtheta) * (3.14159 / 180));
}
// DrawGLScene...
Control();
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -50.0f);
glMultMatrixf(ZMatrix);
glMultMatrixf(YMatrix);
glMultMatrixf(XMatrix);
// draw object;
Yet More Gimbal Locking...
Hello,
I''m having difficulty getting my 3d rotations to work properly. I''m storing the rotation as 3 matrices which are then multed together before the object is rendered. Problem is, the axis are still flipping with each other and generally going out of whack...
Heres the relevent code...
Whats going on? Why am I still getting the evil gimbal with matrices?
As long as you will be doing your transformation in three separate steps, you will get gimbal locking. Whether you use glRotate() or glMultMatrix() does not change this.
You need to make the transformation in one, single, step.
Quaternions, quaternions, quaternions, quaternions !
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
You need to make the transformation in one, single, step.
Quaternions, quaternions, quaternions, quaternions !
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
quaternions.
(just thought I''d back fruny up there).
Actually you can avoid gimbal lock without them (e.g. using axis-angle) but you need them to interpolate rotations which you will most definitely want to do. If you absolutely insist on using Euler angles (don''t) you can avoid gimbal lock by writing routines which check if a rotation is greater than 90 and, if so, split the operation into rotations of less than 90, resolving to a single matrix at each step. This is a lame hack which you shouldn''t bother with. Don''t even know why I mentioned it really.
Geocyte Has Committed Suicide.
(just thought I''d back fruny up there).
Actually you can avoid gimbal lock without them (e.g. using axis-angle) but you need them to interpolate rotations which you will most definitely want to do. If you absolutely insist on using Euler angles (don''t) you can avoid gimbal lock by writing routines which check if a rotation is greater than 90 and, if so, split the operation into rotations of less than 90, resolving to a single matrix at each step. This is a lame hack which you shouldn''t bother with. Don''t even know why I mentioned it really.
Geocyte Has Committed Suicide.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement