UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pyramidworks::collision::CollisionObject Class Reference

A class that knows how to manage collisions. More...

#include <pyramidworks/collision/collisionobject.h>

Public Member Functions

 CollisionObject (CollisionData *data, const std::string &colclass, std::unique_ptr< geometry::GeometricShape > &&shape)
 
 ~CollisionObject ()
 
void SearchCollisions (std::list< CollisionInstance > &collision_list) const
 Search if there's any collision. More...
 
bool IsColliding (const CollisionObject *obj) const
 Verifies if this CollisionObject is colliding with another CollisionObject. More...
 
void AddCollisionLogic (const std::string &colclass, const CollisionLogic &logic)
 Adds a new collision to the known collisions. More...
 
void RemoveCollisionLogic (const std::string &colclass)
 Removes a collision from the known collisions. More...
 
void ChangeCollisionClass (const std::string &)
 Changes the collision class associated with this object. More...
 
void StartColliding (CollisionManager *)
 Enables collisions with this object in the given CollisionManager. More...
 
void StopColliding ()
 Removes this object from it's CollisionClass object list. More...
 
void MoveTo (const ugdk::math::Vector2D &position)
 Moves the object to the given position. More...
 
ugdk::structure::Box< 2 > CreateBoundingBox () const
 Wrapper to shape()->CreateBoundingBox(absolute_position()) More...
 
ugdk::math::Vector2D absolute_position () const
 Calculates the position of this object, with the offset added. More...
 
void ChangeShape (std::unique_ptr< geometry::GeometricShape > &&shape)
 Changes the shape used. More...
 
const std::string & collision_class () const
 Returns the name of the collision class of this object. More...
 
CollisionDatadata () const
 Returns the CollisionData associated with this object. More...
 
const ugdk::math::Vector2Dposition () const
 Returns the position of this object. More...
 
const ugdk::math::Vector2Doffset () const
 Returns the offset of this object. More...
 
const geometry::GeometricShapeshape () const
 Returns the shape used. More...
 
void set_offset (const ugdk::math::Vector2D &_offset)
 Changes the offset of this object. More...
 
void set_data (CollisionData *data)
 Changes the data of this object. More...
 

Detailed Description

A class that knows how to manage collisions.

It encapsulates everything that is related to collisions, from finding the collisions to calling the corresponding methods.

Constructor & Destructor Documentation

pyramidworks::collision::CollisionObject::CollisionObject ( CollisionData data,
const std::string &  colclass,
std::unique_ptr< geometry::GeometricShape > &&  shape 
)
Parameters
dataThe data sent to the CollisionLogic when a collision happens.
colclassName of the collision class of this object.
shapeThe shape for this object.
See also
CollisionLogic
pyramidworks::collision::CollisionObject::~CollisionObject ( )

Member Function Documentation

ugdk::math::Vector2D pyramidworks::collision::CollisionObject::absolute_position ( ) const
inline

Calculates the position of this object, with the offset added.

void pyramidworks::collision::CollisionObject::AddCollisionLogic ( const std::string &  colclass,
const CollisionLogic logic 
)

Adds a new collision to the known collisions.

Parameters
colclassName of the collision class.
logicThe handler called when the collision occurs.
void pyramidworks::collision::CollisionObject::ChangeCollisionClass ( const std::string &  )

Changes the collision class associated with this object.

Parameters
colclassThe string representating the collision class to set to.
void pyramidworks::collision::CollisionObject::ChangeShape ( std::unique_ptr< geometry::GeometricShape > &&  shape)

Changes the shape used.

Parameters
shapeThe shape to use.
See also
GeometricShape
const std::string& pyramidworks::collision::CollisionObject::collision_class ( ) const
inline

Returns the name of the collision class of this object.

ugdk::structure::Box<2> pyramidworks::collision::CollisionObject::CreateBoundingBox ( ) const

Wrapper to shape()->CreateBoundingBox(absolute_position())

CollisionData* pyramidworks::collision::CollisionObject::data ( ) const
inline

Returns the CollisionData associated with this object.

bool pyramidworks::collision::CollisionObject::IsColliding ( const CollisionObject obj) const

Verifies if this CollisionObject is colliding with another CollisionObject.

Parameters
objThe CollisionObject to check against.
Returns
True if there's a collision with the given CollisionObject.
void pyramidworks::collision::CollisionObject::MoveTo ( const ugdk::math::Vector2D position)

Moves the object to the given position.

const ugdk::math::Vector2D& pyramidworks::collision::CollisionObject::offset ( ) const
inline

Returns the offset of this object.

const ugdk::math::Vector2D& pyramidworks::collision::CollisionObject::position ( ) const
inline

Returns the position of this object.

void pyramidworks::collision::CollisionObject::RemoveCollisionLogic ( const std::string &  colclass)

Removes a collision from the known collisions.

Parameters
colclassName of the collision class.
void pyramidworks::collision::CollisionObject::SearchCollisions ( std::list< CollisionInstance > &  collision_list) const

Search if there's any collision.

For each CollisionClass this object knows how to collide with, it gathers a list of CollisionObject it's colliding with and generates a list of the collisions.

Parameters
collision_listA list in which the result is appended to.
Returns
A list of CollisionInstance, appended to the collision_list argument.
void pyramidworks::collision::CollisionObject::set_data ( CollisionData data)
inline

Changes the data of this object.

void pyramidworks::collision::CollisionObject::set_offset ( const ugdk::math::Vector2D _offset)
inline

Changes the offset of this object.

const geometry::GeometricShape* pyramidworks::collision::CollisionObject::shape ( ) const
inline

Returns the shape used.

Returns
A const GeometricShape pointer.
void pyramidworks::collision::CollisionObject::StartColliding ( CollisionManager )

Enables collisions with this object in the given CollisionManager.

void pyramidworks::collision::CollisionObject::StopColliding ( )

Removes this object from it's CollisionClass object list.


The documentation for this class was generated from the following file: