Tutorial 6: Data Objects By
now you may have noticed the use of data structures to initialize different
things. These “data objects” store
descriptions of various OPAL objects, including Solids, Joints, Motors, and
Sensors. Any of these OPAL 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:
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:
As
you can see, data objects are pretty flexible. They allow you to create and copy objects
easily. |
OPAL is Copyright © 2004-2005 Alan Fischer, Andres Reinot, and
Tyler Streeter