Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
jop::Collider2D Class Referenceabstract

#include <Collider2D.hpp>

Inheritance diagram for jop::Collider2D:
jop::Component jop::RigidBody2D

Public Member Functions

bool checkOverlap (const Collider2D &other) const
 Check if this collider overlaps with another. More...
 
bool checkContact (const Collider2D &other) const
 Check if this collider is in contact with another. More...
 
bool checkRay (const glm::vec2 &start, const glm::vec2 &ray) const
 Check if a ray pierces this collider. More...
 
void registerListener (ContactListener2D &listener)
 Register a listener for this collider. More...
 
World2DgetWorld ()
 Get the world this collider belongs to. More...
 
const World2DgetWorld () const
 Get the world this collider belongs to. More...
 
- Public Member Functions inherited from jop::Component
virtual ~Component ()=0
 Virtual destructor. More...
 
Message::Result sendMessage (const Message &message)
 Send a message to this component. More...
 
uint32 getID () const
 Get the identifier. More...
 
void setID (const uint32 ID)
 Set the identifier. More...
 
WeakReference< ObjectgetObject ()
 Get the object this component is bound to. More...
 
WeakReference< const ObjectgetObject () const
 Get the object this component is bound to. More...
 
bool isActive () const
 Check if this component is active. More...
 
void removeSelf ()
 Remove this component from its object. More...
 

Protected Member Functions

 Collider2D (Object &object, World2D &world, const uint32 ID)
 Constructor. More...
 
 Collider2D (const Collider2D &other, Object &newObj)
 Copy constructor. More...
 
virtual ~Collider2D () override=0
 Virtual destructor. More...
 
void update (const float deltaTime) override
 Update. More...
 
void setAllowSleep (const bool allow)
 Set whether the collider is allowed to sleep. More...
 
bool isSleepAllowed () const
 Check if sleep is allowed. More...
 
- Protected Member Functions inherited from jop::Component
 Component (Object &object, const uint32 ID)
 Constructor. More...
 
 Component (const Component &other, Object &newObj)
 Copy constructor. More...
 
virtual Message::Result receiveMessage (const Message &message)
 Receive a message. More...
 

Protected Attributes

b2Body * m_body
 A RigidBody2D. More...
 
World2Dm_worldRef2D
 Reference to the world. More...
 
std::set< ContactListener2D * > m_listeners
 Bound contact listeners. More...
 

Friends

class ContactListener2D
 
class Joint2D
 

Detailed Description

Definition at line 46 of file Collider2D.hpp.

Constructor & Destructor Documentation

jop::Collider2D::Collider2D ( Object object,
World2D world,
const uint32  ID 
)
protected

Constructor.

Parameters
objectReference to the object
worldReference to the physics world
IDId of this component
jop::Collider2D::Collider2D ( const Collider2D other,
Object newObj 
)
protected

Copy constructor.

Parameters
otherThe other collider to copy
newObjThe new object
virtual jop::Collider2D::~Collider2D ( )
overrideprotectedpure virtual

Virtual destructor.

Member Function Documentation

bool jop::Collider2D::checkContact ( const Collider2D other) const

Check if this collider is in contact with another.

Parameters
otherThe other collider to check against
Returns
True if the two colliders are in contact
bool jop::Collider2D::checkOverlap ( const Collider2D other) const

Check if this collider overlaps with another.

This will compare the axis-aligned bounding boxes. To check if two colliders are actually touching, use checkContact().

Parameters
otherThe other collider to check against
Returns
True if the two colliders are overlapping
bool jop::Collider2D::checkRay ( const glm::vec2 &  start,
const glm::vec2 &  ray 
) const

Check if a ray pierces this collider.

Parameters
startThe start position of the ray
rayRay to be shot from start
Returns
True if the ray pierces this collider
World2D& jop::Collider2D::getWorld ( )

Get the world this collider belongs to.

Returns
Reference to the 2D world
const World2D& jop::Collider2D::getWorld ( ) const

Get the world this collider belongs to.

Returns
Reference to the 2D world
bool jop::Collider2D::isSleepAllowed ( ) const
protected

Check if sleep is allowed.

Returns
True if allowed
void jop::Collider2D::registerListener ( ContactListener2D listener)

Register a listener for this collider.

Single collider can have multiple listeners

Parameters
listenerReference to the listener which is to be registered for this collider
void jop::Collider2D::setAllowSleep ( const bool  allow)
protected

Set whether the collider is allowed to sleep.

Parameters
allowTrue to allow sleep. True by default
void jop::Collider2D::update ( const float  deltaTime)
overrideprotectedvirtual

Update.

Parameters
deltaTimeThe delta time

Reimplemented from jop::Component.

Friends And Related Function Documentation

friend class ContactListener2D
friend

Definition at line 50 of file Collider2D.hpp.

friend class Joint2D
friend

Definition at line 55 of file Collider2D.hpp.

Member Data Documentation

b2Body* jop::Collider2D::m_body
protected

A RigidBody2D.

Definition at line 141 of file Collider2D.hpp.

std::set<ContactListener2D*> jop::Collider2D::m_listeners
protected

Bound contact listeners.

Definition at line 143 of file Collider2D.hpp.

World2D& jop::Collider2D::m_worldRef2D
protected

Reference to the world.

Definition at line 142 of file Collider2D.hpp.


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