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::Collider Class Referenceabstract

#include <Collider.hpp>

Inheritance diagram for jop::Collider:
jop::Component jop::SafeReferenceable< Collider > jop::PhantomBody jop::RigidBody jop::CullerComponent jop::Drawable jop::AnimatedSprite jop::SkyBox jop::SkySphere jop::Sprite jop::Text jop::World jop::World2D

Public Member Functions

bool checkOverlap (const Collider &other) const
 Check if this collider overlaps with another. More...
 
bool checkContact (const Collider &other) const
 Check if this collider is in contact with another. More...
 
bool checkRay (const glm::vec3 &start, const glm::vec3 &ray) const
 Check if a ray pierces this collider. More...
 
void registerListener (ContactListener &listener)
 Register a listener for this collider. More...
 
WorldgetWorld ()
 Get the world this collider belongs to. More...
 
const WorldgetWorld () const
 Get the world this collider belongs to. More...
 
void detachFromWorld ()
 Detach this body from its world. More...
 
void attachToWorld ()
 Attach this body to its world if it was previously detached. More...
 
bool isDetachedFromWorld () const
 Check if this body is currently detached from its world. More...
 
void updateWorldBounds ()
 Force update of the world space bounds. More...
 
void setCollisionShape (CollisionShape &shape)
 Set the collision shape. More...
 
const CollisionShapegetCollisionShape () const
 Get the collision shape. 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...
 
- Public Member Functions inherited from jop::SafeReferenceable< Collider >
WeakReference< CollidergetReference () const
 Get a weak reference to the bound object. More...
 

Protected Member Functions

 Collider (Object &object, World &world, const uint32 ID)
 Constructor. More...
 
 Collider (const Collider &other, Object &newObj)
 Copy constructor. More...
 
virtual ~Collider () 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 Member Functions inherited from jop::SafeReferenceable< Collider >
 SafeReferenceable (Collider *ref)
 Constructor. More...
 
 SafeReferenceable (SafeReferenceable< Collider > &&other)
 Move constructor. More...
 
SafeReferenceableoperator= (SafeReferenceable< Collider > &&other)
 Move assignment operator. More...
 
 ~SafeReferenceable ()
 Protected destructor. More...
 

Protected Attributes

std::unique_ptr< btCollisionObject > m_body
 Body data. More...
 
Worldm_worldRef
 Reference to the world. More...
 
std::set< ContactListener * > m_listeners
 Listeners registered for this collider. More...
 
bool m_detached
 Is this body detached from the world? More...
 
bool m_allowSleep
 Is sleep allowed? More...
 

Friends

class ContactListener
 
class Joint
 

Detailed Description

Definition at line 49 of file Collider.hpp.

Constructor & Destructor Documentation

jop::Collider::Collider ( Object object,
World world,
const uint32  ID 
)
protected

Constructor.

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

Copy constructor.

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

Virtual destructor.

Member Function Documentation

void jop::Collider::attachToWorld ( )

Attach this body to its world if it was previously detached.

bool jop::Collider::checkContact ( const Collider 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::Collider::checkOverlap ( const Collider 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::Collider::checkRay ( const glm::vec3 &  start,
const glm::vec3 &  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
void jop::Collider::detachFromWorld ( )

Detach this body from its world.

const CollisionShape* jop::Collider::getCollisionShape ( ) const

Get the collision shape.

Returns
Pointer to the shape. nullptr if none bound
World& jop::Collider::getWorld ( )

Get the world this collider belongs to.

Returns
Reference to the world
const World& jop::Collider::getWorld ( ) const

Get the world this collider belongs to.

Returns
Reference to the world
bool jop::Collider::isDetachedFromWorld ( ) const

Check if this body is currently detached from its world.

Returns
True if detached
bool jop::Collider::isSleepAllowed ( ) const
protected

Check if sleep is allowed.

Returns
True if allowed
void jop::Collider::registerListener ( ContactListener 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::Collider::setAllowSleep ( const bool  allow)
protected

Set whether the collider is allowed to sleep.

Parameters
allowTrue to allow sleep. True by default
void jop::Collider::setCollisionShape ( CollisionShape shape)

Set the collision shape.

Parameters
shapeThe new shape to set
void jop::Collider::update ( const float  deltaTime)
overrideprotectedvirtual

Update.

Parameters
deltaTimeThe delta time

Reimplemented from jop::Component.

Reimplemented in jop::World, jop::World2D, and jop::PhantomBody.

void jop::Collider::updateWorldBounds ( )

Force update of the world space bounds.

You'll usually want to call this when you've called CollisionShape::setLocalScale() for the bound collision shape.

Friends And Related Function Documentation

friend class ContactListener
friend

Definition at line 57 of file Collider.hpp.

friend class Joint
friend

Definition at line 58 of file Collider.hpp.

Member Data Documentation

bool jop::Collider::m_allowSleep
protected

Is sleep allowed?

Definition at line 187 of file Collider.hpp.

std::unique_ptr<btCollisionObject> jop::Collider::m_body
protected

Body data.

Definition at line 183 of file Collider.hpp.

bool jop::Collider::m_detached
protected

Is this body detached from the world?

Definition at line 186 of file Collider.hpp.

std::set<ContactListener*> jop::Collider::m_listeners
protected

Listeners registered for this collider.

Definition at line 185 of file Collider.hpp.

World& jop::Collider::m_worldRef
protected

Reference to the world.

Definition at line 184 of file Collider.hpp.


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