Sign in to follow this  
WiredCat

How to obtain FRONT, UP vec from yaw pitch roll angles

Recommended Posts

hello there,

I want to create basic flight sim, but i have a problem with calculating vectors from pitch , roll, yaw angles

[media]http://www.youtube.com/watch?v=etaxekOHCvE[/media]




I use a rotation formula from one of books

For non zero CENTER_POINT

[quote]void __fastcall TachoGLModel::RotateModel(int dimension, float angle)
{

int i;

t3dpoint p,addme;

for (i = 0; i < VBO_V.Length; i++) {
p = vectors_add(VBO_V[i], reverse_point(CENTER_POINT)); //punkt przeniesiony na srodek bryly

addme = CENTER_POINT;
if (dimension == 0) { //XZ
addme.y = 0.0f;
VBO_V[i].x = cos(angle*imopi)*p.x - sin(angle*imopi)*p.z;
VBO_V[i].z = sin(angle*imopi)*p.x + cos(angle*imopi)*p.z;
}

if (dimension == 1) { //XY
addme.z = 0.0f;
VBO_V[i].x = cos(angle*imopi)*p.x - sin(angle*imopi)*p.y;
VBO_V[i].y = sin(angle*imopi)*p.x + cos(angle*imopi)*p.y;
}

if (dimension == 2) { //ZY
addme.x = 0.0f;
VBO_V[i].z = cos(angle*imopi)*p.z - sin(angle*imopi)*p.y;
VBO_V[i].y = sin(angle*imopi)*p.z + cos(angle*imopi)*p.y;
}

VBO_V[i] = vectors_add(VBO_V[i],addme); //dodaj aby to byla poprawna pozycja

}

}

[/quote]




And everything rotates correctly, but when i changed this code i cant calculate proper vectors, I don't know what i am doing wrong:

if i rotate model with these angles by glRotate everything works fine - i use:

/* XZ */ glRotatef(PHYSIC_MODEL->superpointglop,0.0,1.0,0.0); // YAW angle
/* ZY */ glRotatef(PHYSIC_MODEL->heading,1.0,0.0,0.0); // PITCH angle
/* XY */ glRotatef(PHYSIC_MODEL->glop,0.0,0.0,1.0); // ROLL angle




so i know that i must first rotate by ROLL ANGLE, then by PITCH angle and then by YAW angle but the calculations are wrong :S




can anyody help me with calculations?:)

and i almost forgot imopi equals to

const float pi = 3.1415926535897932384626433832795;

const float imopi = 0.017453292519943295769236907684886; => pi / 180.0f





[quote]void __fastcall WATEK_Z_RYSOWANIEM::Draw()
{
PHYSIC_MODEL->ProcessFrame();

glPushMatrix();

glLoadIdentity();

gluLookAt(kold.x,kold.y,kold.z,kold.x+ksp.x,
kold.y-ksp.y,kold.z-ksp.z,0,1,0);

glTranslatef(PHYSIC_MODEL->pos.x,PHYSIC_MODEL->pos.y,PHYSIC_MODEL->pos.z);
glPushMatrix();
/* XZ */ glRotatef(PHYSIC_MODEL->superpointglop,0.0,1.0,0.0); // YAW angle
/* ZY */ glRotatef(PHYSIC_MODEL->heading,1.0,0.0,0.0); // PITCH angle
/* XY */ glRotatef(PHYSIC_MODEL->glop,0.0,0.0,1.0); // ROLL angle

PHYSIC_MODEL->FRONT.heading = 0.0f;
PHYSIC_MODEL->FRONT.glop = 0.0f;
PHYSIC_MODEL->FRONT.CALCULATE_VEC();


PHYSIC_MODEL->UP.heading = 90.0f;
PHYSIC_MODEL->UP.glop = 0.0f;
PHYSIC_MODEL->UP.CALCULATE_VEC();


PHYSIC_MODEL->RIGHT.heading = 0.0f;
PHYSIC_MODEL->RIGHT.glop = 90.0f;
PHYSIC_MODEL->RIGHT.CALCULATE_VEC();

//XY -> ZY -> XZ
float angle;

//SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM-
angle = PHYSIC_MODEL->glop; //roll
PHYSIC_MODEL->UP.vec.x = cos(angle*imopi)*PHYSIC_MODEL->UP.vec.x - sin(angle*imopi)*PHYSIC_MODEL->UP.vec.y;
PHYSIC_MODEL->UP.vec.y = sin(angle*imopi)*PHYSIC_MODEL->UP.vec.x + cos(angle*imopi)*PHYSIC_MODEL->UP.vec.y;


angle = PHYSIC_MODEL->heading; //pitch
PHYSIC_MODEL->UP.vec.z = cos(angle*imopi)*PHYSIC_MODEL->UP.vec.z - sin(angle*imopi)*PHYSIC_MODEL->UP.vec.y;
PHYSIC_MODEL->UP.vec.y = sin(angle*imopi)*PHYSIC_MODEL->UP.vec.z + cos(angle*imopi)*PHYSIC_MODEL->UP.vec.y;





angle = PHYSIC_MODEL->superpointglop; //yaw
PHYSIC_MODEL->UP.vec.x = cos(angle*imopi)*PHYSIC_MODEL->UP.vec.x - sin(angle*imopi)*PHYSIC_MODEL->UP.vec.z;
PHYSIC_MODEL->UP.vec.z = sin(angle*imopi)*PHYSIC_MODEL->UP.vec.x + cos(angle*imopi)*PHYSIC_MODEL->UP.vec.z;



angle = PHYSIC_MODEL->glop;//roll
PHYSIC_MODEL->FRONT.vec.x = cos(angle*imopi)*PHYSIC_MODEL->FRONT.vec.x - sin(angle*imopi)*PHYSIC_MODEL->FRONT.vec.y;
PHYSIC_MODEL->FRONT.vec.y = sin(angle*imopi)*PHYSIC_MODEL->FRONT.vec.x + cos(angle*imopi)*PHYSIC_MODEL->FRONT.vec.y;
angle = PHYSIC_MODEL->heading;//pitch
PHYSIC_MODEL->FRONT.vec.z = cos(angle*imopi)*PHYSIC_MODEL->FRONT.vec.z - sin(angle*imopi)*PHYSIC_MODEL->FRONT.vec.y;
PHYSIC_MODEL->FRONT.vec.y = sin(angle*imopi)*PHYSIC_MODEL->FRONT.vec.z + cos(angle*imopi)*PHYSIC_MODEL->FRONT.vec.y;
angle = PHYSIC_MODEL->superpointglop;//yaw
PHYSIC_MODEL->FRONT.vec.x = cos(angle*imopi)*PHYSIC_MODEL->FRONT.vec.x - sin(angle*imopi)*PHYSIC_MODEL->FRONT.vec.z;
PHYSIC_MODEL->FRONT.vec.z = sin(angle*imopi)*PHYSIC_MODEL->FRONT.vec.x + cos(angle*imopi)*PHYSIC_MODEL->FRONT.vec.z;



angle = PHYSIC_MODEL->glop;//roll
PHYSIC_MODEL->RIGHT.vec.x = cos(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.x - sin(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.y;
PHYSIC_MODEL->RIGHT.vec.y = sin(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.x + cos(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.y;
angle = PHYSIC_MODEL->heading;//pitch
PHYSIC_MODEL->RIGHT.vec.z = cos(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.z - sin(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.y;
PHYSIC_MODEL->RIGHT.vec.y = sin(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.z + cos(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.y;
angle = PHYSIC_MODEL->superpointglop;//yaw
PHYSIC_MODEL->RIGHT.vec.x = cos(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.x - sin(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.z;
PHYSIC_MODEL->RIGHT.vec.z = sin(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.x + cos(angle*imopi)*PHYSIC_MODEL->RIGHT.vec.z;


//SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM---SO THERE IS A PROBLEM-




glColor3f(1,1,1);
model->DrawSimpleModel();


glPopMatrix(); glPopMatrix(); glPopMatrix();





glPushMatrix();

glBegin(GL_LINES);
glColor3f(1.0f,0.0f,0.0f);glVertex3f(0.0f,0.0f,0.0f); //front
glVertex3f(PHYSIC_MODEL->FRONT.vec.x,PHYSIC_MODEL->FRONT.vec.y,PHYSIC_MODEL->FRONT.vec.z);
//up
glColor3f(0.0f,1.0f,0.0f);glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(PHYSIC_MODEL->UP.vec.x,PHYSIC_MODEL->UP.vec.y,PHYSIC_MODEL->UP.vec.z);
//right
glColor3f(0.0f,0.0f,1.0f);glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(PHYSIC_MODEL->RIGHT.vec.x,PHYSIC_MODEL->RIGHT.vec.y,PHYSIC_MODEL->RIGHT.vec.z);

glEnd();

glPopMatrix();
}



[/quote]

Share this post


Link to post
Share on other sites
LOL man! it works :)



BIG THANKS :D





heres a code for others :P




[quote]

float rotz[16]; angle = PHYSIC_MODEL->glop; // PITCH
PHYSIC_MODEL->PITCH_MATRIX.pointer[0] = cos(angle*imopi);
PHYSIC_MODEL->PITCH_MATRIX.pointer[1] = -sin(angle*imopi);
PHYSIC_MODEL->PITCH_MATRIX.pointer[2] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[3] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[4] = sin(angle*imopi);
PHYSIC_MODEL->PITCH_MATRIX.pointer[5] = cos(angle*imopi);
PHYSIC_MODEL->PITCH_MATRIX.pointer[6] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[7] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[8] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[9] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[10] = 1.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[11] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[12] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[13] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[14] = 0.0f;
PHYSIC_MODEL->PITCH_MATRIX.pointer[15] = 1.0f;


angle = PHYSIC_MODEL->heading; //ROLL

PHYSIC_MODEL->ROLL_MATRIX.pointer[0] = 1.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[1] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[2] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[3] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[4] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[5] = cos(angle*imopi);
PHYSIC_MODEL->ROLL_MATRIX.pointer[6] = -sin(angle*imopi);
PHYSIC_MODEL->ROLL_MATRIX.pointer[7] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[8] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[9] = sin(angle*imopi);
PHYSIC_MODEL->ROLL_MATRIX.pointer[10] = cos(angle*imopi);
PHYSIC_MODEL->ROLL_MATRIX.pointer[11] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[12] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[13] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[14] = 0.0f;
PHYSIC_MODEL->ROLL_MATRIX.pointer[15] = 1.0f;


angle = PHYSIC_MODEL->superpointglop; // YAW

PHYSIC_MODEL->YAW_MATRIX.pointer[0] = cos(angle*imopi);
PHYSIC_MODEL->YAW_MATRIX.pointer[1] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[2] = sin(angle*imopi);
PHYSIC_MODEL->YAW_MATRIX.pointer[3] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[4] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[5] = 1.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[6] = 0.0;
PHYSIC_MODEL->YAW_MATRIX.pointer[7] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[8] = -sin(angle*imopi);
PHYSIC_MODEL->YAW_MATRIX.pointer[9] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[10] = cos(angle*imopi);
PHYSIC_MODEL->YAW_MATRIX.pointer[11] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[12] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[13] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[14] = 0.0f;
PHYSIC_MODEL->YAW_MATRIX.pointer[15] = 1.0f;



// Z X Y

//PITCH -> ROLL -> YAW
MatrixMulti4x4(PHYSIC_MODEL->PITCH_MATRIX.pointer,PHYSIC_MODEL->ROLL_MATRIX.pointer,PHYSIC_MODEL->BASE_ROTATION_MATRIX2);
MatrixMulti4x4(PHYSIC_MODEL->BASE_ROTATION_MATRIX2.pointer,PHYSIC_MODEL->YAW_MATRIX.pointer,PHYSIC_MODEL->BASE_ROTATION_MATRIX);
//



PHYSIC_MODEL->UP.vec.x = PHYSIC_MODEL->BASE_ROTATION_MATRIX.pointer[1];
PHYSIC_MODEL->UP.vec.y = PHYSIC_MODEL->BASE_ROTATION_MATRIX.pointer[5];
PHYSIC_MODEL->UP.vec.z = PHYSIC_MODEL->BASE_ROTATION_MATRIX.pointer[9];

PHYSIC_MODEL->UP.vec = vector_multiple(PHYSIC_MODEL->UP.vec,10000.0f);






[/quote]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this