Help rotating objects

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
User avatar
ifcaro
Posts: 23
Joined: Sun Oct 19, 2008 4:11 am

Help rotating objects

Post 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
LBGSHI
Posts: 136
Joined: Mon Aug 07, 2006 5:56 am
Contact:

Post by LBGSHI »

Glad we could be of help :)
I may be lazy, but I can...zzzZZZzzzZZZzzz...
User avatar
ifcaro
Posts: 23
Joined: Sun Oct 19, 2008 4:11 am

Post by ifcaro »

Post Reply