Skip to main content
GameDev.net gamedev.net
🔒 Locked

[PHYSX] global pose with direct x

Started by david w Mar 18, 2015 at 12:07 AM 1 replies 3.5k views
Original Post
david w
david w

I am have a very frustrating time trying to figure out how to make PhysX and DirectX 9 behave well together.

I have been able to make it so that I can get the position of the cubes from the PhysX system and position them with DirectX.

I have also been able to get the scale correct.

The problem is that I can't seem to figure out how to get the rotation from PhysX system and apply it to my DirectX World Matrix.

The cubes or spheres drop and bounce and expected however they are "frozen" on all axis. They don't spin/rotate as you would expect.

my code is:


						PxMat44 world;
						D3DXMATRIX World, mTrans, mScale, mRot;
						D3DXMatrixIdentity( &World );
						world = physx::PxMat44(physx::PxMat33( worldObject->dynamicActors[num]->getGlobalPose().q), worldObject->dynamicActors[num]->getGlobalPose().p) ;
						
PxMat44 matrix4(worldObject->dynamicActors[num]->getGlobalPose());

						//D3DXVECTOR3 pos,scale, rot;

						//rot.x = worldObject->dynamicActors[num]->getGlobalPose().q.x;
						//rot.y = worldObject->dynamicActors[num]->getGlobalPose().q.y;
						//rot.z = worldObject->dynamicActors[num]->getGlobalPose().q.z;
						D3DXVECTOR3 scale;
 						scale.x = worldObject->WorldInstancesMatrix[num]._11;
						scale.y = worldObject->WorldInstancesMatrix[num]._22;
						scale.z = worldObject->WorldInstancesMatrix[num]._33;
						D3DXMatrixScaling( &mScale, scale.x,scale.y,scale.z);

						world.column0[0] = scale.x;
						world.column1[1] = scale.y;
						world.column2[2] = scale.z;

 memcpy( &World, &world, 4 * 4 * sizeof(float) );   

I "think" that I am getting the rotation correctly from PhysX with getGlobalPose.q ; however I'm not certain how to apply this to a Directx 9 Matrix

Any help would go a very long way.

Thank you.

Buckeye
Buckeye

I'm not familiar with physx but it seems you should be able to get the quaternion part of the pose (PxQuat?). If so, you may have to play with the order of the elements, but you should be able to use D3DXMatrixRotationQuaternion to create a rotation matrix from it. Then create your world from scale, rotation and translate matrices - remember that in DX the order is SRT. That is, worldMat = scaleMat * rotMat * transMat.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
david w
david w

Yes that did the trick. problem solved!!

Thank you

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.