The object class. More...
#include <VR3Obj.h>
Public Member Functions | |
Children Management | |
int | AddChild (VR3Obj *c, GLfloat x, GLfloat y, GLfloat z) |
Makes the specified object child of this object. | |
int | AddChild (VR3Obj *c) |
Makes the specified object child of this object. | |
int | RemoveChild (VR3Obj *c) |
Removes the specified object from the list of child objects. | |
Get and Set Functions | |
void | SetPivotPoint (GLfloat x, GLfloat y, GLfloat z) |
Sets the position of the pivot point. | |
void | SetPivotPoint (const GLfloat *vec) |
Sets the position of the pivot point. | |
void | GetPivotPoint (GLfloat *vec) |
Gets the position of the pivot point. | |
void | GetPosition (GLfloat *p) |
Retrieves the position of the current object. | |
void | SetPosition (GLfloat x, GLfloat y, GLfloat z) |
Sets the object position. | |
void | SetPosition (const GLfloat *point) |
Sets the object position. | |
void | GetScale (GLfloat *s) |
Gets the object scale. | |
void | SetScale (GLfloat scx, GLfloat scy, GLfloat scz) |
Sets the scaling factors. | |
void | SetScale (const GLfloat *s) |
Sets the scaling factors. | |
void | GetRotationMatrix (GLfloat *m) |
Retrieves the rotation matrix of the current object. | |
void | SetRotationMatrix (const GLfloat *m) |
Sets the rotation matrix of the current object. | |
VR3Mesh * | GetMesh (int lod=0) |
Gets one of the mesh associated with the object. | |
void | Hide () |
Hides the object an its children. | |
void | UnHide () |
Unhides the object an its children. | |
void | LinkToMesh (VR3Mesh *m, GLfloat dist=0.0f) |
Links a mesh to this object. | |
bool | PointInBBox (GLfloat x, GLfloat y, GLfloat z) |
Finds out if the given point is inside the object bounding box. | |
bool | PointInBBox (const GLfloat *p) |
Finds out if the given point is inside the object bounding box. | |
void | LocalToWorld (const GLfloat *inpoint, GLfloat *outpoint) |
Brings a point from obj-space coordinates to world coordinates. | |
bool | IsRoot () |
Finds out if this object is a root object, i.e. has no parent. | |
VR3Obj * | GetParent () |
Returns the parent of this object. | |
Transformation Functions | |
void | SetRotation (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) |
Sets the rotation of the object around the specified axis. | |
void | SetRotation (GLfloat angle, GLfloat *axis) |
Sets the rotation of the object around the specified axis. | |
void | RotateLocal (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) |
Rotates the object around the specified axis (local coordinates) | |
void | RotateLocal (GLfloat angle, GLfloat *axis) |
Rotates the object around the specified axis (local coordinates) | |
void | RotateGlobal (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) |
Rotates the object around the specified axis (parent or world coordinates) | |
void | RotateGlobal (GLfloat angle, const GLfloat *axis) |
Rotates the object around the specified axis (parent or world coordinates) | |
void | TranslateLocal (GLfloat x, GLfloat y, GLfloat z) |
Moves the object along the main axes (local coordinates) | |
void | TranslateLocal (const GLfloat *vec) |
Moves the object along the main axes (local coordinates) | |
void | TranslateGlobal (GLfloat x, GLfloat y, GLfloat z) |
Moves the object along the main axes (parent or world coordinates) | |
void | TranslateGlobal (const GLfloat *vec) |
Moves the object along the main axes (parent or world coordinates) | |
void | Normalize (GLfloat size) |
Scales the object to match the desired size. | |
Private Member Functions | |
VR3Obj (const VR3Obj &) | |
Disable default copy constructor. | |
VR3Obj & | operator= (const VR3Obj &) |
Disable default assignment operator. | |
Modeling Tranformation Extraction Function | |
void | TotModelMatrix (GLfloat *modelmat) const |
Extract the total transformation matrix of an object. | |
Private Attributes | |
GLfloat | m_lod_activations [VR3OBJ_NUM_LODS] |
The LOD activation distances (squared) | |
GLint | m_lod_count |
Effective number of LODs available. | |
std::set< VR3Obj * > | m_children |
Children objects. | |
VR3Obj * | m_parent |
Parent object (if any) | |
GLfloat | m_pos [3] |
Object position. | |
GLfloat | m_scale [3] |
Object scaling. | |
GLfloat | m_rotation_matrix [16] |
Object rotation matrix. | |
GLfloat | m_pivot [3] |
Current pivot point position for rotations. | |
VR3Mesh * | m_meshes [VR3OBJ_NUM_LODS] |
Meshes (possibly one for each LOD) | |
bool | m_ishidden |
Hidden flag. | |
Friends | |
class | VR3PhysicsSimulator |
Friend physics simulator class to access the meshes. | |
Constructor and Destructor | |
void | Init () |
VR3Obj Initialization function. | |
VR3Obj () | |
VR3Obj constructor. | |
VR3Obj (const char *mesh_file, GLfloat x=0.0f, GLfloat y=0.0f, GLfloat z=0.0f, const char *mesh_name=0, int objID=-1) | |
VR3Obj constructor. | |
VR3Obj (VR3Mesh *mesh) | |
VR3Obj constructor. | |
~VR3Obj () | |
VR3Obj destructor. | |
Drawing Functions | |
void | Draw (const GLfloat *modelmat, int flags) |
Real drawing method. | |
void | Draw (int flags=0) |
Draws the object and possibly all the children objects. |
The object class.
The VR3Obj class implements the functionalities related to the visual objects. Objects contain spatial information (i.e. position, rotation, and scale) of the visual entity which it is linked to, such as Meshes. Every object represent a geometrical transformation, therefore different objects can be linked to the same mesh (or billboard, etc.) as this allow to save memory if more instances of the same visual entity have to be displayed. The linked entities undergo all the geometrical transformation of the objects which they are connected to. In addition to visual entities, it is also possible to link objects to other objects, in order to create hierarchies which allow to manage articulations or complex links. Every geometrical transformation applied to an object is also propagated to all its children. When a Draw is issued on an object, all its children are drawn first, and then the linked visual entity is also drawn. It is possible to create empty objects which represent pure geometrical transformations which allow to realize complex transformations by composing simple transformations.
It is possible to associate to the same object more than one mesh (exclusively instances of the VR3Mesh class), representing the same geometrical entity with different levels of detail. However, only one of these, the active mesh, can be drawn. A mesh becomes active when the distance between the object and the camera is lower than a certain activation distance.
NOTE:
When dealing with object hierarchies, the user should be aware that undesired results may arise in case of transparent (or translucent) objects in the chain. Translucent objects should be rendered after opaque objects to allow alpha blending to occour as expected: if a translucent object is rendered before an opaque one, even if the opaque object is behind the translucent one, its fragments will fail the depth test and not be drawn behind the transparent object. In our case, children object are always drawn first, in the order specified when adding them to their parent. Even if it were possible to specify an arbitrary order between a parent and its children, there is no way a user can specify an order that works in all cases. Imagine the following situation.
If obj2 is rendered before obj1, obj3 rendering is triggered before rendering of obj1, that is, it will be possible to see both obj2 and and obj3 behind the transparent object obj1, but it won't be possible to see obj1 behind obj3 (because obj3 is rendered first and obj1 will fail the depth test).
Definition at line 77 of file VR3Obj.h.
VR3Obj::VR3Obj | ( | const VR3Obj & | ) | [private] |
Disable default copy constructor.
VR3Obj::VR3Obj | ( | ) |
VR3Obj::VR3Obj | ( | const char * | mesh_file, |
GLfloat | x = 0.0f , |
||
GLfloat | y = 0.0f , |
||
GLfloat | z = 0.0f , |
||
const char * | mesh_name = 0 , |
||
int | objID = -1 |
||
) |
VR3Obj constructor.
This constructor initializes the VR3Obj and loads the mesh from the specified AAM file. The mesh_name specifies which object to load from the AAM file (perhaps representing the whole scene). The ID may be used to identify the desired object as well. If no objID or name is specified, an undefined object from the file will be loaded. To specify a null name value but explicitly specify the desired objID, a name of 0 must be passed to the function (NULL).
[in] | mesh_file | The name of the VR3Mesh file to load and link |
[in] | x,y,z | The new object position |
[in] | mesh_name | The name of the object to load from the file |
[in] | objID | Object ID of the desired object in the AAM file |
VR3Obj::VR3Obj | ( | VR3Mesh * | mesh ) |
VR3Obj::~VR3Obj | ( | ) |
VR3Obj destructor.
int VR3Obj::AddChild | ( | VR3Obj * | c, |
GLfloat | x, | ||
GLfloat | y, | ||
GLfloat | z | ||
) |
Makes the specified object child of this object.
Allows to create hierarchies among the objects in the scene. The VR3Obj child object is linked to the current object and it inherits all its geometrical transformations. The user must specify the position (posx, posy, posz) of the origin of the child reference frame with respect to the parent reference frame.
[in] | c | The object to attach |
[in] | x,y,z | Offsets with reference to the parent reference frame |
int VR3Obj::AddChild | ( | VR3Obj * | c ) |
Makes the specified object child of this object.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function does not change the child object position depending on the provided parameters.
[in] | c | The object to attach |
void VR3Obj::Draw | ( | const GLfloat * | modelmat, |
int | flags | ||
) | [private] |
Real drawing method.
This method is called recursively when issueing a public Draw() call, here is where the real rendering takes place. The distinction between a private and a public Draw() methods is needed to avoid the public user to provide a specific modeling matrix, the user will simply call the Draw() public method without noticing that the method is simply mapped onto a private Draw() call with initial identity model matrix. At each recursive call, the modelmat parameter represents the resulting modeling matrix from the chain of ancestors transformations. The first call to the public Draw() method will therefore call the private Draw method simply specifying the identity matrix, this will be progressively transformed depending on the objects transformations.
[in] | modelmat | The ancestors transformations final modeling matrix |
[in] | flags | Draw flags |
void VR3Obj::Draw | ( | int | flags = 0 ) |
Draws the object and possibly all the children objects.
The VR3Obj object is drawn. All the hierarchy of its children is also recursively traversed and drawn.
[in] | flags | Draw flags |
VR3Mesh* VR3Obj::GetMesh | ( | int | lod = 0 ) |
Gets one of the mesh associated with the object.
A VR3Obj object may have multiple meshes associated with it, at most one for each possible level of detail. With this function the user may recover a reference to that mesh. Be aware that this operation effectively means that a new reference to the mesh is now active. When the user has finished with this reference (even if it has used it to load meshes in objects), the VR3Mesh::Destroy() function should be called.
[in] | lod | The required level of detail mesh return The required mesh or 0 if not found |
VR3Obj* VR3Obj::GetParent | ( | ) | [inline] |
void VR3Obj::GetPivotPoint | ( | GLfloat * | vec ) |
Gets the position of the pivot point.
Retrieves the pivot point position of the current object, i.e. the point in which the rotation axis is fixed. The coordinates are expressed in the parent's reference frame. If the object has no parent, the pivot point position is expressed in world coordinates.
[out] | vec | The retrieved pivot point position (3 components) |
void VR3Obj::GetPosition | ( | GLfloat * | p ) |
Retrieves the position of the current object.
Returns the position of the current object expressed the parent's reference frame or, if the object has no parent, in world coordinates.
[out] | p | The retrieved object position (3 components) |
void VR3Obj::GetRotationMatrix | ( | GLfloat * | m ) |
Retrieves the rotation matrix of the current object.
Returns the current orientation of the object as a 16-elements array, notice that this orientation matrix is relative to the parent orientation matrix. The matrix is in column-major order.
[out] | m | The rotation matrix (16 components) |
void VR3Obj::GetScale | ( | GLfloat * | s ) |
Gets the object scale.
Returns the current scaling of the object as a 3-components vector (one for each axis).
[out] | s | The retrieved scaling vector (3 components) |
void VR3Obj::Hide | ( | ) | [inline] |
void VR3Obj::Init | ( | ) | [private] |
bool VR3Obj::IsRoot | ( | ) | [inline] |
Finds out if this object is a root object, i.e. has no parent.
It may be useful tu understand if an object is a root object, for example to avoid rendering the children object if already rendered by their parent.
void VR3Obj::LinkToMesh | ( | VR3Mesh * | m, |
GLfloat | dist = 0.0f |
||
) |
Links a mesh to this object.
Links the specified VR3Mesh to the current object. If no activation distance is specified, the linked mesh is the base one (full detail), otherwise it is added to the group of meshes linked to the current object. At run-time, one of these meshes will be selected when drawing the corresponding VR3Obj, according to the distance between the camera and the object.
[in] | m | The mesh to link |
[in] | dist | The activation distance |
void VR3Obj::LocalToWorld | ( | const GLfloat * | inpoint, |
GLfloat * | outpoint | ||
) |
Brings a point from obj-space coordinates to world coordinates.
This function may be called to figure out the position of an object space point into the world (compute its world position). Please note that this function (as any other VR3Obj function implying position or transformations) only has the desired effect if the scene is not being physically simulated. This function also works in case of hierarchies, but this is done through a recursive chain exploration and therefore the user should avoid calling this function repeatedly (it might be very time consuming). Note that inpoint may equal outpoint.
[in] | inpoint | Point in object coordinates |
[out] | outpoint | Computed world space position |
void VR3Obj::Normalize | ( | GLfloat | size ) |
Scales the object to match the desired size.
This function sets the scaling factors for the current object to fit the main mesh bounding box inside the desired size. The scaling factors are set but the mesh is unaltered, a new scaling will erase the effect of the Normalize() call.
[in] | size | The desired size |
bool VR3Obj::PointInBBox | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Finds out if the given point is inside the object bounding box.
This function is used to discover if a given world-space point is inside the object bounding box or not. Bounding boxes are computed once when a mesh is loaded and we check if the point belongs to the base level of detail (LOD = 0) bounding box (the most accurate one). This function takes into account all object ancestors and therefore it may be quite time-consuming. If this function is to be called extensively, we recommend calling it only on root or near-root objects.
[in] | x,y,z | Coordinates of the world space point |
bool VR3Obj::PointInBBox | ( | const GLfloat * | p ) | [inline] |
Finds out if the given point is inside the object bounding box.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | p | Point world position vector |
int VR3Obj::RemoveChild | ( | VR3Obj * | c ) |
Removes the specified object from the list of child objects.
Detaches a child object from the current object, notice that the object is not deleted and will continue existing as a separate object with its children.
[in] | c | The object to detach |
void VR3Obj::RotateGlobal | ( | GLfloat | angle, |
GLfloat | x, | ||
GLfloat | y, | ||
GLfloat | z | ||
) |
Rotates the object around the specified axis (parent or world coordinates)
Rotates the current object of angle degrees around the axis defined by (x,y,z) running through the object's pivot point. The axis is expressed in global world coordinates if the object has no parent or in the parent's reference system otherways. The default pivot point is the origin of the object's local reference frame. The specified rotation is added to previous rotations, allowing the composition of subsequent rotations.
[in] | angle | The rotation angle |
[in] | x,y,z | The rotation axis components |
void VR3Obj::RotateGlobal | ( | GLfloat | angle, |
const GLfloat * | axis | ||
) | [inline] |
Rotates the object around the specified axis (parent or world coordinates)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | angle | The rotation angle |
[in] | axis | The rotation axis (3 components) |
void VR3Obj::RotateLocal | ( | GLfloat | angle, |
GLfloat * | axis | ||
) | [inline] |
Rotates the object around the specified axis (local coordinates)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | angle | The rotation angle |
[in] | axis | The rotation axis (3 components) |
void VR3Obj::RotateLocal | ( | GLfloat | angle, |
GLfloat | x, | ||
GLfloat | y, | ||
GLfloat | z | ||
) |
Rotates the object around the specified axis (local coordinates)
Rotates the current object of angle degrees around the axis defined by (x,y,z) running through the object's pivot point. The axis is expressed in the current object local coordinates. The default pivot point is the origin of the object's local reference frame. The specified rotation is added to previous rotations, allowing the composition of subsequent rotations.
[in] | angle | The rotation angle |
[in] | x,y,z | The rotation axis components |
void VR3Obj::SetPivotPoint | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Sets the position of the pivot point.
Sets the pivot point of the current object, i.e. the point in which the rotation axis is fixed. By default the pivot point coincides with the origin of the reference frame. Changing the pivot point position allows the object to rotate around an axis different from the default one The coordinates are expressed in the parent's reference frame. If the object has no parent, the pivot point position is expressed in world coordinates.
[in] | x,y,z | The pivot point position coordinates |
void VR3Obj::SetPivotPoint | ( | const GLfloat * | vec ) |
Sets the position of the pivot point.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | vec | The pivot point position (3 components) |
void VR3Obj::SetPosition | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Sets the object position.
Sets the position of the current object. The coordinates are expressed in the parent's reference frame. If the object has no parent, the position is expressed in world coordinates.
[in] | x,y,z | The coordinates of the new object position |
void VR3Obj::SetPosition | ( | const GLfloat * | point ) |
Sets the object position.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | point | The new object position (3 components) |
void VR3Obj::SetRotation | ( | GLfloat | angle, |
GLfloat * | axis | ||
) | [inline] |
Sets the rotation of the object around the specified axis.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | angle | The rotation angle |
[in] | axis | The rotation axis (3 components) |
void VR3Obj::SetRotation | ( | GLfloat | angle, |
GLfloat | x, | ||
GLfloat | y, | ||
GLfloat | z | ||
) |
Sets the rotation of the object around the specified axis.
Rotates the current object of angle degrees around the axis defined by (x,y,z) running through the object's pivot point. The default pivot point is the origin of the object's local reference frame. The specified rotation overwrites previous rotations (the rotation matrix is recalculated).
[in] | angle | The rotation angle |
[in] | x,y,z | The rotation axis components |
void VR3Obj::SetRotationMatrix | ( | const GLfloat * | m ) |
Sets the rotation matrix of the current object.
Sets the rotation matrix of the current object, forcing this way the orientation of the object with reference to the parent object (or the world if the object is a root object).
[in] | m | The new rotation matrix (16 components, column-major order) |
void VR3Obj::SetScale | ( | const GLfloat * | s ) |
Sets the scaling factors.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | s | The new object scale (3 components) |
void VR3Obj::SetScale | ( | GLfloat | scx, |
GLfloat | scy, | ||
GLfloat | scz | ||
) |
Sets the scaling factors.
Sets the scaling factors along the main axes. The scaling can be not-uniform specifying different factors, or uniform if the same factor is specified once for all axes.
[in] | scx,scy,scz | The scaling factors |
void VR3Obj::TotModelMatrix | ( | GLfloat * | modelmat ) | const [private] |
Extract the total transformation matrix of an object.
This function is used to recover the full modeling transformation matrix for a given object. Please not that this function precedes up on the scene graph to the root objects. For this reason, this function is quite time consuming.
[out] | modelmat | Final modeling matrix |
void VR3Obj::TranslateGlobal | ( | const GLfloat * | vec ) | [inline] |
void VR3Obj::TranslateGlobal | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Moves the object along the main axes (parent or world coordinates)
Moves the object along the main axes (or, if in a hierarchy, in the parent reference frame) of the specified amount, starting from its current position.
[in] | x,y,z | Translation vector components |
void VR3Obj::TranslateLocal | ( | const GLfloat * | vec ) | [inline] |
void VR3Obj::TranslateLocal | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Moves the object along the main axes (local coordinates)
Moves the object in its own reference frame of the specified amount, starting from its current position.
[in] | x,y,z | Translation vector components |
void VR3Obj::UnHide | ( | ) | [inline] |
friend class VR3PhysicsSimulator [friend] |
std::set<VR3Obj*> VR3Obj::m_children [private] |
bool VR3Obj::m_ishidden [private] |
GLfloat VR3Obj::m_lod_activations[VR3OBJ_NUM_LODS] [private] |
GLint VR3Obj::m_lod_count [private] |
VR3Mesh* VR3Obj::m_meshes[VR3OBJ_NUM_LODS] [private] |
VR3Obj* VR3Obj::m_parent [private] |
GLfloat VR3Obj::m_pivot[3] [private] |
GLfloat VR3Obj::m_pos[3] [private] |
GLfloat VR3Obj::m_rotation_matrix[16] [private] |
GLfloat VR3Obj::m_scale[3] [private] |