Introduction

By now you may have noticed the use of data structures to initialize different things. These “data objects” store descriptions of various XPA objects, including Solids, Joints, Motors, and Sensors. Any of these XPA objects can be initialized from a data object, setting all parameters at once.

Solids use this feature merely as a convenience; Joints, Motors, and Sensors must be initialized from a data object before they can be used at all. Shapes are a little different in that they are only represented as data objects: there are no Shape classes that can be instantiated.

The data objects themselves use default parameters, so you don’t have to set every parameter in a data object if you don’t want to.

Solid Creation Methods

The first example here shows three different ways to create a Solid:
  • Method 1
Solid solid = sim.CreateSolid(); 
BoxShapeData boxData = new BoxShapeData();
solid.LinearDamping = 0.2f;
solid.AddShape(boxData); 

Note: sim is an initialized Simulator
  • Method 2
Solid solid = sim.CreateSolid();
SolidData solidData = new SolidData();
BoxShapeData boxData = new BoxShapeData();
solidData.LinearDamping = 0.2f;
solidData.AddShape(boxData);
solid.Init(solidData); 

  • Method 3
Solid solid = sim.CreateSolid();
SolidData solidData = new SolidData();
BoxShapeData boxData = new BoxShapeData();
solidData.LinearDamping = 0.2f;
solidData.AddShape(boxData);
solid.Init(solidData);
SphereShapeData sphereData = new SphereShapeData();
solid.AddShape(sphereData); 


The first method creates a Solid, sets its parameters, and adds Shapes to it. The second method adds Shapes to a SolidData object, sets its parameters, and uses it to initialize a Solid. The third method is the same as the second except that it adds a Shape to the Solid after it has been initialized from a SolidData object.

Joints, Motors, and Sensors can only be created one way: by initializing them with data objects. The tutorials on Joints, Motors, and Sensors already show how to do this, so it will not be repeated here.

Object Cloning

Data objects make it easy to clone objects. The following examples are pretty self-explanatory:
Solid object1 = sim.CreateSolid();
Joint joint1 = sim.CreateJoint();
// Setup the Solid and Joint...

...

// Now make clones of the objects.
Solid object2 = sim.CreateSolid();
SolidData object1Data = object1.Data;
object2.Init(object1Data);
 
Joint joint2 = sim.CreateJoint();
JointData joint1Data = joint1.Data;
joint2.Init(joint1Data); 


As you can see, data objects are pretty flexible. They allow you to create and copy objects easily.

Last edited Oct 12, 2006 at 8:09 PM by KleMiX, version 2

Comments

No comments yet.