 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
ayatollah
Joined: 04 Sep 2005 Posts: 15
|
Posted: Wed Nov 23, 2005 10:15 am Post subject: Matrix Problems with rotating an object around its Pivot |
|
|
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: |
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: |
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: |
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 |
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Wed Nov 23, 2005 11:03 am Post subject: |
|
|
Instead of the
| Code: | sceGumStoreMatrix(&temp);
sceGumLoadMatrix(&wheel);
sceGumLoadIdentity(); |
at the start, try wrapping the wheel drawing in a
| Code: |
sceGumPushMatrix();
sceGumPopMatrix();
|
pair, just like it's usually done in hierarchical transformations. |
|
| Back to top |
|
 |
ayatollah
Joined: 04 Sep 2005 Posts: 15
|
Posted: Wed Nov 23, 2005 7:44 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Thu Nov 24, 2005 12:02 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|