Page 1 of 1

Help rotating objects

Posted: Sun Oct 19, 2008 4:17 am
by ifcaro
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:

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&#40;obj->rotation&#91;0&#93;&#91;0&#93; < -PI&#41; obj->rotation&#91;0&#93;&#91;0&#93; += PI_2;
    while&#40;obj->rotation&#91;0&#93;&#91;1&#93; < -PI&#41; obj->rotation&#91;0&#93;&#91;1&#93; += PI_2;
    while&#40;obj->rotation&#91;0&#93;&#91;2&#93; < -PI&#41; obj->rotation&#91;0&#93;&#91;2&#93; += PI_2;

&#125;

Code: Select all

void objectRender&#40;Object3D *obj&#41;&#123;

	objectReset&#40;obj&#41;;
	
	// aplicamos la rotacion a la matriz
    libVu0RotMatrix&#40;obj->localToWorld&#91;0&#93;,
                    obj->localToWorld&#91;0&#93;,
                    obj->rotation&#91;0&#93;&#41;;					
    libVu0RotMatrix&#40;obj->localToWorldRotation&#91;0&#93;,
                    obj->localToWorldRotation&#91;0&#93;,
                    obj->rotation&#91;0&#93;&#41;;
					
	// posicion
	libVu0TransMatrix&#40;obj->localToWorld&#91;0&#93;, obj->localToWorld&#91;0&#93;, obj->translation&#91;0&#93;&#41;;

	actualobj=NULL;
    objectRender_Calc&#40;obj&#41;;
    objectRender_Draw&#40;obj&#41;;
&#125;
EDIT: It seems that I get it :D

Posted: Sun Oct 19, 2008 10:31 am
by LBGSHI
Glad we could be of help :)

Posted: Mon Oct 20, 2008 9:32 am
by ifcaro