directx12 – How to update DX12 Render Mesh from PhysX mesh

I have 2 Meshes and I want to add physics to them, the first is a primitive box, the second is a terrain

the box and the terrain made with DirectXMath

Using PhysX library, I made a copy of the terrain and used it to create a Triangle mesh then

and I created a box using physx::PxBoxGeometry as you can see here

        physx::PxTransform boxPos(physx::PxVec3(0.0f, 20, 0.0f));
        physx::PxBoxGeometry boxGeometry(physx::PxVec3(0.5f, 0.5f, 0.5f));
        physx::PxShape* shape =m_pPhysics->createShape(boxGeometry, *m_pMaterial);
        physx::PxRigidDynamic* boxRigid = m_pPhysics->createRigidDynamic(boxPos);
        physx::PxRigidBodyExt::updateMassAndInertia(*boxRigid, .15f);

I added them to the scene and I ran the simulation and I can see the box is dropped and flipped couple times using Physx Visual Debugger(though, on some runs the debugger shows artifacts, anyway)

I found out that I can get the translation and rotation by using m_pPhysicsActors[]->getGlobalPose() which is both quaternion for rotation and vector for position so I thought that’s it

but in the hello world snippets they made this function

brief Retrieves the world space pose of the shape.

param[in] shape The shape for which to get the global pose.
param[in] actor The actor to which the shape is attached

return Global pose of shape.
static PX_INLINE    PxTransform     getGlobalPose(const PxShape& shape, const PxRigidActor& actor)
    return actor.getGlobalPose() * shape.getLocalPose();

then they put the output in a matrix

Now I am confused, why actor.getGlobalPose() * shape.getLocalPose();

I thought the shape and the actor are the same thing, like a relationship or a property, since I assign a shape to an actor, I imagine that if I rotate a shape, I rotate the actor vice verse and it is one thing.

this is where I am lost! , so can someone walk me through on this part of how to update render items from PhysX

Source link

More To Explore

Share on facebook
Share on twitter
Share on linkedin
Share on email