R3d.HingeJoint

From GiderosMobile
Revision as of 14:30, 13 July 2023 by Hgy29 (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")

Available since: Gideros 2019.10
Class: R3d.Joint

Description

The HingeJoint class describes a hinge joint (or revolute joint) between two rigid bodies.

The hinge joint only allows rotation around an anchor point and around a single axis (the hinge axis). This joint can be used to simulate doors or pendulums for instance.

In order to create a hinge joint, you first need to create a HingeJointInfo object with the necessary information. You need to provide the pointers to the two rigid bodies, the coordinates of the anchor point (in world-space) and also the hinge rotation axis (in world-space). The two bodies need to be in a correct position when the joint is created. <syntaxhighlight lang="lua"> r3d.HingeJoint </source>

Now, it is time to create the actual joint in the dynamics world using the Dynamics World::createJoint() method.

Note that this method will also return a pointer to the HingeJoint object that has been created internally. You will then be able to use that pointer to change properties of the joint and also to destroy it at the end.


Limits

With the hinge joint, you can constrain the motion range using limits. The limits of the hinge joint are the minimum and maximum angle of rotation allowed with respect to the initial angle between the bodies when the joint is created.

The limits are disabled by default. If you want to use the limits, you first need to enable them by setting the isLimitEnabled variable of the HingeJointInfo object to true before you create the joint. You also have to specify the minimum and maximum limit angles (in radians) using the minAngleLimit and maxAngleLimit variables of the joint info object.

Note that the minimum limit angle must be in the range [−2π;0] and the maximum limit angle must be in the range [0;2π].

Motor

A motor is also available for the hinge joint. It can be used to rotate the bodies around the hinge axis at a given angular speed and such that the torque applied to rotate the bodies does not exceed a maximum allowed torque.

The motor is disabled by default. If you want to use it, you first have to activate it using the isMotorEnabled boolean variable of the HingeJointInfo object before you create the joint. Then, you need to specify the angular motor speed (in radians/seconds) using the motorSpeed variable and also the maximum allowed torque (in Newton · meters) with the maxMotorTorque variable.

Example

<syntaxhighlight lang="lua"> </source>