Advertisement

3D World - movement as a state machine ???

Started by June 16, 2004 02:00 AM
22 comments, last by Yaniv Shekel 20 years, 5 months ago
Hi I'm having trouble with the yaw, maybe i'm rotating the wrong axes. Which are they?
Yaw, pitch and roll come from the aircraft world AFAIK. Think of a 'plane. Pitch is the up and down of the nose. Roll is the side to side rotation of the aircraft, along the fuselage. (left wing up, right down etc.,) Yaw is the heading of the aircraft, as in left and right.

Obviously, planes actually use combinations of these to move, but that's a different thing.

the actual mapping of axes onto these is code specific, however supposing the plane fracing into into the screen and z is into the screen, x is left and y is up, Pitch is rotation about the x axis, roll is rotation about the y axis and yaw is rotation about the z axis.
-- Jonathan
Advertisement
Er, no.

Using the coordinate convention that you said. Yaw is rotating along the y axis (up), and roll is rotating along the z axis (front).
If at first you don't succeed, redefine success.
Well I decided to go at it simply and wrote a short program that uses openGL to calculate the vectors as I understood them from python_regious. For now its supposed to take me anywhere on the xz plane. It doesn't for some reason it screws up my vectors. I don't understand why. I'll post an excerpt of it and maybe you guys/gals can help me.


int movement = 0;void initVectors(){        side.x = 1.0;        side.y = 0.0;        side.z = 0.0;        up.x = 0.0;        up.y = 1.0;        up.z = 0.0;        forward.x = 0.0;        forward.y = 0.0;        forward.z = 1.0;        position.x = 0.0;        position.y = 0.0;        position.z = 0.0;}void recalcAroundUp(GLdouble angle){        GLdouble matrix[16] = {0};        matrix[0] = side.x;        matrix[1] = side.y;        matrix[2] = side.z;        matrix[4] = up.x;        matrix[5] = up.y;        matrix[6] = up.z;        matrix[8] = forward.x;        matrix[9] = forward.y;        matrix[10] = forward.z;        matrix[15] = 1;        glPushMatrix();        glLoadMatrixd(matrix);        glRotated(angle, up.x, up.y, up.z);        // COULD THIS BE THE PROBLEM        glGetDoublev (GL_MODELVIEW_MATRIX, matrix);        glPopMatrix();        for (int i = 0; i < 16; i++)        {                if ((matrix > 0 && matrix < EPSILON) ||                        (matrix < 0 && matrix > -EPSILON))                        matrix = 0;        }        side.x = matrix[0];        side.y = matrix[1];        side.z = matrix[2];        up.x = matrix[4];        up.y = matrix[5];        up.z = matrix[6];        forward.x = matrix[8];        forward.y = matrix[9];        forward.z = matrix[10];}void recalcMoveForward(){        position.x += -forward.x * movement;        position.y += -forward.y * movement;        position.z += forward.z * movement;}void renderCube(GLdouble trans_x, GLdouble trans_y, GLdouble trans_z){        glPushMatrix();        glLoadIdentity();        glRotated(angle, up.x, up.y, up.z);        glTranslated(trans_x, trans_y, trans_z);        glTranslated(position.x, position.y, position.z);        glBegin(GL_QUADS);                /* start drawing the cube.*/...}GLvoid DrawGLScene(){  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  renderCube( 0, 0, -8);...}void NormalKey(GLubyte key, GLint x, GLint y){    switch ( key )    {         case '/': // forward key                 movement = 1;                 recalcMoveForward();                 glutPostRedisplay();                 break;         case '0': // backward key                ...         case '6': // right key                 amountTurnedSide++;                 angle = ANGLE * amountTurnedSide;                 if (angle > 360.0)                         angle -= 360.0;                 else if (angle < 0)                        angle = 360.0 + angle;                 recalcAroundUp(angle);                 glutPostRedisplay();                 break;         ...}

This topic is closed to new replies.

Advertisement