Constraints

As the name suggests, a constraint limits the possible movement of entities. By default all objects are constrained to not penetrate the level walls or other entities. Further constraints are possible and act on one or more entities. Because constraints also join two entities to act as a composite entity, they can also be referred to as joints. The usual procedure of adding constraints is to :
    1. Call phcon_add with one or more entities and store the returned ID number
    2. Depending on the type of constraint call phcon_setparams1 and phcon_setparams2
    3. If you want to move two joined bodies, you can add a motor by calling phcon_setmotor
    4. When no longer needed, destroy the constraint by calling phcon_remove

When connecting two objects by calling phcon_add, make sure that they are already in the right position and don't penetrate each other- if they are meant to penetrate a little (e.g. wheels inside the car body's bounding box), set both objects to the same group ID using phent_setgroup. The following list provides an overview of currently available constraints and their required parameters.

PH_HINGE

Type:

hinge (10K)

Description : A hinge constrains two entitites to have a common axis of rotation and to stay a fixed distance from this axis. As depicted in the image above, you need to specify this rotation axis and an anchor point on said axis. The distance from each entity to the axis is determined when you first create the constraint. Therefore make sure to place the entities in the right position, before adding the hinge. The initial orientation is also taken as an angle value of zero degrees. Thus if both entities are rotated by 90 degrees with respect to each other and you set the angle limit to (0,0) they will remain in the initial orientation.
Parameter 1 : Anchor point
Parameter 2 : Hinge axis, e.g. (0,0,1)
Parameter 3: nullvector
Parameter 4 : Allowed angles, e.g. (-45, 90, 0) sets the lower limit to -45 degrees and the upper limit around the axis to +90 degrees. Use (-360, 360, 0) to remove all limits.
Parameter 5 : nullvector
Parameter 6 : nullvector
Motor 1 : Set desired angular velocity and the maximum torque allowed to achieve this velocity, e.g. (10, 50,0) will set a desired angular velocity of 10 Hz and a maximum torque of 50,000 Nm

PH_BALL

Type:

ball (10K)

Description : Description: Entities rotate freely around the balljoint/anchor point.
Parameter 1 : Anchor point
Parameter 2 : nullvector
Parameter 3: nullvector
Parameter 4 : nullvector
Parameter 5 : nullvector
Parameter 6 : nullvector
Motor 1 : not available

PH_WHEEL

Type:

wheel (10K)

Description : Entities are allowed to rotate around axis 1 and axis 2. Use this constraint for setting up wheel-like behavior instead of using two separate PH_HINGEs. For a car, axis 1 is the steering axis (left/right), while axis 2 is required for forward/backward movement. Only axis 1 can have angle limits and can have its orientation queried (phcon_getposition).
Parameter 1 : Anchor point
Parameter 2 : Wheel axis 1 relative to first entity´s orientation, e.g. (0,0,1)
Parameter 3: Wheel axis 2 relative to second entity´s orientation, e.g. (1,0,0)
Parameter 4 : Allowed angles around axis1,e.g. (-45, 90, 0) sets the lower limit to -45 degrees and the upper limit around the axis to +90 degrees. Use (-360, 360, 0) to remove all limits.
Parameter 5 : nullvector
Parameter 6 : nullvector or spring-damper constants in the 0..100000 range, e.g. (90000,100,0)
Motor 1 : Set desired angular velocity around axis1 and the maximum torque allowed to achieve this velocity, e.g. (10, 50,0) will set a desired angular velocity of 10 Hz and a maximum torque of 50,000 Nm
Motor 2 : Set desired angular velocity around axis2 and the maximum torque allowed to achieve this velocity, e.g. (10, 50,0) will set a desired angular velocity of 10 Hz and a maximum torque of 50,000 Nm

PH_SLIDER

Type:

slider (10K)

Description : Entities are allowed to rotate along the slider axis and move along the slider axis. Other movement is blocked.
Parameter 1 : Slider axis, e.g. (0,0,1)
Parameter 2 : nullvector
Parameter 3: nullvector
Parameter 4 : Allowed distance from original position, e.g. (-100, 1000, 0) allows the objects to slide apart by 1000 quants along the axis and 100 quants in the opposite direction, thus giving a total range of 1100 quants.
Parameter 5 : nullvector
Parameter 6 : nullvector
Motor 1 : Set desired linear velocity (can be negative to flip direction) and the maximum force allowed to achieve this velocity, e.g. (10, 50,0) will set a desired velocity of 10 quants per second and a maximum force of 50,000 N.

See also:

GameStudio Physics