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

#include <RigidBody.hpp>

Inheritance diagram for jop::RigidBody:
jop::Collider jop::Component jop::SafeReferenceable< Collider >

Classes

class  ConstructInfo
 

Public Types

enum  Type {
  Type::Static, Type::Dynamic, Type::Kinematic, Type::StaticSensor,
  Type::KinematicSensor
}
 

Public Member Functions

 RigidBody (Object &object, World &world, const ConstructInfo &info)
 Constructor. More...
 
virtual ~RigidBody () override
 Destructor. More...
 
RigidBodysetGravityScale (const glm::vec3 &acceleration)
 Set gravity to the rigid body object. More...
 
glm::vec3 getGravityScale () const
 Get the gravity. More...
 
RigidBodysetFixedMovement (const glm::bvec3 &fixed)
 Sets the linear factor for rigid body. More...
 
glm::bvec3 hasFixedMovement () const
 Check if the movement is fixed. More...
 
RigidBodysetFixedRotation (const glm::bvec3 &axis)
 Sets/unsets the body to constantly rotate. More...
 
glm::bvec3 hasFixedRotation () const
 Check if the rotation is fixed. More...
 
RigidBodyapplyForce (const glm::vec3 &force, const glm::vec3 &rel_pos)
 Applies constant force to rigid bodies relative position. More...
 
RigidBodyapplyImpulse (const glm::vec3 &impulse, const glm::vec3 &rel_pos)
 Applies an impulse to rigid bodies relative position. More...
 
RigidBodyapplyTorque (const glm::vec3 &torque)
 Applies torque to the rigid body. More...
 
RigidBodyapplyTorqueImpulse (const glm::vec3 &torque)
 Applies torque impulse to the rigid body. More...
 
RigidBodysetLinearVelocity (const glm::vec3 &linearVelocity)
 Sets linear velocity to the rigid body. More...
 
glm::vec3 getLinearVelocity () const
 Get the linear (movement) velocity. More...
 
RigidBodysetAngularVelocity (const glm::vec3 &angularVelocity)
 Sets angular velocity to the rigid body. More...
 
glm::vec3 getAngularVelocity () const
 Get the angular (rotational) velocity. More...
 
RigidBodyapplyCentralForce (const glm::vec3 &force)
 Applies force to the rigid body's center. More...
 
RigidBodyapplyCentralImpulse (const glm::vec3 &impulse)
 Applies impulse to the rigid body's center. More...
 
RigidBodyclearForces ()
 Clear all the forces affecting this body. More...
 
std::pair< glm::vec3, glm::vec3 > getLocalBounds () const
 Get the local bounds of this body. More...
 
RigidBodysynchronizeTransform ()
 Sets the RigidBody position to be same as the objects' transform. More...
 
template<typename T >
T * getJoint (unsigned int id=0)
 Returns a pointer to a joint on the RigidBody whence called from. More...
 
template<typename T >
bool breakJoint (RigidBody &other, unsigned int IDthis=0, unsigned int IDother=0)
 Breaks a joint from the RigidBody whence called from. More...
 
template<typename T , typename... Args>
T & link (RigidBody &body, Args &&...args)
 Creates a joint between this RigidBody and another RigidBody. More...
 
- Public Member Functions inherited from jop::Collider
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

Message::Result receiveMessage (const Message &message) override
 Receive a message. More...
 
- Protected Member Functions inherited from jop::Collider
 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...
 
- 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< detail::MotionState > m_motionState
 The motion state. More...
 
const Type m_type
 The body type. More...
 
const float m_mass
 The mass. More...
 
btRigidBody * m_rigidBody
 Pointer to derived rigid body pointer for convenience. More...
 
std::unordered_set< std::shared_ptr< Joint > > m_joints
 Joints. More...
 
- Protected Attributes inherited from jop::Collider
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 Joint
 

Detailed Description

Definition at line 44 of file RigidBody.hpp.

Member Enumeration Documentation

enum jop::RigidBody::Type
strong

Rigid body type

Enumerator
Static 

Non-moving body.

Dynamic 

Moving body.

Kinematic 

User-animated body.

StaticSensor 

Non-moving.

KinematicSensor 

User-animated.

Definition at line 56 of file RigidBody.hpp.

Constructor & Destructor Documentation

jop::RigidBody::RigidBody ( Object object,
World world,
const ConstructInfo info 
)

Constructor.

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

Destructor.

Member Function Documentation

RigidBody& jop::RigidBody::applyCentralForce ( const glm::vec3 &  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
RigidBody& jop::RigidBody::applyCentralImpulse ( const glm::vec3 &  impulse)

Applies impulse to the rigid body's center.

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

Applies constant force to rigid bodies relative position.

Parameters
forceAmount and direction of the force
rel_posVector for the relative position on rigid body that the force applies on
Returns
Reference to self
This method is exposed as command named applyForce
RigidBody& jop::RigidBody::applyImpulse ( const glm::vec3 &  impulse,
const glm::vec3 &  rel_pos 
)

Applies an impulse to rigid bodies relative position.

Parameters
impulseAmount and direction of the impulse
rel_posVector for the relative position on rigid body that the impulse applies on
Returns
Reference to self
This method is exposed as command named applyImpulse
RigidBody& jop::RigidBody::applyTorque ( const glm::vec3 &  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
RigidBody& jop::RigidBody::applyTorqueImpulse ( const glm::vec3 &  torque)

Applies torque impulse 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 applyTorqueImpulse
template<typename T >
bool jop::RigidBody::breakJoint ( RigidBody other,
unsigned int  IDthis = 0,
unsigned int  IDother = 0 
)

Breaks a joint from the RigidBody whence called from.

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

Returns
Returns true if successful.
RigidBody& jop::RigidBody::clearForces ( )

Clear all the forces affecting this body.

Returns
Reference to self
This method is exposed as command named clearForces
glm::vec3 jop::RigidBody::getAngularVelocity ( ) const

Get the angular (rotational) velocity.

Returns
The angular velocity
glm::vec3 jop::RigidBody::getGravityScale ( ) const

Get the gravity.

Returns
The gravity scale
template<typename T >
T* jop::RigidBody::getJoint ( unsigned int  id = 0)

Returns a pointer to a joint on the RigidBody 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 RigidBody has.

Returns
Returns a pointer to the joint. nullptr if not found.
glm::vec3 jop::RigidBody::getLinearVelocity ( ) const

Get the linear (movement) velocity.

Returns
The linear velocity
std::pair<glm::vec3, glm::vec3> jop::RigidBody::getLocalBounds ( ) const

Get the local bounds of this body.

Returns
The local bounds
glm::bvec3 jop::RigidBody::hasFixedMovement ( ) const

Check if the movement is fixed.

Returns
The axis values
glm::bvec3 jop::RigidBody::hasFixedRotation ( ) const

Check if the rotation is fixed.

Returns
The axis values
template<typename T , typename... Args>
T& jop::RigidBody::link ( RigidBody body,
Args &&...  args 
)

Creates a joint between this RigidBody and another RigidBody.

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

Parameters
bodyThe other body to link with
argsThe arguments to pass to the joint's constructor
Returns
Returns a reference to the RigidBody whence called from.
Message::Result jop::RigidBody::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.

RigidBody& jop::RigidBody::setAngularVelocity ( const glm::vec3 &  angularVelocity)

Sets angular velocity to the rigid body.

Parameters
angularVelocityAmount and direction of the angular velocity
Returns
Reference to self
This method is exposed as command named setAngularVelocity
RigidBody& jop::RigidBody::setFixedMovement ( const glm::bvec3 &  fixed)

Sets the linear factor for rigid body.

Parameters
fixedAxes to disable movement
Returns
Reference to self
This method is exposed as command named setLinearFactor
RigidBody& jop::RigidBody::setFixedRotation ( const glm::bvec3 &  axis)

Sets/unsets the body to constantly rotate.

Parameters
axisAxes to disable rotations
Returns
Reference to self
This method is exposed as command named setFixedRotation
RigidBody& jop::RigidBody::setGravityScale ( const glm::vec3 &  acceleration)

Set gravity to the rigid body object.

Parameters
accelerationAmount of the gravity to be applied as vector
Returns
Reference to self
This method is exposed as command named setBodyGravity
RigidBody& jop::RigidBody::setLinearVelocity ( const glm::vec3 &  linearVelocity)

Sets linear velocity to the rigid body.

Parameters
linearVelocityAmount and direction of the linear velocity
Returns
Reference to self
This method is exposed as command named setLinearVelocity
RigidBody& jop::RigidBody::synchronizeTransform ( )

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

Returns
Reference to self.

Friends And Related Function Documentation

friend class Joint
friend

Definition at line 50 of file RigidBody.hpp.

Member Data Documentation

std::unordered_set<std::shared_ptr<Joint> > jop::RigidBody::m_joints
protected

Joints.

Definition at line 317 of file RigidBody.hpp.

const float jop::RigidBody::m_mass
protected

The mass.

Definition at line 314 of file RigidBody.hpp.

std::unique_ptr<detail::MotionState> jop::RigidBody::m_motionState
protected

The motion state.

Definition at line 312 of file RigidBody.hpp.

btRigidBody* jop::RigidBody::m_rigidBody
protected

Pointer to derived rigid body pointer for convenience.

Definition at line 315 of file RigidBody.hpp.

const Type jop::RigidBody::m_type
protected

The body type.

Definition at line 313 of file RigidBody.hpp.


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