Matrix Problems with rotating an object around its Pivot

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Matrix Problems with rotating an object around its Pivot

Post by ayatollah »

I was wondering if somebody here could help me out?

I am trying to display a 3d Object (CAR) and want to move it forward. During this forward move, I want to rotate it's wheels around their own pivot point!

Everything works fine as long as the car does not move but once I start moving the car along it's Y axis, the wheels remain in place!

This is what I draw each frame:

Code: Select all

static void draw_frame(float frame)
{

	ScePspFVector3 eye, center, up;
	
	sceGuStart(GU_DIRECT,list);
	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

	sceGumPushMatrix();
	sceGumLoadIdentity();


	DrawCube(1.0f, frame);

	sceGumPopMatrix();

	sceGuFinish();
	sceGuSync(0,0);

}
and in the DrawCube, I have the following Commands:

Code: Select all

void DrawCube(float scale, float frame)
{
	ScePspFVector3 vec;
	float angle;
	ScePspFMatrix4 wheel;
	ScePspFMatrix4 temp;
	vec.x=scale, vec.y=scale, vec.z=scale;

	sceGumScale(&vec);

	sceGumDrawArray(GU_TRIANGLES, 
				GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT,
				alight_NUMFACES*3, (void *)alight_idx, (void *)alight_vtx);
.........
more faces are drawn here
........
and here I try my wheel thing (this displays one wheel and the RIM) and rotates it:

Code: Select all

	sceGumStoreMatrix(&temp);

	sceGumLoadMatrix(&wheel);
	sceGumLoadIdentity();
	
	pos.trans.x = -lftire_pivot.px;
	pos.trans.y = -lftire_pivot.py;
	pos.trans.z = -lftire_pivot.pz;
	sceGumTranslate(&pos.trans);

	angle = frame*50 * (M_PI/180.0f);
	sceGumRotateX(angle);

	pos.trans.x = lftire_pivot.px;
	pos.trans.y = lftire_pivot.py;
	pos.trans.z = lftire_pivot.pz;
	sceGumTranslate(&pos.trans);

	sceGumDrawArray(GU_TRIANGLES, 
				GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT,
				lftire_NUMFACES*3, (void *)lftire_idx, (void *)lftire_vtx);
	sceGumDrawArray(GU_TRIANGLES, 
				GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT,
				lfrim_NUMFACES*3, (void *)lfrim_idx, (void *)lfrim_vtx);
	sceGumMultMatrix(&temp);
}
lftire_pivot.px, lftire_pivot.py and lftire_pivot.pz hold the x, y and z of the wheel's Pivot Points. This rotates the wheel successfully on the NOT MOVING Car. However as soon as I put a translate on the very top of the drawcube, the car moves but the wheel remains on it's place..

My problem is, that I am fairly new to 3d and I dont really get the whole things with the matrices..

Thank you very much for your help. It's greatly appreciated!

Roland
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

Instead of the

Code: Select all

sceGumStoreMatrix(&temp);

   sceGumLoadMatrix(&wheel);
   sceGumLoadIdentity(); 
at the start, try wrapping the wheel drawing in a

Code: Select all

   sceGumPushMatrix(); 
   sceGumPopMatrix(); 
pair, just like it's usually done in hierarchical transformations.
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Post by ayatollah »

Thanx for the Hint... I will try that out tonight..

One thing:
How big is the Matrix Stack? How many matrices can I push there and get back out?
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

The matrix stack is currently 32 entries per type. There is currently no way of changing this at runtime, so if you need a bigger stack you have to change it yourself in gumInternal and recompile.
GE Dominator
Post Reply