dms::Object

Object is a generic class to represent any object that will be drawn in a scene. Subclasses can be created for specific types of geometry (such as the QuadricObject class). Object includes three major features:

Source Code

Class Specification

#include <dms/Object.h>

Object(void);
virtual ~Object(void);

virtual void draw(void);
virtual void update(void);
void drawAll(void);
void updateAll(void);

void setTransform(Transform&);
void setMaterial(Material&);
void setTexture(Texture&);
void setTransparency(Transparency&);
Transform& transform(void) const;
Material& material(void) const;
Texture& texture(void) const;
Transparency& transparency(void) const;

void attach(Object&);
void detach(Object&);
int numChildren(void);
Object& child(int n);


typedef void (*CallbackFunc)(Object&,void*);

void setDrawCallback(CallbackFunc drawfunc,void *data=0);
void setDrawCallbackData(void *data);
void setUpdateCallback(CallbackFunc updatefunc,void *data=0);
void setUpdateCallbackData(void *data);

Description

void draw(void)

Draws the object. This will generally be defined in derived classes to draw the geometry handled by that class; Object itself draws nothing.
If a draw-callback function has been set, it will be called by draw().

void drawAll(void)

Applies the objects transform, material, texture, and transparency (if they have been set), and calls the draw() function. Also calls drawAll() for all child Objects that are attached to the Object, with the transform still applied (but not the material, texture, or transparency).

void update(void)

Performs updates on the object - typically calculations for dynamic objects. This can be defined in derived classes that provide special object behaviors; Object itself performs no special updates.
If an update-callback function has been set, it will be called by update().

void updateAll(void)

Calls update() for the Object, then calls updateAll() for all attached child Objects.

void setTransform(Transform&)
Transform& transform(void)

Sets / returns the Transform object that is to be applied whenever drawAll() is called for the Object.
Example:

dms::SimpleTransform xform;
xform.setTranslation(5.0, 0.0, 0.0);
object.setTransform(xform);
void setMaterial(Material&)
Material& material(void)

Sets / returns the Material that is to be applied whenever drawAll() is called for the Object.
Example:

dms::Material redmaterial(dms::Color::Red);
object.setMaterial(redmaterial);
void setTexture(Texture&)
Texture& texture(void)

Sets / returns the Texture that is to be applied whenever drawAll() is called for the Object.
Example:

dms::Texture2D tex("image.jpg");
object.setTexture(tex);
void setTransparency(Transparency&)
Transparency& transparency(void)

Sets / returns the Transparency that is to be applied whenever drawAll() is called for the Object.
Example:

object.setTransparency(dms::Transparency::StandardBlend);
void attach(Object& child)

Attaches child to the Object that attach() is called on. An attached child Object will be drawn whenever drawAll() is called for the parent Object, and will be updated whenever updateAll() is called for the parent Object.
An Object's transformation is applied to all child Objects (along with the child Objects' transformations).
Example:

object1.attach(object2);
object2.attach(object3);
object1.drawAll();   /* Draws object1, object2, and object3 */
void detach(Object& child)

Removes child from the list of children attached to the Object.

object1.attach(object2);
...
object1.detach(object2);
int numChildren(void)

Returns the number of children attached to the Object.

Object& child(int n)

Returns the nth child attached to the Object. n should be in the range 0 to numChildren()-1, inclusive.

object1.detach(object1.child(0));
void setDrawCallback(CallbackFunc drawfunc,void *data=0)

Defines a draw-callback function, which is called whenever draw() is called for the Object.
The function should have the prototype void drawfunc(Object& object, void *data). object is the Object for which the function is being called; data is the data pointer that was given as the second argument of setDrawCallback(), or via setDrawCallbackData().
Example:

object1.setDrawCallback(myDrawFunc, &drawData);
void setDrawCallbackData(void *data)

Sets the data pointer that will be passed as the second argument of the draw-callback function, if one is defined.

void setUpdateCallback(CallbackFunc updatefunc,void *data=0)

Defines a update-callback function, which is called whenever update() is called for the Object. The function should have the prototype void updatefunc(Object& object, void *data). object is the Object for which the function is being called; data is the data pointer that was given as the second argument of setUpdateCallback(), or via setUpdateCallbackData().
Example:

object1.setDrawCallback(moveObject, &objectData);
void setUpdateCallbackData(void *data)

Sets the data pointer that will be passed as the second argument of the update-callback function, if one is defined.