![]() |
Jopnal Engine
alpha 0.4
Simple Component Based 2D/3D Game Engine
|
#include <RigidBody2D.hpp>
Classes | |
class | ConstructInfo2D |
Public Member Functions | |
RigidBody2D (Object &object, World2D &world, const ConstructInfo2D &info) | |
Constructor. More... | |
virtual | ~RigidBody2D () override |
Destructor. More... | |
RigidBody2D & | setGravityScale (const float scale) |
Set gravity scaling to the rigid body object. More... | |
float | getGravityScale () const |
Get the gravity scale. More... | |
RigidBody2D & | setLinearVelocity (const glm::vec2 &linearVelocity) |
Sets the linear velocity for rigid body. More... | |
glm::vec2 | getLinearVelocity () const |
Get the linear velocity of the body. More... | |
RigidBody2D & | setAngularVelocity (const float angularVelocity) |
Sets the angular velocity for rigid body. More... | |
float | getAngularVelocity () const |
Gets the angular velocity as float. More... | |
RigidBody2D & | applyForce (const glm::vec2 &force, const glm::vec2 &worldPoint) |
Applies constant force to rigid bodies relative position. More... | |
RigidBody2D & | applyCentralForce (const glm::vec2 &force) |
Applies force to the rigid body's center. More... | |
RigidBody2D & | applyTorqueImpulse (const float impulse) |
Applies an impulse to rigid bodies relative position. More... | |
RigidBody2D & | applyLinearImpulse (const glm::vec2 &impulse, const glm::vec2 &point) |
Applies an impulse to rigid bodies relative position. More... | |
RigidBody2D & | applyCentralImpulse (const glm::vec2 &impulse) |
Applies impulse to the rigid body's center. More... | |
RigidBody2D & | applyTorque (const float torque) |
Applies torque to the rigid body. More... | |
RigidBody2D & | setFixedRotation (const bool rot) |
Sets/unsets the body to constantly rotate. More... | |
bool | hasFixedRotation () const |
Check if fixed rotation has been set. More... | |
RigidBody2D & | synchronizeTransform () |
Sets the RigidBody2D position to be same as the objects' transform. More... | |
RigidBody2D & | clearForces () |
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... | |
![]() | |
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... | |
World2D & | getWorld () |
Get the world this collider belongs to. More... | |
const World2D & | getWorld () const |
Get the world this collider belongs to. More... | |
![]() | |
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< Object > | getObject () |
Get the object this component is bound to. More... | |
WeakReference< const Object > | getObject () 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... | |
![]() | |
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... | |
![]() | |
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 |
![]() | |
b2Body * | m_body |
A RigidBody2D. More... | |
World2D & | m_worldRef2D |
Reference to the world. More... | |
std::set< ContactListener2D * > | m_listeners |
Bound contact listeners. More... | |
Definition at line 42 of file RigidBody2D.hpp.
jop::RigidBody2D::RigidBody2D | ( | Object & | object, |
World2D & | world, | ||
const ConstructInfo2D & | info | ||
) |
Constructor.
object | Reference to the object |
world | The physics world |
info | Construction info |
|
overridevirtual |
Destructor.
RigidBody2D& jop::RigidBody2D::applyCentralForce | ( | const glm::vec2 & | force | ) |
Applies force to the rigid body's center.
force | Amount and direction of the applied force |
RigidBody2D& jop::RigidBody2D::applyCentralImpulse | ( | const glm::vec2 & | impulse | ) |
Applies impulse to the rigid body's center.
impulse | Amount and direction of the impulse |
RigidBody2D& jop::RigidBody2D::applyForce | ( | const glm::vec2 & | force, |
const glm::vec2 & | worldPoint | ||
) |
Applies constant force to rigid bodies relative position.
force | Amount and direction of the force |
worldPoint | Vector for a point in the world that the force is applied to relative to the rigid body |
RigidBody2D& jop::RigidBody2D::applyLinearImpulse | ( | const glm::vec2 & | impulse, |
const glm::vec2 & | point | ||
) |
Applies an impulse to rigid bodies relative position.
impulse | Amount and direction of the impulse |
point | Vector for a point in world that the impulse is applied to relative to the rigid body |
RigidBody2D& jop::RigidBody2D::applyTorque | ( | const float | torque | ) |
Applies torque to the rigid body.
torque | Amount and direction as vector of the applied torque |
RigidBody2D& jop::RigidBody2D::applyTorqueImpulse | ( | const float | impulse | ) |
Applies an impulse to rigid bodies relative position.
impulse | Amount of the impulse |
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.
ID | The joint's identifier |
RigidBody2D& jop::RigidBody2D::clearForces | ( | ) |
Clear the affecting forces of this body.
|
protected |
Initializes m_body with a collidable object.
Handled by the engine.
float jop::RigidBody2D::getAngularVelocity | ( | ) | const |
Gets the angular velocity as float.
float jop::RigidBody2D::getGravityScale | ( | ) | const |
Get the gravity scale.
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.
ID | The joint's identifier |
glm::vec2 jop::RigidBody2D::getLinearVelocity | ( | ) | const |
Get the linear velocity of the body.
bool jop::RigidBody2D::hasFixedRotation | ( | ) | const |
Check if fixed rotation has been set.
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.
body | The other body to link |
args | The arguments to pass to the joint's constructor |
|
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.
message | The message |
Reimplemented from jop::Component.
RigidBody2D& jop::RigidBody2D::setAngularVelocity | ( | const float | angularVelocity | ) |
Sets the angular velocity for rigid body.
angularVelocity | Unique float for angular velocity |
RigidBody2D& jop::RigidBody2D::setFixedRotation | ( | const bool | rot | ) |
Sets/unsets the body to constantly rotate.
rot | Enable/disable body from rotating. Resets the mass of the body. |
RigidBody2D& jop::RigidBody2D::setGravityScale | ( | const float | scale | ) |
Set gravity scaling to the rigid body object.
scale | Scale of the gravity to be applied as float |
RigidBody2D& jop::RigidBody2D::setLinearVelocity | ( | const glm::vec2 & | linearVelocity | ) |
Sets the linear velocity for rigid body.
linearVelocity | Unique vector for linear velocity |
RigidBody2D& jop::RigidBody2D::synchronizeTransform | ( | ) |
Sets the RigidBody2D position to be same as the objects' transform.
|
protected |
All the joints that this body has.
Definition at line 283 of file RigidBody2D.hpp.