Rune Engine  Version 0.2.7-alpha
Documentation for how to make games using the Rune Engine.
physics::RigidBody Class Reference

Game object component that allows a game object to have collisions with other objects. More...

#include <rigidBody.h>

Inheritance diagram for physics::RigidBody:
Collaboration diagram for physics::RigidBody:

Public Member Functions

virtual void start ()
 Initialize the physics::RigidBody to be approximately the same size as the rune::GameObject.
 
 RigidBody (double mass=0, rune::Vec2 gravity=rune::Vec2(0, 0))
 Constructor to set up mass data of the RigidBody. More...
 
void setUpObject (int width, int height, double mass, bool rotation)
 Set up the object. Identical to the constructor but can be used to set up an object after it's been created. More...
 
void updateAABB ()
 Recalculate the AABB based on the rigid body position.
 
void setMass (float newMass)
 Set the mass of the object, more massive objects will react more slowly to collisions. More...
 
AABB getBoundingBox (void)
 Return an AABB containing the information about the rigid body bounding box. More...
 
void addAngularVelocity (double angularVel)
 Adds to the rigid body angular velocity making it spin faster or slower. More...
 
void setRotation (double angle)
 Overwrite the orientation of the rigid body to be something new. More...
 
void setPosition (rune::Vec2)
 Overwrite the position of the rigid body to be something new. More...
 
void addPosition (rune::Vec2 newPos)
 Add some vector to the current position. More...
 
rune::Vec2 getPosition (void)
 Get the current rigid body position. More...
 
void addVelocity (rune::Vec2)
 Add to the objects current velocity vector. More...
 
void updatePosition (double dT)
 Update the position of the object based on collisions and velocities. More...
 
void interpolatePosition (double alpha)
 Linearly interpolate the position of the rune::RigidBody for editing to transform of the parent object. More...
 
rune::Vec2 getGravity (void)
 Get the gravity vector of the object. More...
 
rune::Vec2 getVelocity (void)
 Get the current velocity of the rigid body. More...
 
void setVelocity (rune::Vec2)
 Set the current velocity of the rigid body. More...
 
rune::Vec2 getVertex (int)
 Return the current position of a vertex in world coordinates. More...
 
double getInvMass (void)
 Get the inverse mass of the rigid body. More...
 
double getInvIntertia (void)
 Get the inverse inertia of the rigid body. More...
 
double getRestitution (void)
 Return the restitution (bounciness) of the rigid body. More...
 
void setRestitution (double)
 Set the restitution (bounciness) of the rigid body. More...
 
double getStaticFriction (void)
 Get the coefficient of static friction. More...
 
void setStaticFriction (float friction)
 Set the coefficient of static friction.
 
double getDynamicFriction (void)
 Get the coefficient of dynamic friction. More...
 
void setDynamicFriction (float friction)
 Set the coefficient of dynamic friction.
 
double getOrientation (void)
 Get the current orientation of the rigid body. More...
 
double getWidth (void)
 Get the width of the AABB. More...
 
double getHeight (void)
 Get the height of the AABB. More...
 
rune::Vec2 getPreviousPosition (void)
 Get the position that the rigid body was in last frame. More...
 
void setPreviousPosition (rune::Vec2)
 Set the position that the rigid body was in last frame. More...
 
void clearCollisions (void)
 Clear the list of collisions that rigid body is involved with.
 
void addCollision (collision)
 Add a collision to the list of collisions the rigid body was involved in. More...
 
std::vector< collisiongetCollisions (void)
 Get the list of collisions the rigid body was involved in. More...
 
bodygetBodyStruct (void)
 Get the rigidBody struct for modification. More...
 
- Public Member Functions inherited from rune::Component
 Component ()=default
 Default constructor to set up.
 
virtual void awake ()
 A function that will be called before all other start functions but after the component has been assigned to a GameObject.
 
virtual void update ()
 A function for each component that is called every frame.
 
virtual void fixedUpdate ()
 A function for each component that is called once every physics update.
 
void setParent (GameObject *newParent)
 A function to set the pointer to the parent rune::GameObject for each component. More...
 
void setEnable (bool newEnable)
 Enable or disable the component. More...
 
bool isComponentEnabled (void)
 Gets whether or not the current component is enabled.
 
void onNotify (Signal const &signal) override
 A virtual method to be overridden by a concrete implementation of the observer class.
 

Additional Inherited Members

- Protected Attributes inherited from rune::Component
GameObjectparentObject = nullptr
 The rune::GameObject that this component is attached to. If not attached to a rune::GameObject this will equal nullptr.
 
bool isEnabled = true
 Whether or not the component is currently enabled. If not enabled, update function will not be called.
 

Detailed Description

Game object component that allows a game object to have collisions with other objects.

Author
Thomas Montano
Date
March 2 2020

Constructor & Destructor Documentation

◆ RigidBody()

physics::RigidBody::RigidBody ( double  mass = 0,
rune::Vec2  gravity = rune::Vec2(0,0) 
)

Constructor to set up mass data of the RigidBody.

Parameters
massThe mass in units that the RigidBody will have.
gravityThe gravity vector that this RigidBody will be subjected to.

Member Function Documentation

◆ addAngularVelocity()

void physics::RigidBody::addAngularVelocity ( double  angularVel)

Adds to the rigid body angular velocity making it spin faster or slower.

Parameters
angularVelAngular velocity to be added to the RigidBody.

◆ addCollision()

void physics::RigidBody::addCollision ( collision  newCollision)

Add a collision to the list of collisions the rigid body was involved in.

Parameters
newCollisionCollision manifold to be stored in the GameObject associated with the RigidBody.

◆ addPosition()

void physics::RigidBody::addPosition ( rune::Vec2  newPos)

Add some vector to the current position.

Parameters
newPosPosition vector to be added to the object's current position.

◆ addVelocity()

void physics::RigidBody::addVelocity ( rune::Vec2  velocity)

Add to the objects current velocity vector.

Parameters
velocityVelocity vector to be added to the current object velocity.

◆ getBodyStruct()

physics::body * physics::RigidBody::getBodyStruct ( void  )

Get the rigidBody struct for modification.

Returns
A pointer to the RigidBody data struct.

◆ getBoundingBox()

physics::AABB physics::RigidBody::getBoundingBox ( void  )

Return an AABB containing the information about the rigid body bounding box.

Returns
the AABB associated with the RigidBody.

◆ getCollisions()

std::vector< physics::collision > physics::RigidBody::getCollisions ( void  )

Get the list of collisions the rigid body was involved in.

Returns
The collision manifolds associated with this RigidBody.

◆ getDynamicFriction()

double physics::RigidBody::getDynamicFriction ( void  )

Get the coefficient of dynamic friction.

Returns
The coefficient of dynamic friction for the RigidBody.

◆ getGravity()

rune::Vec2 physics::RigidBody::getGravity ( void  )

Get the gravity vector of the object.

Returns
The current gravity the object is being subjected to.

◆ getHeight()

double physics::RigidBody::getHeight ( void  )

Get the height of the AABB.

Returns
The height in pixels of the RigidBody object.

◆ getInvIntertia()

double physics::RigidBody::getInvIntertia ( void  )

Get the inverse inertia of the rigid body.

Returns
1 divided by the rotational inertia of the RigidBody.

◆ getInvMass()

double physics::RigidBody::getInvMass ( void  )

Get the inverse mass of the rigid body.

Returns
Get 1 divided by the mass of the RigidBody.

◆ getOrientation()

double physics::RigidBody::getOrientation ( void  )

Get the current orientation of the rigid body.

Returns
The current angle of the RigidBody.

◆ getPosition()

rune::Vec2 physics::RigidBody::getPosition ( void  )

Get the current rigid body position.

Returns
A vector that corresponds to the RigidBody position.

◆ getPreviousPosition()

rune::Vec2 physics::RigidBody::getPreviousPosition ( void  )

Get the position that the rigid body was in last frame.

Returns
The position vector of the RigidBody from last frame.

◆ getRestitution()

double physics::RigidBody::getRestitution ( void  )

Return the restitution (bounciness) of the rigid body.

Returns
Get the restitution of the object.

◆ getStaticFriction()

double physics::RigidBody::getStaticFriction ( void  )

Get the coefficient of static friction.

Returns
The coefficient of static friction for the RigidBody.

◆ getVelocity()

rune::Vec2 physics::RigidBody::getVelocity ( void  )

Get the current velocity of the rigid body.

Returns
The velocity vector of the RigidBody.

◆ getVertex()

rune::Vec2 physics::RigidBody::getVertex ( int  i)

Return the current position of a vertex in world coordinates.

Parameters
iThe index of the RigidBody vertex starting in the top left and going counter clockwise around.
Returns
The location of the vertex in world coordinates.

◆ getWidth()

double physics::RigidBody::getWidth ( void  )

Get the width of the AABB.

Returns
The width in pixels of the RigidBody object.

◆ interpolatePosition()

void physics::RigidBody::interpolatePosition ( double  alpha)

Linearly interpolate the position of the rune::RigidBody for editing to transform of the parent object.

Parameters
alphalinear interpolation factor.

◆ setMass()

void physics::RigidBody::setMass ( float  newMass)

Set the mass of the object, more massive objects will react more slowly to collisions.

Parameters
newMassThe new mass of the object.

◆ setPosition()

void physics::RigidBody::setPosition ( rune::Vec2  newPos)

Overwrite the position of the rigid body to be something new.

Parameters
newPosSet the position of the RigidBody in world coordinates.

◆ setPreviousPosition()

void physics::RigidBody::setPreviousPosition ( rune::Vec2  newPos)

Set the position that the rigid body was in last frame.

Parameters
newPosThe position that the RigidBody was last frame.

◆ setRestitution()

void physics::RigidBody::setRestitution ( double  newRest)

Set the restitution (bounciness) of the rigid body.

Parameters
newRestOverride the restitution of the RigidBody.

◆ setRotation()

void physics::RigidBody::setRotation ( double  angle)

Overwrite the orientation of the rigid body to be something new.

Parameters
angleNew orientation for the RigidBody to be set to.

◆ setUpObject()

void physics::RigidBody::setUpObject ( int  width,
int  height,
double  mass,
bool  rotation 
)

Set up the object. Identical to the constructor but can be used to set up an object after it's been created.

Parameters
widthWidth of the rigid body in pixels, should be the same as the GameObject sprite.
heightHeight of the rigid body in pixels, should be the same as the GameObject sprite.
massMass of the RigidBody to be used for physical simulations.
rotationWhether or not the RigidBody is allowed to rotate in 2D space.

◆ setVelocity()

void physics::RigidBody::setVelocity ( rune::Vec2  newVel)

Set the current velocity of the rigid body.

Parameters
newVelVelocity vector that will override the current object velocity.

◆ updatePosition()

void physics::RigidBody::updatePosition ( double  dT)

Update the position of the object based on collisions and velocities.

Parameters
dTAmount of time in seconds that has passed since the last update. Used to calculate change in position based on velocity.

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