Help rotating objects
Posted: Sun Oct 19, 2008 4:17 am
Hi, I'm an amateur programmer who is doing a modified version of Llibplanar but I have a couple of problems that I am not able to solve, move and rotate objects relatively.
To move and rotate objects using the following functions:
EDIT: It seems that I get it :D
To move and rotate objects using the following functions:
Code: Select all
void objectTranslate(Object3D *obj,float x,float y,float z){
obj->translation[0][0] = x;
obj->translation[0][1] = y * -1.0f;
obj->translation[0][2] = z;
}
Code: Select all
void objectRotate(Object3D *obj,float x,float y,float z){
obj->rotation[0][0] = -x;
obj->rotation[0][1] = -y;
obj->rotation[0][2] = -z;
// cuidado con pasarnos por encima
while(obj->rotation[0][0] > PI) obj->rotation[0][0] -= PI_2;
while(obj->rotation[0][1] > PI) obj->rotation[0][1] -= PI_2;
while(obj->rotation[0][2] > PI) obj->rotation[0][2] -= PI_2;
// y por debajo
while(obj->rotation[0][0] < -PI) obj->rotation[0][0] += PI_2;
while(obj->rotation[0][1] < -PI) obj->rotation[0][1] += PI_2;
while(obj->rotation[0][2] < -PI) obj->rotation[0][2] += PI_2;
}
Code: Select all
void objectRender(Object3D *obj){
objectReset(obj);
// aplicamos la rotacion a la matriz
libVu0RotMatrix(obj->localToWorld[0],
obj->localToWorld[0],
obj->rotation[0]);
libVu0RotMatrix(obj->localToWorldRotation[0],
obj->localToWorldRotation[0],
obj->rotation[0]);
// posicion
libVu0TransMatrix(obj->localToWorld[0], obj->localToWorld[0], obj->translation[0]);
actualobj=NULL;
objectRender_Calc(obj);
objectRender_Draw(obj);
}