CollisionModel Class Reference
[Game Data]

Basic class for collision detections. More...

#include <colmodel.h>

Collaboration diagram for CollisionModel:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CollisionModel ()
virtual ~CollisionModel ()
bool checkCollision (const CollisionModel &model)
 Checks if this model collides with another.
const GLVector3d & getAvoidVector ()
 get mAvoidVector
bool computeMinimalAvoidVector (const CollisionModel &model, GLVector3d &result)
 Compute minimal vector that avoids collision with second model.
double computeMinimalAvoidDistance (const CollisionModel &model, GLVector3d &direction)
 Compute scale of direction vector so that translation will avoid collision with second model.
void setTranslation (const GLVector3d &translation)
 Sets the translation ( to the world coordinates ) of the model.
void addTranslation (const GLVector3d &translation)
 Add the relative ranslation ( to the world coordinates ) of the model.
void setRotation (const GLQuaterniond &rotation)
 Sets the rotation (in the models coordinations) of the model.
void addRotation (const GLQuaterniond &rotation)
 Add the rotation (in the models coordinations) of the model.
void finishTransformations ()
 Finishes trasnsformations and computes final coordinates of model.
void resetTransformations ()
 Resets the transformations set by setTranslation() and setRotation().
bool isReseted () const
 Tells whether model is ready for applying transformations.
CDBoxgetModel ()
 Returns reference to the non-transformed model.
CDBoxgetTransModel ()
 Returns reference to the transformed model.
void setModel (const CDBox &model)
 Sets the model to the given box.

Private Attributes

CDBox mBox
 Default object box, the origin should be in center of object ( CommonEntity::mPosition respresents this point ).
CDBox mTransBox
 Box with applyied transformations.
bool mReseted
 True, if model is ready for applying new transformations.
GLVector3d mTranslation
 Vector, that stores translations.
GLQuaterniond mRotation
 Vector, that stores rotations.
GLVector3d mAvoidVector
 Stores result of colision detection.

Detailed Description

Basic class for collision detections.

Description of algorithm for detectiong colision between two CollisionModels. The idea is firstly to use min max test - CDBox::quickCheckCollision and then the algorihm try to find sepparating axis.

Definition at line 241 of file colmodel.h.


Constructor & Destructor Documentation

CollisionModel::CollisionModel  ) 
 

Definition at line 13 of file colmodel.cpp.

References mAvoidVector, mBox, mReseted, mRotation, mTransBox, mTranslation, ZERO_ROTATION_VECTOR, and CDBox::zeroize().

Here is the call graph for this function:

virtual CollisionModel::~CollisionModel  )  [inline, virtual]
 

Definition at line 245 of file colmodel.h.


Member Function Documentation

void CollisionModel::addRotation const GLQuaterniond &  rotation  )  [inline]
 

Add the rotation (in the models coordinations) of the model.

Parameters:
rotation Quaternion we want to add to current rotation.

Definition at line 328 of file colmodel.h.

void CollisionModel::addTranslation const GLVector3d &  translation  )  [inline]
 

Add the relative ranslation ( to the world coordinates ) of the model.

This may be used for incremental change of translation.

Parameters:
translation The vector of which we want to relatively translate

Definition at line 308 of file colmodel.h.

bool CollisionModel::checkCollision const CollisionModel model  )  [inline]
 

Checks if this model collides with another.

Checks if this model collides with another. If this is true, you can get vector to avoid colision by calling getAvoidVector()

Parameters:
model Another model, which we are checking for collisions with this model
Returns:
True, if there's a collision

Definition at line 254 of file colmodel.h.

double CollisionModel::computeMinimalAvoidDistance const CollisionModel model,
GLVector3d &  direction
 

Compute scale of direction vector so that translation will avoid collision with second model.

Scale of direction vector and its length to avoid second model.

Parameters:
model Another model, which we are checking for collision with this model
direction Vector in vhich you want to move this box.
Returns:
zero if no collision

Definition at line 169 of file colmodel.cpp.

References mTransBox, CDBox::quickCheckCollision(), SEP_TESTMAX, SEPSELF_MINUSTESTMAX, and SEPSELF_TESTMAX.

Here is the call graph for this function:

bool CollisionModel::computeMinimalAvoidVector const CollisionModel model,
GLVector3d &  result
 

Compute minimal vector that avoids collision with second model.

Compute minimum vector and its length to avoid second model.

Parameters:
model Another model, which we are checking for collision with this model
result Vector that needs to be added (eg by addTranslation) to current translation vector of this model. The result is normalized. It may contain a garbage if no colision.
Returns:
true if there is a collision

Definition at line 44 of file colmodel.cpp.

References mTransBox, CDBox::quickCheckCollision(), SEP_TEST, SEPSELF_MINUSTEST, and SEPSELF_TEST.

Here is the call graph for this function:

void CollisionModel::finishTransformations  )  [inline]
 

Finishes trasnsformations and computes final coordinates of model.

Call this everytime you change translation, rotation or model. Else the collisions won't return correct results.

Definition at line 338 of file colmodel.h.

Referenced by CommonEntity::tranformColModel().

const GLVector3d& CollisionModel::getAvoidVector  )  [inline]
 

get mAvoidVector

The vector is (may be) computed in checkCollision call

Returns:
mAvoidVector

Definition at line 265 of file colmodel.h.

CDBox& CollisionModel::getModel  )  [inline]
 

Returns reference to the non-transformed model.

Note:
don't forget to call finishTransformations() is you modify the model.
Returns:
Reference to model without transformations

Definition at line 371 of file colmodel.h.

Referenced by Tank::render().

CDBox& CollisionModel::getTransModel  )  [inline]
 

Returns reference to the transformed model.

Returns:
Reference to model with transformations

Definition at line 380 of file colmodel.h.

Referenced by TaskSimulationServer::checkTerrainHeights().

bool CollisionModel::isReseted  )  const [inline]
 

Tells whether model is ready for applying transformations.

Definition at line 360 of file colmodel.h.

void CollisionModel::resetTransformations  )  [inline]
 

Resets the transformations set by setTranslation() and setRotation().

Definition at line 349 of file colmodel.h.

Referenced by CommonEntity::tranformColModel().

void CollisionModel::setModel const CDBox model  )  [inline]
 

Sets the model to the given box.

Parameters:
model Box that will be the model

Definition at line 389 of file colmodel.h.

void CollisionModel::setRotation const GLQuaterniond &  rotation  )  [inline]
 

Sets the rotation (in the models coordinations) of the model.

Parameters:
rotation Quaternion we want to rotate by. (Like CommonEntity::mOrientation)

Definition at line 318 of file colmodel.h.

Referenced by CommonEntity::tranformColModel().

void CollisionModel::setTranslation const GLVector3d &  translation  )  [inline]
 

Sets the translation ( to the world coordinates ) of the model.

The old translation is deleted.

Parameters:
translation The vector of which we want to translate

Definition at line 297 of file colmodel.h.

Referenced by CommonEntity::tranformColModel().


Member Data Documentation

GLVector3d CollisionModel::mAvoidVector [private]
 

Stores result of colision detection.

Definition at line 406 of file colmodel.h.

Referenced by CollisionModel().

CDBox CollisionModel::mBox [private]
 

Default object box, the origin should be in center of object ( CommonEntity::mPosition respresents this point ).

Definition at line 396 of file colmodel.h.

Referenced by CollisionModel().

bool CollisionModel::mReseted [private]
 

True, if model is ready for applying new transformations.

Definition at line 400 of file colmodel.h.

Referenced by CollisionModel().

GLQuaterniond CollisionModel::mRotation [private]
 

Vector, that stores rotations.

Definition at line 404 of file colmodel.h.

Referenced by CollisionModel().

CDBox CollisionModel::mTransBox [private]
 

Box with applyied transformations.

Definition at line 398 of file colmodel.h.

Referenced by CollisionModel(), computeMinimalAvoidDistance(), and computeMinimalAvoidVector().

GLVector3d CollisionModel::mTranslation [private]
 

Vector, that stores translations.

Definition at line 402 of file colmodel.h.

Referenced by CollisionModel().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:12:32 2006 for bjs by  doxygen 1.4.5