Private Member Functions | Private Attributes | Friends

VR3Obj Class Reference

The object class. More...

#include <VR3Obj.h>

Collaboration diagram for VR3Obj:
Collaboration graph
[legend]

List of all members.

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.
VR3MeshGetMesh (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.
VR3ObjGetParent ()
 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.
VR3Objoperator= (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.
VR3Objm_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.
VR3Meshm_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.

Detailed Description

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.


Constructor & Destructor Documentation

VR3Obj::VR3Obj ( const VR3Obj  ) [private]

Disable default copy constructor.

VR3Obj::VR3Obj (  )

VR3Obj constructor.

This constructor merely initializes a VR3Obj with default member values.

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).

Parameters:
[in]mesh_fileThe name of the VR3Mesh file to load and link
[in]x,y,zThe new object position
[in]mesh_nameThe name of the object to load from the file
[in]objIDObject ID of the desired object in the AAM file
VR3Obj::VR3Obj ( VR3Mesh mesh )

VR3Obj constructor.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
[in]meshThe VR3Mesh to link to the new object
VR3Obj::~VR3Obj (  )

VR3Obj destructor.


Member Function Documentation

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.

Parameters:
[in]cThe object to attach
[in]x,y,zOffsets with reference to the parent reference frame
Returns:
The number of resulting children for the current object
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.

Parameters:
[in]cThe object to attach
Returns:
The number of resulting children for the current object
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.

Parameters:
[in]modelmatThe ancestors transformations final modeling matrix
[in]flagsDraw 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.

Parameters:
[in]flagsDraw 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.

Parameters:
[in]lodThe required level of detail mesh return The required mesh or 0 if not found
VR3Obj* VR3Obj::GetParent (  ) [inline]

Returns the parent of this object.

If the object has no parent because it is a root object, 0 is returned.

Returns:
The parent VR3Obj pointer or null if no parent was found

Definition at line 444 of file VR3Obj.h.

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.

Parameters:
[out]vecThe 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.

Parameters:
[out]pThe 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.

Parameters:
[out]mThe 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).

Parameters:
[out]sThe retrieved scaling vector (3 components)
void VR3Obj::Hide (  ) [inline]

Hides the object an its children.

This method forces the object rendering to take no action, the object will not be visible no matter what. Notice that by setting an object as not visible all its children will be hidden as well.

Definition at line 366 of file VR3Obj.h.

void VR3Obj::Init (  ) [private]

VR3Obj Initialization function.

This function is the true initialization function called by all overloaded constructors, it writes some default values in the VR3Obj member variables.

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.

Returns:
true if the object is a root object, false otherways

Definition at line 435 of file VR3Obj.h.

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.

Parameters:
[in]mThe mesh to link
[in]distThe 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.

Parameters:
[in]inpointPoint in object coordinates
[out]outpointComputed 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.

Parameters:
[in]sizeThe desired size
VR3Obj& VR3Obj::operator= ( const VR3Obj  ) [private]

Disable default assignment operator.

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.

Parameters:
[in]x,y,zCoordinates of the world space point
Returns:
true if the point is in the bbox, false otherways
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.

Parameters:
[in]pPoint world position vector
Returns:
true if the point is in the bbox, false otherways

Definition at line 408 of file VR3Obj.h.

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.

Parameters:
[in]cThe object to detach
Returns:
The number of resulting children for the current object
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.

Parameters:
[in]angleThe rotation angle
[in]x,y,zThe 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.

Parameters:
[in]angleThe rotation angle
[in]axisThe rotation axis (3 components)

Definition at line 514 of file VR3Obj.h.

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.

Parameters:
[in]angleThe rotation angle
[in]axisThe rotation axis (3 components)

Definition at line 492 of file VR3Obj.h.

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.

Parameters:
[in]angleThe rotation angle
[in]x,y,zThe 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.

Parameters:
[in]x,y,zThe 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.

Parameters:
[in]vecThe 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.

Parameters:
[in]x,y,zThe 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.

Parameters:
[in]pointThe 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.

Parameters:
[in]angleThe rotation angle
[in]axisThe rotation axis (3 components)

Definition at line 471 of file VR3Obj.h.

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).

Parameters:
[in]angleThe rotation angle
[in]x,y,zThe 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).

Parameters:
[in]mThe 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.

Parameters:
[in]sThe 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.

Parameters:
[in]scx,scy,sczThe 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.

Parameters:
[out]modelmatFinal modeling matrix
void VR3Obj::TranslateGlobal ( const GLfloat *  vec ) [inline]

Moves the object along the main axes (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.

Parameters:
[in]vecTranslation vector (3 components)

Definition at line 545 of file VR3Obj.h.

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.

Parameters:
[in]x,y,zTranslation vector components
void VR3Obj::TranslateLocal ( const GLfloat *  vec ) [inline]

Moves the object along the main axes (local coordinates)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
[in]vecTranslation vector (3 components)

Definition at line 529 of file VR3Obj.h.

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.

Parameters:
[in]x,y,zTranslation vector components
void VR3Obj::UnHide (  ) [inline]

Unhides the object an its children.

This method renders the object visible again, its children will be hidden or not depending on their private visibility status.

Definition at line 372 of file VR3Obj.h.


Friends And Related Function Documentation

friend class VR3PhysicsSimulator [friend]

Friend physics simulator class to access the meshes.

Definition at line 80 of file VR3Obj.h.


Member Data Documentation

std::set<VR3Obj*> VR3Obj::m_children [private]

Children objects.

Definition at line 89 of file VR3Obj.h.

bool VR3Obj::m_ishidden [private]

Hidden flag.

Definition at line 106 of file VR3Obj.h.

GLfloat VR3Obj::m_lod_activations[VR3OBJ_NUM_LODS] [private]

The LOD activation distances (squared)

Definition at line 84 of file VR3Obj.h.

GLint VR3Obj::m_lod_count [private]

Effective number of LODs available.

Definition at line 86 of file VR3Obj.h.

VR3Mesh* VR3Obj::m_meshes[VR3OBJ_NUM_LODS] [private]

Meshes (possibly one for each LOD)

Definition at line 103 of file VR3Obj.h.

Parent object (if any)

Definition at line 91 of file VR3Obj.h.

GLfloat VR3Obj::m_pivot[3] [private]

Current pivot point position for rotations.

Definition at line 100 of file VR3Obj.h.

GLfloat VR3Obj::m_pos[3] [private]

Object position.

Definition at line 94 of file VR3Obj.h.

GLfloat VR3Obj::m_rotation_matrix[16] [private]

Object rotation matrix.

Definition at line 98 of file VR3Obj.h.

GLfloat VR3Obj::m_scale[3] [private]

Object scaling.

Definition at line 96 of file VR3Obj.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines