Hello,
I am trying to use Physx 3.4 to run a simulation with objects that I display in a ray-traced scene (created with the Embree API). The idea is to retrieve the transform matrix of an actor at each step of the simulation until the actor is sleeping.
However, I’m having issues with sending the original matrix (from my 3D scene, row-major and right-handed), to a PxTransform (or PxMat44, column-major and lefft-handed) when I’m creating an actor, and retrieving it by doing the inverse operation.
For now, I’m just calling these custom converting functions :
PxTransform Cfloat44ToPxTransform(Cfloat44& m)
{
Cfloat4 scale = m.getscale();
Cfloat44 am = Cfloat44(1/scale.x,0.0,0.0,0.0,
0.0,1/scale.y,0.0,0.0,
0.0,0.0,1/scale.z,0.0,
0.0,0.0,0.0,1.0) * m;
Cfloat44 tr(1,0,0,0,
0,1,0,0,
0,0,-1,0,
0,0,0,1);
Cfloat4 pos = am.v[3];
Cfloat44 pm = am * tr;
pm.v[3] = pos;
PxMat44 mat(pm.f);
return PxTransform(mat);
}
Cfloat44 transformToCfloat44(const PxTransform& transform, Cfloat4 &scale)
{
PxMat44 m = PxMat44(transform);
Cfloat44 cMatrix(m[0][0],m[0][1],m[0][2],m[0][3],
m[1][0],m[1][1],m[1][2],m[1][3],
m[2][0],m[2][1],m[2][2],m[2][3],
m[3][0],m[3][1],m[3][2],m[3][3]);
Cfloat44 tr(1,0,0,0,
0,1,0,0,
0,0,-1,0,
0,0,0,1);
Cfloat4 pos = cMatrix.v[3];
Cfloat44 pm = cMatrix * tr;
pm.v[3] = pos;
pm = Cfloat44(scale.x,0.0,0.0,0.0,
0.0,scale.y,0.0,0.0,
0.0,0.0,scale.z,0.0,
0.0,0.0,0.0,1.0) * pm;
return pm;
}
Cfloat44 and Cfloat4 corresponds to a (4,4) matrix and (4,) vector respectively.
I use those converting functions when I create PxRigidStatic and PxRigidDynamic actors. I only retrieve PxDynamic actor matrices to display the related object in my 3D scene.
I can see that something is wrong when I display the simulation in my 3D scene, especially when it comes to collision between a PxRigidStatic and a PxRigidDynamic (overlapping, odd behavior, etc.)
I’m guessing there is something wrong with my coordinate system conversion, but I can’t seem to figure out what it is.
Does anyone have a lead on what is incorrect here ?