Skip to content

Tutorial 4: Joints and Constraints

Matthew Leibowitz edited this page Dec 14, 2015 · 2 revisions

In this tutorial we connect the two boxes from Tutorial 1 with a PointConstraint:

// set the position of the box size=(1,1,1)
// 2 and 5 units above the ground box size=(10,1,10)
boxBody1.Position = new JVector(0, 4, 1.0f);
boxBody2.Position = new JVector(0, 4, -1.0f);

pointConstraint = new PointConstraint(
    boxBody1, boxBody2, new JVector(0, 4f, 0));

world.AddConstraint(pointConstraint);

Both bodies are given to the constructor. Also the point (in world space) where both bodies get fixed together. The constraint is then added to the world. More information about how which constraints work is included in the documentation.

In Jitter constraints are related to 'joints'. Joints are collections of several constraints. Joints don't need to be added to the world - they add and manage the constraints they own.

Figure 4

Figure 4: Tutorial 4 - Two boxes constrained to a fixed point.

A helpful feature of Jitter is the possibility to get debug data from the constraints:

pointConstraint.AddToDebugDrawList(lineList, pointList);

The lineList and pointList variables contain a list of JVectors. Every two points in line list form a line.