Tutorial 2: Solids, Shapes, and Materials

 

 

Solids

A Solid is analogous to a physical object in the real world.  It can be static (just a shape, not physically simulated) or dynamic (has a shape, mass, and is physically simulated).  The available Shapes are: boxes, spheres, capsule, planes, and triangular meshes.  A Solid contains no moving parts.  Complex objects with moving parts can be built from multiple Solids with Joints.

 

Create a Solid by asking a Simulator to create one:

 

 

opal::Simulator* sim = opal::createSimulator();

opal::Solid* solid = sim->createSolid();

 

 

 

 

 

 

Once you have a Solid, you can set its various parameters.  For example…

 

 

solid->setLinearDamping(0.2);

 

opal::Matrix44r transform;

transform.translate(1.0, 0.0, 5.0);

transform.rotate(45.0, 0.0, 1.0, 0.0);

solid->setTransform(transform);

 

solid->setStatic(true);

 

 

 

 

 

 

 

 

 

 

 

 

The last call makes the Solid static, i.e. it will not be physically simulated but still takes part in collision detection.

 

You can apply forces and torques to a Solid like this:

 

 

opal::Force f;

f.type = opal::GLOBAL_FORCE;

f.vec = opal::Vec3r(20.0, 20.0, 40.0);

f.duration = 0.1;

solid->addForce(f);

 

 

 

 

 

 

 

 

 

This force will be applied to the Solid until its duration expires.

 

When you are done with a Solid, tell the Simulator to destroy it:

 

 

sim->destroySolid(solid);

 

 

 

 

 

If other things depends on this Solid, like Joints, Motors, or Sensors, they will automatically be disabled.

 

Shapes

An important part of creating a Solid is giving it Shapes.  A Solid can contain any number of Shapes.  To add box and sphere Shapes to the Solid, do the following:

 

 

opal::BoxShapeData boxData;

boxData.dimensions.set(1.0, 1.0, 2.0);

solid->addShape(boxData);

opal::SphereShapeData sphereData;

sphereData.radius = 2.0;

sphereData.offset.translate(4.0, 0.0, 0.0);

solid->addShape(sphereData);

 

 

 

 

 

 

 

 

 

 

 

Notice how the sphere’s offset was changed.  The offset positions the Shape relative to the Solid’s transform.  Shapes are not offset at all by default.  Here, we have moved the Sphere away from the Solid’s origin.

 

Materials

Each Shape can have different Material properties.  Now for a demonstration of using a custom Material:

 

 

opal::BoxShapeData boxData;

boxData.dimensions.set(1.0, 1.0, 2.0);

boxData.material.hardness = 0.2;

boxData.material.bounciness = 0.6;

boxData.material.friction = 1.0;

boxData.material.density = 0.4;

solid->addShape(boxData);

 

 

 

 

 

 

 

 

 

 

 

Note that Material density affects a Solid’s mass (calculated from each Shape’s density and volume).  The rest of the Material properties are described in the API reference.

 

 

OPAL is Copyright © 2004-2005 Alan Fischer, Andres Reinot, and Tyler Streeter