thorsan

02-22-2004, 05:12 AM

Hello

Imhaving a little problem with rotating around a cube. First tried using glRotatef ariund the three different vectors. this seemed to work nice, but... When i have rotated 90 degrees around the y axis and then want to rotate over the cube( "standing" along the x axis ) and want to rotate "over the cube" the cube spins like a wheel. this is so because, when i push the up button i increase the rotation around the x axis. but when im not standing orthogonally on the x axis, i must also rotate around the z axis too...

i have tried building up a projection matrix this way:

void buildMatrix()

{

float phi = mat.xgrad;

float kappa = mat.ygrad;

float omega = mat.zgrad;

mat.trans[0] = cos(kappa)*cos(omega);

mat.trans[1] = -sin(omega);/*-cos(kappa)*-sin(omega);*/

mat.trans[2] = sin(kappa);

mat.trans[3] = 0.0f;

mat.trans[4] = sin(omega);/*sin(phi)*sin(kappa)*cos(omega) + cos(phi)*sin(omega);*/

mat.trans[5] = cos(phi) * cos(omega);/*-sin(phi)*sin(kappa)*sin(omega) + cos(phi)*cos(omega);*/

mat.trans[6] = -sin(phi);/**cos(kappa);*/

mat.trans[7] = 0.0f;

mat.trans[8] = -sin(kappa); /*-cos(phi)*sin(kappa)*cos(omega) + sin(phi)*sin(omega);*/

mat.trans[9] = sin(phi); /*cos(phi)*sin(kappa)*sin(omega) + sin(phi)*cos(omega);*/

mat.trans[10] = cos(phi)*cos(kappa);

mat.trans[11] = 0.0f;

mat.trans[12] = 0.0f;//mat.xgrad;

mat.trans[13] = 0.0f;//mat.ygrad;

mat.trans[14] = 0.0f;//mat.zgrad;

mat.trans[15] = 1.f;

}

this doesnt work at all. i need tips! how do i freely move around an object?

Imhaving a little problem with rotating around a cube. First tried using glRotatef ariund the three different vectors. this seemed to work nice, but... When i have rotated 90 degrees around the y axis and then want to rotate over the cube( "standing" along the x axis ) and want to rotate "over the cube" the cube spins like a wheel. this is so because, when i push the up button i increase the rotation around the x axis. but when im not standing orthogonally on the x axis, i must also rotate around the z axis too...

i have tried building up a projection matrix this way:

void buildMatrix()

{

float phi = mat.xgrad;

float kappa = mat.ygrad;

float omega = mat.zgrad;

mat.trans[0] = cos(kappa)*cos(omega);

mat.trans[1] = -sin(omega);/*-cos(kappa)*-sin(omega);*/

mat.trans[2] = sin(kappa);

mat.trans[3] = 0.0f;

mat.trans[4] = sin(omega);/*sin(phi)*sin(kappa)*cos(omega) + cos(phi)*sin(omega);*/

mat.trans[5] = cos(phi) * cos(omega);/*-sin(phi)*sin(kappa)*sin(omega) + cos(phi)*cos(omega);*/

mat.trans[6] = -sin(phi);/**cos(kappa);*/

mat.trans[7] = 0.0f;

mat.trans[8] = -sin(kappa); /*-cos(phi)*sin(kappa)*cos(omega) + sin(phi)*sin(omega);*/

mat.trans[9] = sin(phi); /*cos(phi)*sin(kappa)*sin(omega) + sin(phi)*cos(omega);*/

mat.trans[10] = cos(phi)*cos(kappa);

mat.trans[11] = 0.0f;

mat.trans[12] = 0.0f;//mat.xgrad;

mat.trans[13] = 0.0f;//mat.ygrad;

mat.trans[14] = 0.0f;//mat.zgrad;

mat.trans[15] = 1.f;

}

this doesnt work at all. i need tips! how do i freely move around an object?