3d model pin to Physx

Hello, I write game in c++ directx and I have question.
I have textured 3d model for instance “gun m4”, I have also simplified mesh of this model for collision.
And now how I can connect both(I mean connects actor with collision model(mesh) and next with main 3d model) ?

Hi,

With easy words: Create a simple shape, (Convex or with basic forms like Sphere, Box , Capsule) your desired collision shape “via coding” at runtime.
Now you can update the position of your 3D model from the collisionshape.

[If you want to “attach” your weapon the your player model, you should read about bones - your designer of your 3D model [player] should know what I mean. Of course, its possible to hard code it
but you know math for doing it this way (and its not recommended) …]

But wait, there are some ways to solve it:

0.0.0 You are completly new and doesnt know anything.
First you should read the PhysX Guide completly to understand how PhysX works.
0.0.1 After you read the PhysX Guide completly, you also read the Snippets. (-> Hello World)
0.0.1.x Change some values, play with it, just to understand how it works.
0.0.2 After you understand how it works, you should sneek into the “advandced” Snippets.
0.0.3 After you understand all of them, you should read the PhysX Guide again.
0.0.4 Now you are ready to take a peek into the “most advanced” examples in Samples.
0.0.5 Alright, you know enough to change the Samples (and the Snipptes of course :D)
0.0.6 Lets go, read on!

  1. FROM THE GUIDE:
    Connecting PhysX Objects with User Application Objects
    Various PhysX callbacks and interfaces provide information on status changes and events triggered by PhysX objects. Usually, the application needs a means to translate the PhysX object pointers to user application object pointers to adjust the latter for game logic or rendering purposes, for example. An easy way to connect user application objects with PhysX objects is to use the userData member provided by the most important PhysX classes (see PxActor::userData, PxShape::userData, PxMaterial::userData, …). The userData member is a void* pointer for user purposes only and allows to link the user application object to the corresponding PhysX object. However, please note that if the user application has not full control over the creation of PhysX objects, special considerations need to be taken into account when using the userData field (see Simulation Clients).

  2. Create a class or struct which holds pointers to your mesh and your PxActor - and code a function
    called eg update() which updates the position of the PxActor to the 3D model.

  3. Same as above, but it doesent have a update function, it synchronized the PxActor position with the 3D Model via getting the new transformation as a great matrix. [Read PhysX guide…]

[s]With easy words: Create a simple shape, (Convex or with basic forms like Sphere, Box , Capsule) your desired collision shape “via coding” at runtime.
Now you can update the position of your 3D model from the collisionshape.

Yes but how update rotation of object ? I only have actor->getGlobalPose();[/s]

EDIT.
Okey I know.
PxQuat rotation = actor->getGlobalPose().q;
And after , rotation.x, rotation.y, rotation.z :)

Thanks :)

Hi,

PhysX rotation system is done via Quaternion, not Euler, so you need the rotation.w part of it.
If you have an euler rotation system, you have to convert it to euler values. ( x, y, z )
Rotate your 3D model with this values.
Or pass these values as an matrix to your 3D model, if its possible.

Or you calculate it by hand :D

[UPDATE:]
A hint: Here is a snippet how I convert an Euler rotation system to a Quaterion system:

https://devtalk.nvidia.com/default/topic/666401/physx-and-physics-modeling/physx-3-3-creating-pxshape-error/post/4074705/#4074705