-
Notifications
You must be signed in to change notification settings - Fork 87
Tutorial 3: Compound Body
matbord edited this page May 8, 2019
·
3 revisions
In this tutorial we use the CompoundShape
to add two sub-BoxShapes
to it.
You can use compound shapes to build new shapes out of the basic shapes. For
example, a car chassis could be made of a compound shapes. This is a common
technique to save a lot of computation time.
Figure 3: Tutorial 3 - Two boxes form a compound compound body.
// Build the CompoundShape.TransformedShape structure,
// containing "normal" shapes and position/orientation
// information.
CompoundShape.TransformedShape[] transformedShapes =
new CompoundShape.TransformedShape[2];
// Create a rotation matrix (90°)
JMatrix rotated = JMatrix.CreateRotationX((float)(90* (Math.PI)) / 180);
// the first "sub" shape. A rotatated boxShape.
transformedShapes[0] = new CompoundShape.TransformedShape(
boxShape, rotated, JVector.Zero);
// the second "sub" shape.
transformedShapes[1] = new CompoundShape.TransformedShape(
boxShape, JMatrix.Identity, JVector.Zero);
// Pass the CompoundShape.TransformedShape structure to the compound shape.
CompoundShape compoundShape = new CompoundShape(transformedShapes);
RigidBody compoundBody = new RigidBody(compoundShape);