Revolute here is the meaning of rotation, revolute joint is the meaning of rotational joints.
Can imagine the door of our daily life, pull, the door will revolve around the wall.
Like distance joint, Revolute joint also has two anchor points. The position of the anchor point is bound to the corresponding rigidbody.
After the scene simulate, the anchor points control Rigidbody movement and rotation.
The Unity 3D Hingejoint is implemented with Revolute joint.
There are three features in the Unity 3D Hingejoint:
1.Spring
The effect of this function is to produce a rotational elasticity. Just as we usually open the door, the spring will automatically buckle the door.
Implement spring with Revolute joint:
Pxjointangularlimitpair limitpair (min, Max, tolerance));
Limitpair.spring = .... Elastic ...;
Limitpair.damping = .... friction;
Revolute->setlimit (Limitpair);
Revolute->setrevolutejointflag (pxrevolutejointflag::elimit_enabled, true);
If you want to mimic unity for the editor function, you need to call the wakeup method of the corresponding rigidbody after you have set up a property.
But Unity's target position how to set it, I don't know how to set it, theoretically it's set on the Max field.
You also need to call the Rigidbody to update the moment of inertia, otherwise the rotation will be unnatural.
2.Limit
The function is to set the limit of the joint. Just as we usually slam the door close, the inside of the door hits the wall will bounce back the door.
Use Revolute joint to achieve limit:
Pxjointangularlimitpair limit (min, max, tolerance)
limit.bouncethreshold = minbounce;
limit.restitution= maxbounce;
Revolute->setlimit (limit); Upper, lower, tolerance
Revolute->setrevolutejointflag (pxrevolutejointflag::elimit_enabled, true);
3.Motor
The function is to set a rotational speed for the joint, like an engine.
Implement motor with Revolute joint:
Joint->setdrivevelocity (target speed);
Joint->setdriveforcelimit (force);
Joint->setconstraintflag (Pxconstraintflag::edrive_limits_are_forces, true);
Revolute->setrevolutejointflag (pxrevolutejointflag::edrive_enabled, true);
if (requires smoothing)
{
Revolute->setrevolutejointflag (Pxrevolutejointflag::edrive_freespin, True);
}
Finally, if you want to set the axis of the joint, that is, axis in u3d, you need to calculate joint each anchor point.
Sets the orientation of the axis of the joint, which is the rotation of the two anchor points of the joint.
The default orientation of the joint axis in PhysX 3.3.4 is the x-axis, which is (1,0,0).
Assuming that the rotated axis is (a,b,c), we need to figure out how much the rotation matrix is.
Set the rotation matrix to
X1,x2,x3
r=[Y1,y2,y3]
Z1,z2,z3
Then the result of (1,0,0) cross-multiply R is
(X1,X2,X3)
And we know that the axis after rotation is (a,b,c).
So the rotation matrix is
A, 0, 0
r=[B, 0,0]
C, 0,0
Finally we initialize a four element with a rotation matrix,
Pxqua qua (R);
Call
Revolute->setlocalpose (Pxtransform (Pos,qua));
So the rotation of the axis is done.