Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ime::RigidBody Class Referencefinal

A rigid body. More...

#include <RigidBody.h>

Inheritance diagram for ime::RigidBody:
ime::Object

Public Types

enum class  Type { Static = 0 , Kinematic , Dynamic }
 The rigid body type. More...
 
using Ptr = std::unique_ptr< RigidBody >
 Unique body pointer. More...
 
template<typename... Args>
using Callback = std::function< void(Args...)>
 Event listener. More...
 

Public Member Functions

 RigidBody (const RigidBody &)=delete
 Copy constructor. More...
 
RigidBodyoperator= (const RigidBody &)=delete
 Copy assignment operator. More...
 
 RigidBody (RigidBody &&) noexcept
 Move constructor. More...
 
RigidBodyoperator= (RigidBody &&) noexcept
 Move assignment operator. More...
 
RigidBody::Ptr copy () const
 Create a copy of the rigid body. More...
 
std::string getClassName () const override
 Get the name of this class. More...
 
ColliderattachCollider (Collider::Ptr collider)
 Attach a collider to the body. More...
 
CollidergetColliderById (unsigned int id)
 Get a collider by its id. More...
 
const CollidergetColliderById (unsigned int id) const
 
void removeColliderWithId (unsigned int id)
 Remove a collider with a given id from the body. More...
 
void setPosition (const Vector2f &position)
 Set the world position of the body's local origin. More...
 
Vector2f getPosition () const
 Get the world position of the body's origin. More...
 
void setRotation (float angle)
 Set the body's rotation about the world origin. More...
 
float getRotation () const
 Get the body's world rotation. More...
 
Vector2f getWorldCenter () const
 Get the world position of the centre of mass. More...
 
Vector2f getLocalCenter () const
 Get the local position of the centre of mass. More...
 
void setLinearVelocity (const Vector2f &velocity)
 Set the linear velocity of the body in pixels per second. More...
 
Vector2f getLinearVelocity () const
 Get the linear velocity of the centre of mass. More...
 
void setAngularVelocity (float degrees)
 Set the angular velocity in degrees per second. More...
 
float getAngularVelocity () const
 Get the angular velocity. More...
 
void applyForce (const Vector2f &force, const Vector2f &point, bool wake=true)
 Apply a force at a world point. More...
 
void applyForceToCenter (const Vector2f &force, bool wake=true)
 Apply a force to the centre of mass. More...
 
void applyTorque (float torque, bool wake=true)
 Apply a torque. More...
 
void applyLinearImpulse (const Vector2f &impulse, const Vector2f &point, bool wake=true)
 Apply an impulse at a world point. More...
 
void applyLinearImpulseToCenter (const Vector2f &impulse, bool wake=true)
 Apply an impulse at the centre of mass. More...
 
void applyAngularImpulse (float impulse, bool wake=true)
 Apply an angular impulse. More...
 
float getMass () const
 Get the total mass of the body. More...
 
float getInertia () const
 Get the rotational inertia of the body about the local origin. More...
 
Vector2f getLocalPoint (const Vector2f &worldPoint) const
 Get the local coordinate of a world coordinate. More...
 
Vector2f getWorldPoint (const Vector2f &localPoint) const
 Get the world coordinate of a local coordinate. More...
 
Vector2f getLocalRotation (const Vector2f &worldVector) const
 Get the local rotation of a world rotation. More...
 
Vector2f getWorldRotation (const Vector2f &localVector) const
 Get the world rotation of a local rotation. More...
 
Vector2f getLinearVelocityFromLocalPoint (const Vector2f &localPoint) const
 Get the world velocity of a local point. More...
 
Vector2f getLinearVelocityFromWorldPoint (const Vector2f &worldPoint) const
 Get the world linear velocity of a world point on the body. More...
 
void setLinearDamping (float damping)
 Set the linear damping of the body. More...
 
float getLinearDamping () const
 Get the linear damping of the body. More...
 
void setAngularDamping (float damping)
 Set the angular damping. More...
 
float getAngularDamping () const
 Get the angular damping of the body. More...
 
void setGravityScale (float scale)
 Set the gravity scale of the body. More...
 
float getGravityScale () const
 Get the gravity cale of the body. More...
 
void setType (Type type)
 Change the type of the body. More...
 
Type getType () const
 Get the body type. More...
 
void setFastBody (bool fast)
 Set whether or not the body is fast moving. More...
 
bool isFastBody () const
 Check if the body is a fast moving body or not. More...
 
void setSleepingAllowed (bool sleeps)
 Set whether or not this body isSleepingAllowed. More...
 
bool isSleepingAllowed () const
 Check if the body is allowed to sleep when inactive or not. More...
 
void setAwake (bool awake)
 Awake the body or put it to sleep. More...
 
bool isAwake () const
 Check if the body is awake or sleeping. More...
 
void setEnabled (bool enable)
 Enable or disable a body. More...
 
bool isEnabled () const
 Check whether or not the body is enabled. More...
 
void setFixedRotation (bool rotate)
 Set whether or not the body can rotate. More...
 
bool isFixedRotation () const
 Check if the body can rotate or not. More...
 
void setGameObject (GameObject *gameObject)
 
GameObjectgetGameObject ()
 Get the game object the body is attached to. More...
 
const GameObjectgetGameObject () const
 
PhysicsEnginegetWorld ()
 Get the physics world the body is in. More...
 
const PhysicsEnginegetWorld () const
 
PropertyContainergetUserData ()
 Get the user data added to this body. More...
 
const PropertyContainergetUserData () const
 
void forEachCollider (const Callback< Collider * > &callback) const
 Execute a function for each collider attached to the body. More...
 
std::size_t getColliderCount () const
 Get the number of colliders attached to the body. More...
 
std::unique_ptr< b2Body, Callback< b2Body * > > & getInternalBody ()
 
const std::unique_ptr< b2Body, Callback< b2Body * > > & getInternalBody () const
 
 ~RigidBody () override
 Destructor. More...
 
void setTag (const std::string &tag)
 Assign the object an alias. More...
 
const std::string & getTag () const
 Get the tag assigned to the object. More...
 
unsigned int getObjectId () const
 Get the unique id of the object. More...
 
virtual std::string getClassType () const
 Get the name of the direct parent of an object instance. More...
 
int onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to a specific property change event. More...
 
int onPropertyChange (const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to any property change event. More...
 
void suspendedEventListener (int id, bool suspend)
 Pause or resume execution of an event listener. More...
 
bool isEventListenerSuspended (int id) const
 Check if an event listener is suspended or not. More...
 
bool removeEventListener (const std::string &event, int id)
 Remove an event listener from an event. More...
 
bool removeEventListener (int id)
 Remove an event listener. More...
 
int onDestruction (const Callback<> &callback)
 Add a destruction listener. More...
 
bool isSameObjectAs (const Object &other) const
 Check if another object is the same instance as this object. More...
 

Protected Member Functions

void emitChange (const Property &property)
 Dispatch a property change event. More...
 
void emitDestruction ()
 Emit a destruction event. More...
 

Protected Attributes

EventEmitter eventEmitter_
 Event dispatcher. More...
 

Friends

class PhysicsEngine
 Needs access to constructor. More...
 

Detailed Description

A rigid body.

Bodies have position and velocity. You can apply forces, torques, and impulses to bodies. Bodies can be static, kinematic, or dynamic:

  1. A static body does not move under simulation and behaves as if it has infinite mass.
  2. A kinematic body moves under simulation according to its velocity. Kinematic bodies do not respond to forces
  3. A dynamic body is fully simulated. They can be moved manually by the user, but normally they move according to forces

Note that a rigid body without a Collider attached to it will not be able to collide with other rigid bodies. This means that it will not generate a collision when it overlaps with another rigid body. A Collider must be attached to the rigid body if you want the body to react to physics (gravity, friction, applied forces, impulses etc...) and also be able to collide with other rigid bodies. In addition a rigid body does not have a shape or size, the shape and the size of the body are derived from the body's Collider. As a result, when debug drawing is enabled, rigid bodies without colliders will not be rendered on the render window

A body is not constructed directly, use the PhysicsEngine::createBody function to construct a rigid body

Definition at line 74 of file RigidBody.h.

Member Typedef Documentation

◆ Callback

template<typename... Args>
using ime::RigidBody::Callback = std::function<void(Args...)>

Event listener.

Definition at line 79 of file RigidBody.h.

◆ Ptr

using ime::RigidBody::Ptr = std::unique_ptr<RigidBody>

Unique body pointer.

Definition at line 76 of file RigidBody.h.

Member Enumeration Documentation

◆ Type

enum class ime::RigidBody::Type
strong

The rigid body type.

Enumerator
Static 

Zero mass, zero velocity, may be moved manually.

Kinematic 

Zero mass, non-zero velocity set by user, moved by physics engine.

Dynamic 

Positive mass, non-zero velocity determined by forces, moved by physics engine.

Definition at line 84 of file RigidBody.h.

Constructor & Destructor Documentation

◆ RigidBody() [1/2]

ime::RigidBody::RigidBody ( const RigidBody )
delete

Copy constructor.

◆ RigidBody() [2/2]

ime::RigidBody::RigidBody ( RigidBody &&  )
noexcept

Move constructor.

◆ ~RigidBody()

ime::RigidBody::~RigidBody ( )
override

Destructor.

Member Function Documentation

◆ applyAngularImpulse()

void ime::RigidBody::applyAngularImpulse ( float  impulse,
bool  wake = true 
)

Apply an angular impulse.

Parameters
impulseThe impulse to be applied in kg*m*m/s
wakeTrue to wake the body, otherwise false

By default, This function will wake the body if it is sleeping

◆ applyForce()

void ime::RigidBody::applyForce ( const Vector2f force,
const Vector2f point,
bool  wake = true 
)

Apply a force at a world point.

Parameters
forceThe force to apply in Newtons (N)
pointThe point at which to apply the force
wakeTrue to wake the body if sleeping, otherwise false

If the force is not applied at the centre of mass, it will generate a torque and affect the angular velocity. This wakes up the body

◆ applyForceToCenter()

void ime::RigidBody::applyForceToCenter ( const Vector2f force,
bool  wake = true 
)

Apply a force to the centre of mass.

Parameters
forceThe force to be applied in Newton
wakeTrue to wake up the body, otherwise false

This function will force the body to wake up

◆ applyLinearImpulse()

void ime::RigidBody::applyLinearImpulse ( const Vector2f impulse,
const Vector2f point,
bool  wake = true 
)

Apply an impulse at a world point.

Parameters
impulseThe impulse to be applied in N-s or kg-m/s
pointThe world position to apply the impulse
wakeTrue to wake the body otherwise false

This function will affect the velocity and the angular velocity if the point of application is not at the centre of mass

This function will force the body to wake if it is sleeping

◆ applyLinearImpulseToCenter()

void ime::RigidBody::applyLinearImpulseToCenter ( const Vector2f impulse,
bool  wake = true 
)

Apply an impulse at the centre of mass.

Parameters
impulseThe impulse to be applied in N-s or kg-m/s
wakeTrue to wake the body otherwise false

By default, This function will wake the body if it is sleeping

◆ applyTorque()

void ime::RigidBody::applyTorque ( float  torque,
bool  wake = true 
)

Apply a torque.

Parameters
torqueThe torque to be applied about the z-axis in N-m
wakeTrue to wake the body, otherwise false

This function affects the angular velocity. This function will wake the body if sleeping

◆ attachCollider()

Collider * ime::RigidBody::attachCollider ( Collider::Ptr  collider)

Attach a collider to the body.

Parameters
colliderThe collider to be attached to the body
Returns
Pointer to the collider after it is attached to the body or a nullptr if the function is called inside a world callback

Note that a body may have more than one collider. However a collider can only be attached to one rigid body

Note
All colliders attached to the body are destroyed when the body is destroyed

By default, the body has no collider attached to it

Warning
This function is locked during callbacks

◆ copy()

RigidBody::Ptr ime::RigidBody::copy ( ) const

Create a copy of the rigid body.

Returns
The new rigid body
Note
The user data of this object will not be copied and the copy will not be attached to a game object

◆ emitChange()

void ime::Object::emitChange ( const Property property)
protectedinherited

Dispatch a property change event.

Parameters
propertyThe property that changed

This function will invoke all the event listeners of the specified property

See also
emit

◆ emitDestruction()

void ime::Object::emitDestruction ( )
protectedinherited

Emit a destruction event.

Note
This function must be the first statement in the definition of a destructor to avoid undefined behavior. In addition, note that destruction listeners are invoked once. Therefore, multiple classes in a hierarchy may call this function but the class that makes the call first will be the one that invokes the destruction listeners

◆ forEachCollider()

void ime::RigidBody::forEachCollider ( const Callback< Collider * > &  callback) const

Execute a function for each collider attached to the body.

Parameters
callbackThe function to be executed

The callback is passed a collider on invocation

◆ getAngularDamping()

float ime::RigidBody::getAngularDamping ( ) const

Get the angular damping of the body.

Returns
The angular damping of the body

◆ getAngularVelocity()

float ime::RigidBody::getAngularVelocity ( ) const

Get the angular velocity.

Returns
The new angular velocity

◆ getClassName()

std::string ime::RigidBody::getClassName ( ) const
overridevirtual

Get the name of this class.

Returns
The name of this class

Implements ime::Object.

◆ getClassType()

virtual std::string ime::Object::getClassType ( ) const
virtualinherited

Get the name of the direct parent of an object instance.

Returns
The name of the direct parent of an object instance

In contrast to getClassName() which returns the name of the concrete class, this function returns the name of the concrete class's base class. This function is implemented by all derived classes of ime::Object which also serve as base classes. For classes whose direct parent is this class, this function will return the name of this class

auto rectangle = ime::RectangleShape(); // RectangleShape is derived from Shape
std::cout << rectangle->getClassName(); // Prints "RectangleShape"
std::cout << rectangle->getClassType(); // Prints "Shape"
A 2D shape having four sides and four corners (90 degree angles)
See also
getClassName

Reimplemented in ime::audio::Audio, ime::GameObject, ime::GridMover, ime::Collider, ime::Joint, ime::Drawable, ime::Shape, and ime::SpriteImage.

◆ getColliderById()

Collider * ime::RigidBody::getColliderById ( unsigned int  id)

Get a collider by its id.

Parameters
idThe unique identifier of the collider
Returns
The collider with the given id or a nullptr if the body does not have a collider with the given id attached to it
Warning
This function is locked during callbacks

◆ getColliderCount()

std::size_t ime::RigidBody::getColliderCount ( ) const

Get the number of colliders attached to the body.

Returns
The number of colliders attached to the body

◆ getGameObject()

GameObject * ime::RigidBody::getGameObject ( )

Get the game object the body is attached to.

Returns
The game object this body is attached to or a nullptr if teh body is not attached to any game object

By default, the body is not attached to any game object

◆ getGravityScale()

float ime::RigidBody::getGravityScale ( ) const

Get the gravity cale of the body.

Returns
The gravity scale of the body

◆ getInertia()

float ime::RigidBody::getInertia ( ) const

Get the rotational inertia of the body about the local origin.

Returns
The rotational inertia in kg-m^2

◆ getLinearDamping()

float ime::RigidBody::getLinearDamping ( ) const

Get the linear damping of the body.

Returns
The linear damping of the body

◆ getLinearVelocity()

Vector2f ime::RigidBody::getLinearVelocity ( ) const

Get the linear velocity of the centre of mass.

Returns
The linear velocity of the center of mass.

◆ getLinearVelocityFromLocalPoint()

Vector2f ime::RigidBody::getLinearVelocityFromLocalPoint ( const Vector2f localPoint) const

Get the world velocity of a local point.

Parameters
localPointLocal point to get world velocity of
Returns
The world velocity of a point

◆ getLinearVelocityFromWorldPoint()

Vector2f ime::RigidBody::getLinearVelocityFromWorldPoint ( const Vector2f worldPoint) const

Get the world linear velocity of a world point on the body.

Parameters
worldPointThe world point
Returns
The world velocity of a point

◆ getLocalCenter()

Vector2f ime::RigidBody::getLocalCenter ( ) const

Get the local position of the centre of mass.

Returns
The local position of the centre of mass

◆ getLocalPoint()

Vector2f ime::RigidBody::getLocalPoint ( const Vector2f worldPoint) const

Get the local coordinate of a world coordinate.

Parameters
worldPointThe world coordinate to be converted to local
Returns
The given world coordinate relative to the body's origin

◆ getLocalRotation()

Vector2f ime::RigidBody::getLocalRotation ( const Vector2f worldVector) const

Get the local rotation of a world rotation.

Parameters
worldVectorThe world rotation to get local rotation from
Returns
worldVector in local rotation

◆ getMass()

float ime::RigidBody::getMass ( ) const

Get the total mass of the body.

Returns
The mass of the body in kilograms (Kg)

The mass of the body is derived from the colliders attached to the body. The more colliders are attached the bigger the mass of the body, likewise the less number of colliders attached, the smaller the mass

By default, the mass is 0

◆ getObjectId()

unsigned int ime::Object::getObjectId ( ) const
inherited

Get the unique id of the object.

Returns
The unique id of the object

Note that each instance of ime::Object has a unique id

See also
setTag

◆ getPosition()

Vector2f ime::RigidBody::getPosition ( ) const

Get the world position of the body's origin.

Returns
The world position of the body's origin

◆ getRotation()

float ime::RigidBody::getRotation ( ) const

Get the body's world rotation.

Returns
The current world rotation of the body

◆ getTag()

const std::string & ime::Object::getTag ( ) const
inherited

Get the tag assigned to the object.

Returns
The tag of the object
See also
setTag

◆ getType()

Type ime::RigidBody::getType ( ) const

Get the body type.

Returns
The type of this body

◆ getUserData()

PropertyContainer & ime::RigidBody::getUserData ( )

Get the user data added to this body.

Returns
The user data

The user data can be used to store additional information to the body. You can store any type of data in the user date. IME does not use this data and it is sorely available for you to use

◆ getWorld()

PhysicsEngine * ime::RigidBody::getWorld ( )

Get the physics world the body is in.

Returns
The physics world the body is simulated in

◆ getWorldCenter()

Vector2f ime::RigidBody::getWorldCenter ( ) const

Get the world position of the centre of mass.

Returns
The world position centre position

◆ getWorldPoint()

Vector2f ime::RigidBody::getWorldPoint ( const Vector2f localPoint) const

Get the world coordinate of a local coordinate.

Parameters
localPointA point on the body measured relative to the body's origin
Returns
The given point in world coordinates

◆ getWorldRotation()

Vector2f ime::RigidBody::getWorldRotation ( const Vector2f localVector) const

Get the world rotation of a local rotation.

Parameters
localVectorThe local rotation to be converted to world rotation
Returns
The given local rotation in world rotation

◆ isAwake()

bool ime::RigidBody::isAwake ( ) const

Check if the body is awake or sleeping.

Returns
True if awake, otherwise false

◆ isEnabled()

bool ime::RigidBody::isEnabled ( ) const

Check whether or not the body is enabled.

Returns
True if enabled or false if disabled

◆ isEventListenerSuspended()

bool ime::Object::isEventListenerSuspended ( int  id) const
inherited

Check if an event listener is suspended or not.

Parameters
idThe identification number of the listener to be checked
Returns
True if suspended, otherwise false

This function also returns false if the specified event listener does not exist

See also
suspendedEventListener

◆ isFastBody()

bool ime::RigidBody::isFastBody ( ) const

Check if the body is a fast moving body or not.

Returns
True if body is a fast moving body, otherwise false
See also
setFastBody

◆ isFixedRotation()

bool ime::RigidBody::isFixedRotation ( ) const

Check if the body can rotate or not.

Returns
True if the body cn rotate, otherwise false
See also
setFixedRotation

◆ isSameObjectAs()

bool ime::Object::isSameObjectAs ( const Object other) const
inherited

Check if another object is the same instance as this object.

Parameters
otherThe object to compare against this object
Returns
True if other is the same instance as this object, otherwise false

◆ isSleepingAllowed()

bool ime::RigidBody::isSleepingAllowed ( ) const

Check if the body is allowed to sleep when inactive or not.

Returns
True if the body sleeps or false if the body never sleeps
See also
setSleepingAllowed

◆ onDestruction()

int ime::Object::onDestruction ( const Callback<> &  callback)
inherited

Add a destruction listener.

Parameters
callbackFunction to be executed when the object is destroyed
Returns
The unique id of the destruction listener

The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it

Warning
It's not advised to call virtual functions in the destruction callback as some parts of the object may have already been destroyed by the time the callback is invoked. In such an event, the behavior is undefined
See also
removeEventListener

◆ onPropertyChange() [1/2]

int ime::Object::onPropertyChange ( const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to any property change event.

Parameters
callbackThe function to be executed when any property changes
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The unique id of the event listener

When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event

See also
onPropertyChange(const std::string&, const ime::Callback<ime::Property>&)

◆ onPropertyChange() [2/2]

int ime::Object::onPropertyChange ( const std::string &  property,
const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to a specific property change event.

Parameters
propertyThe name of the property to add an event listener to
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
callbackThe function to be executed when the property changes
Returns
The unique id of the event listener

A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called

Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.

// Prints the tag of the player object to the console everytime it changes
player.onPropertyChange("tag", [](const Property& property) {
cout << "New tag: " << property.getValue<std::string>() << endl;
});
...
//Sets tag = "player1" and invokes event listener(s)
player.setTag("player1");
See also
unsubscribe and onPropertyChange(const ime::Callback<ime::Property>&)

◆ operator=() [1/2]

RigidBody & ime::RigidBody::operator= ( const RigidBody )
delete

Copy assignment operator.

◆ operator=() [2/2]

RigidBody & ime::RigidBody::operator= ( RigidBody &&  )
noexcept

Move assignment operator.

◆ removeColliderWithId()

void ime::RigidBody::removeColliderWithId ( unsigned int  id)

Remove a collider with a given id from the body.

Parameters
idThe id of the collider to be removed
  • The mass of the body will be adjusted if the body is dynamic and the collider has a positive density
Note
All colliders attached to a body are destroyed when the body is destroyed
Warning
This function is locked during world callbacks

◆ removeEventListener() [1/2]

bool ime::Object::removeEventListener ( const std::string &  event,
int  id 
)
inherited

Remove an event listener from an event.

Parameters
eventThe name of the event to remove an event listener from
idThe unique id of the event listener to be removed
Returns
True if the event listener was removed or false if the event or the event listener is does not exist
// Display the tag of the object to console every time it changes
auto tagChangeId = object.onPropertyChange("tag", [](ime::Property tag) {
std::cout << name.getValue<std::string>() << std::endl;
});
// Stop displaying the tag of the object when it changes
object.removeEventListener("tag", tagChangeId);
Class that can store a value of any type.
Definition: Property.h:38

◆ removeEventListener() [2/2]

bool ime::Object::removeEventListener ( int  id)
inherited

Remove an event listener.

Parameters
idThe id of the event listener to be removed
Returns
True if the event listener was removed or false if no such handler exists

◆ setAngularDamping()

void ime::RigidBody::setAngularDamping ( float  damping)

Set the angular damping.

Parameters
dampingThe new angular damping

The angular damping is used to reduce the angular velocity. The damping parameter can be larger than 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is large. Units are 1/time

By default, the angular damping is zero

◆ setAngularVelocity()

void ime::RigidBody::setAngularVelocity ( float  degrees)

Set the angular velocity in degrees per second.

Parameters
degreesThe new angular velocity

By default, the angular velocity is 0 degrees per second

◆ setAwake()

void ime::RigidBody::setAwake ( bool  awake)

Awake the body or put it to sleep.

Parameters
awakeTrue to awake the body or false to put it to sleep

A sleeping body is not simulated. Note that if a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed.

By default, the body is awake

◆ setEnabled()

void ime::RigidBody::setEnabled ( bool  enable)

Enable or disable a body.

Parameters
enableTrue to enable or false to disable

A disabled body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all colliders will be added to the broad-phase. If you pass a flag of false, all colliders will be removed from the broad-phase and all contacts will be destroyed. Colliders and joints are otherwise unaffected. You may continue to create/destroy colliders and joints on disabled bodies. Colliders on a disabled body are implicitly disabled and will not participate in collisions, ray-casts, or queries. Joints connected to a disabled body are implicitly disabled. A disabled body is still owned by a world object and remains in the body list.

Warning
Enabling a disabled body is almost as expensive as creating the body from scratch, so use this function sparingly

By default, the body is enabled

Warning
This function is locked during callbacks

◆ setFastBody()

void ime::RigidBody::setFastBody ( bool  fast)

Set whether or not the body is fast moving.

Parameters
fastTrue to set as fast moving, otherwise false

When set to true, the body is prevented from tunnelling through other moving bodies (The body is treated like a bullet for continuous collision detection). All bodies are prevented from from tunneling through kinematic and static bodies. This option is only considered for dynamic bodies

By default, the body is NOT a fast body

Warning
Fast bodies increases processing time and hence decreases performance. Therefore, you should only set the body as a fast body if it is indeed a fast body, such as a bullet

◆ setFixedRotation()

void ime::RigidBody::setFixedRotation ( bool  rotate)

Set whether or not the body can rotate.

Parameters
rotateTrue to allow rotations or false to disallow rotations

By default, the body can rotate

◆ setGravityScale()

void ime::RigidBody::setGravityScale ( float  scale)

Set the gravity scale of the body.

Parameters
scaleThe gravity scale

By default, the gravity scale is 1.0f

◆ setLinearDamping()

void ime::RigidBody::setLinearDamping ( float  damping)

Set the linear damping of the body.

Parameters
dampingThe new linear damping

The linear damping is used to reduce the linear velocity. The damping parameter can be larger than 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is large. Units are 1/time

By default, the linear damping is 0.0f

◆ setLinearVelocity()

void ime::RigidBody::setLinearVelocity ( const Vector2f velocity)

Set the linear velocity of the body in pixels per second.

Parameters
velocityThe new linear velocity of the centre of mass

By default, the linear velocity is 0 pixels per second

◆ setPosition()

void ime::RigidBody::setPosition ( const Vector2f position)

Set the world position of the body's local origin.

Parameters
positionThe position to set

By default, the position is (0, 0)

◆ setRotation()

void ime::RigidBody::setRotation ( float  angle)

Set the body's rotation about the world origin.

Parameters
angleThe body's world rotation

By default, the rotation is 0 degrees

◆ setSleepingAllowed()

void ime::RigidBody::setSleepingAllowed ( bool  sleeps)

Set whether or not this body isSleepingAllowed.

Parameters
sleepsTrue to allow sleep or false to keep the body awake at all times

By default, the body is allowed to sleep when not in contact with another body or is not in motion

Note
Setting the body to never sleep increases CPU usage

◆ setTag()

void ime::Object::setTag ( const std::string &  tag)
inherited

Assign the object an alias.

Parameters
tagThe alias of the object

This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag

By default, the tag is an empty string

See also
getObjectId

◆ setType()

void ime::RigidBody::setType ( Type  type)

Change the type of the body.

Parameters
typeThe type of this body

This function may alter the mass and velocity.

Warning
This function is locked during callbacks

◆ suspendedEventListener()

void ime::Object::suspendedEventListener ( int  id,
bool  suspend 
)
inherited

Pause or resume execution of an event listener.

Parameters
idThe event listeners unique identification number
suspendTrue to suspend/pause or false to unsuspend/resume
See also
isEventListenerSuspended

Friends And Related Function Documentation

◆ PhysicsEngine

friend class PhysicsEngine
friend

Needs access to constructor.

Definition at line 622 of file RigidBody.h.

Member Data Documentation

◆ eventEmitter_

EventEmitter ime::Object::eventEmitter_
protectedinherited

Event dispatcher.

Definition at line 289 of file Object.h.


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