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

#include <RigidBody2D.hpp>

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

Classes

class  ConstructInfo2D
 

Public Member Functions

 RigidBody2D (Object &object, World2D &world, const ConstructInfo2D &info)
 Constructor. More...
 
virtual ~RigidBody2D () override
 Destructor. More...
 
RigidBody2DsetGravityScale (const float scale)
 Set gravity scaling to the rigid body object. More...
 
float getGravityScale () const
 Get the gravity scale. More...
 
RigidBody2DsetLinearVelocity (const glm::vec2 &linearVelocity)
 Sets the linear velocity for rigid body. More...
 
glm::vec2 getLinearVelocity () const
 Get the linear velocity of the body. More...
 
RigidBody2DsetAngularVelocity (const float angularVelocity)
 Sets the angular velocity for rigid body. More...
 
float getAngularVelocity () const
 Gets the angular velocity as float. More...
 
RigidBody2DapplyForce (const glm::vec2 &force, const glm::vec2 &worldPoint)
 Applies constant force to rigid bodies relative position. More...
 
RigidBody2DapplyCentralForce (const glm::vec2 &force)
 Applies force to the rigid body's center. More...
 
RigidBody2DapplyTorqueImpulse (const float impulse)
 Applies an impulse to rigid bodies relative position. More...
 
RigidBody2DapplyLinearImpulse (const glm::vec2 &impulse, const glm::vec2 &point)
 Applies an impulse to rigid bodies relative position. More...
 
RigidBody2DapplyCentralImpulse (const glm::vec2 &impulse)
 Applies impulse to the rigid body's center. More...
 
RigidBody2DapplyTorque (const float torque)
 Applies torque to the rigid body. More...
 
RigidBody2DsetFixedRotation (const bool rot)
 Sets/unsets the body to constantly rotate. More...
 
bool hasFixedRotation () const
 Check if fixed rotation has been set. More...
 
RigidBody2DsynchronizeTransform ()
 Sets the RigidBody2D position to be same as the objects' transform. More...
 
RigidBody2DclearForces ()
 Clear the affecting forces of this body. More...
 
template<typename T >
T * getJoint (unsigned int id=0)
 Returns a pointer to a joint on the RigidBody2D whence called from. More...
 
template<typename T >
bool breakJoint (unsigned int ID=0)
 Breaks a joint from the RigidBody2D whence called from. More...
 
template<typename T , typename... Args>
T & link (RigidBody2D &body, Args &&...args)
 Creates a joint between this RigidBody2D and another RigidBody2D. More...
 
- Public Member Functions inherited from jop::Collider2D
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

Message::Result receiveMessage (const Message &message) override
 Receive a message. More...
 
void createCollidable (const ConstructInfo2D &info, const b2Shape &shape)
 Initializes m_body with a collidable object. More...
 
- Protected Member Functions inherited from jop::Collider2D
 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...
 

Protected Attributes

std::unordered_set< std::shared_ptr< Joint2D > > m_joints
 
- Protected Attributes inherited from jop::Collider2D
b2Body * m_body
 A RigidBody2D. More...
 
World2Dm_worldRef2D
 Reference to the world. More...
 
std::set< ContactListener2D * > m_listeners
 Bound contact listeners. More...
 

Detailed Description

Definition at line 42 of file RigidBody2D.hpp.

Constructor & Destructor Documentation

jop::RigidBody2D::RigidBody2D ( Object object,
World2D world,
const ConstructInfo2D info 
)

Constructor.

Parameters
objectReference to the object
worldThe physics world
infoConstruction info
virtual jop::RigidBody2D::~RigidBody2D ( )
overridevirtual

Destructor.

Member Function Documentation

RigidBody2D& jop::RigidBody2D::applyCentralForce ( const glm::vec2 &  force)

Applies force to the rigid body's center.

Parameters
forceAmount and direction of the applied force
Returns
Reference to self
This method is exposed as command named applyCentralForce
RigidBody2D& jop::RigidBody2D::applyCentralImpulse ( const glm::vec2 &  impulse)

Applies impulse to the rigid body's center.

Parameters
impulseAmount and direction of the impulse
Returns
Reference to self
This method is exposed as command named applyCentralImpulse
RigidBody2D& jop::RigidBody2D::applyForce ( const glm::vec2 &  force,
const glm::vec2 &  worldPoint 
)

Applies constant force to rigid bodies relative position.

Parameters
forceAmount and direction of the force
worldPointVector for a point in the world that the force is applied to relative to the rigid body
Returns
Reference to self
This method is exposed as command named applyForce
RigidBody2D& jop::RigidBody2D::applyLinearImpulse ( const glm::vec2 &  impulse,
const glm::vec2 &  point 
)

Applies an impulse to rigid bodies relative position.

Parameters
impulseAmount and direction of the impulse
pointVector for a point in world that the impulse is applied to relative to the rigid body
Returns
Reference to self
This method is exposed as command named applyImpulse
RigidBody2D& jop::RigidBody2D::applyTorque ( const float  torque)

Applies torque to the rigid body.

Parameters
torqueAmount and direction as vector of the applied torque
Returns
Reference to self
This method is exposed as command named applyTorque
RigidBody2D& jop::RigidBody2D::applyTorqueImpulse ( const float  impulse)

Applies an impulse to rigid bodies relative position.

Parameters
impulseAmount of the impulse
Returns
Reference to self
This method is exposed as command named applyImpulse
template<typename T >
bool jop::RigidBody2D::breakJoint ( unsigned int  ID = 0)

Breaks a joint from the RigidBody2D whence called from.

User can give an ID of the the joint which to break. If left empty, breaks the first joint the RigidBody2D has.

Parameters
IDThe joint's identifier
Returns
Returns true if successful.
RigidBody2D& jop::RigidBody2D::clearForces ( )

Clear the affecting forces of this body.

void jop::RigidBody2D::createCollidable ( const ConstructInfo2D info,
const b2Shape &  shape 
)
protected

Initializes m_body with a collidable object.

Handled by the engine.

float jop::RigidBody2D::getAngularVelocity ( ) const

Gets the angular velocity as float.

Returns
The angular velocity
float jop::RigidBody2D::getGravityScale ( ) const

Get the gravity scale.

Returns
float
template<typename T >
T* jop::RigidBody2D::getJoint ( unsigned int  id = 0)

Returns a pointer to a joint on the RigidBody2D whence called from.

User can give an ID of the the joint which to return. If left empty, returns a pointer to the first joint the RigidBody2D has.

Parameters
IDThe joint's identifier
Returns
Returns a pointer to the joint. nullptr if not found.
glm::vec2 jop::RigidBody2D::getLinearVelocity ( ) const

Get the linear velocity of the body.

Returns
The linear velocity
bool jop::RigidBody2D::hasFixedRotation ( ) const

Check if fixed rotation has been set.

Returns
True if set
template<typename T , typename... Args>
T& jop::RigidBody2D::link ( RigidBody2D body,
Args &&...  args 
)

Creates a joint between this RigidBody2D and another RigidBody2D.

T is the type of the joint to create. Applicable joints are derived from Joint2D.

Parameters
bodyThe other body to link
argsThe arguments to pass to the joint's constructor
Returns
Returns a reference to the RigidBody2D whence called from.
Message::Result jop::RigidBody2D::receiveMessage ( const Message message)
overrideprotectedvirtual

Receive a message.

Override this to handle messages sent to this. Don't forget to call the base class' method as well to ensure that the message gets forwarded correctly.

Parameters
messageThe message
Returns
The message result

Reimplemented from jop::Component.

RigidBody2D& jop::RigidBody2D::setAngularVelocity ( const float  angularVelocity)

Sets the angular velocity for rigid body.

Parameters
angularVelocityUnique float for angular velocity
Returns
Reference to self
This method is exposed as command named setAngularVelocity
RigidBody2D& jop::RigidBody2D::setFixedRotation ( const bool  rot)

Sets/unsets the body to constantly rotate.

Parameters
rotEnable/disable body from rotating. Resets the mass of the body.
Returns
Reference to self
This method is exposed as command named setFixedRotation
RigidBody2D& jop::RigidBody2D::setGravityScale ( const float  scale)

Set gravity scaling to the rigid body object.

Parameters
scaleScale of the gravity to be applied as float
Returns
Reference to self
This method is exposed as command named setGravityScale
RigidBody2D& jop::RigidBody2D::setLinearVelocity ( const glm::vec2 &  linearVelocity)

Sets the linear velocity for rigid body.

Parameters
linearVelocityUnique vector for linear velocity
Returns
Reference to self
This method is exposed as command named setLinearVelocity
RigidBody2D& jop::RigidBody2D::synchronizeTransform ( )

Sets the RigidBody2D position to be same as the objects' transform.

Returns
Reference to self.

Member Data Documentation

std::unordered_set<std::shared_ptr<Joint2D> > jop::RigidBody2D::m_joints
protected

All the joints that this body has.

Definition at line 283 of file RigidBody2D.hpp.


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