Aspen
2D C++ Class-Based Object Oriented Game Engine
Aspen::Physics::Rigidbody Class Reference

Rigidbody class. More...

#include <Physics.hpp>

Inheritance diagram for Aspen::Physics::Rigidbody:
Aspen::Object::Object

Public Member Functions

 Rigidbody (Object *parent=nullptr, std::string name="Rigidbody")
 Constructor. More...
 
 Rigidbody (double mass, Object *parent=nullptr, std::string name="Rigidbody")
 Constructor Derived classes should call this in their constructors' initialization list. More...
 
 ~Rigidbody ()
 Destructor.
 
void operator() ()
 Updates this object and all of its children Derived classes should call or reimplement this at some point in their operator() This won't run if the Object isn't Active.
 
double GetMass ()
 Gets the object's mass. More...
 
void SetMass (double mass)
 Sets the object's mass. More...
 
double GetVelocityStrength ()
 Gets the current velocity strength. More...
 
double GetVelocityDirection ()
 Gets the current velocity direction. More...
 
double GetVelocityX ()
 Gets the current horizontal cartesian velocity strength. More...
 
double GetVelocityY ()
 Gets the current vertical cartesian velocity strength. More...
 
void SetVelocityStrength (double strength)
 Sets the velocity strength. More...
 
void SetVelocityDirection (double direction)
 Sets the velocity direction. More...
 
void SetVelocity (double strength, double direction)
 Sets the velocity. More...
 
void SetCartesianVelocity (double x, double y)
 Sets the velocity strength and direction via cartesian coordinates. More...
 
double GetAccelerationStrength ()
 Gets the current acceleration strength. More...
 
double GetAccelerationDirection ()
 Gets the current acceleration direction. More...
 
double GetAccelerationX ()
 Gets the current horizontal cartesian acceleration strength. More...
 
double GetAccelerationY ()
 Gets the current vertical cartesian acceleration strength. More...
 
void SetAccelerationStrength (double strength)
 Sets the acceleration strength. More...
 
void SetAccelerationDirection (double direction)
 Sets the acceleration direction. More...
 
void SetAcceleration (double strength, double direction)
 Sets the acceleration. More...
 
void SetCartesianAcceleration (double x, double y)
 Sets the acceleration strength and direction via cartesian coordinates. More...
 
void ApplyForce (double force, double angle)
 Applies a force to the Rigidbody. More...
 
void ApplyCartesianForce (double x, double y)
 Applies a cartesian force to the Rigidbody. More...
 
double GetGravityScale ()
 Sets the object's gravity scale. More...
 
void SetGravityScale (double scale)
 Sets the object's gravity scale. More...
 
void PopulateDebugger ()
 Fills out the Debugger if it exists with this Object's information Derived classes should call their base class's version of this method.
 
- Public Member Functions inherited from Aspen::Object::Object
 Object (Object *parent=nullptr, std::string name="Object")
 Constructor Derived classes should call this in their constructors' initialization list. More...
 
virtual ~Object ()
 Destructor This will End and then delete all child Objects.
 
const ObjectParent () const
 Gets the parent of this Object. More...
 
ObjectParent ()
 Gets the parent of this Object. More...
 
const ObjectRoot () const
 Gets the root Object of the parent/child tree this Object is a part of. More...
 
ObjectRoot ()
 Gets the root Object of the parent/child tree this Object is a part of. More...
 
Transform::TransformGetTransform ()
 Gets the first child Transform::Transform. More...
 
const Transform::TransformGetTransform () const
 Gets the first child Transform::Transform. More...
 
Physics::ColliderGetCollider ()
 Gets the first child Physics::Collider. More...
 
const Physics::ColliderGetCollider () const
 Gets the first child Physics::Collider. More...
 
Physics::RigidbodyGetRigidbody ()
 Gets the first child Physics::Rigidbody. More...
 
const Physics::RigidbodyGetRigidbody () const
 Gets the first child Physics::Rigidbody. More...
 
void AddChild (Object *child)
 Adds child to this Object's list of children This will also set child's _parent to this This will do nothing if child is already in the list of children Useful for adding an already created Object as a child or passing in the return operator new with parameters. More...
 
template<typename T >
T * CreateChild ()
 Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later. More...
 
template<typename T >
T * CreateChild (std::string name)
 Creates a new child of type T Useful for creating an object with no constructor parameters and/or modifying it later. More...
 
void RemoveChild (Object *child)
 Removes child from this Object's list of children This will also set child's _parent to nullptr This will do nothing if child is not in the Object's list of children. More...
 
void RemoveChild (unsigned index)
 Removes the child at index from this Object's list of children This will also set the child's _parent to nullptr This will do nothing if index is out of range of the Object's list of children. More...
 
Objectoperator[] (unsigned index)
 Gets the child at index from this Object's list of children. More...
 
int operator[] (Object *child)
 Gets the index of a given child in this Object's list of children. More...
 
ObjectGetLastChild ()
 Gets the youngest child from this Object's list of children. More...
 
int ParentCount ()
 Determines the generation of this object in the parent/child tree. More...
 
template<typename T >
T * FindAncestorOfType () const
 Finds the closest ancestor Object of a type applicable to that which was requested. More...
 
template<typename T >
const T * FindChildOfType () const
 Finds the first child Object of a type applicable to that which was requested. More...
 
template<typename T >
T * FindChildOfType ()
 Finds the first child Object of a type applicable to that which was requested. More...
 
template<typename T >
const std::vector< T * > FindChildrenOfType () const
 Finds all children Objects of a type applicable to that which was requested. More...
 
template<typename T >
std::vector< T * > FindChildrenOfType ()
 Finds all children Objects of a type applicable to that which was requested. More...
 
template<typename T >
const std::vector< T * > FindDescendentsOfType () const
 Recursively finds all descendent Objects of a type applicable to that which was requested. More...
 
template<typename T >
std::vector< T * > FindDescendentsOfType ()
 Recursively finds all descendent Objects of a type applicable to that which was requested. More...
 
const bool & Valid () const
 Determines if the Object is valid. More...
 
bool Active () const
 Determines if the Object is active. More...
 
void SetActive (bool active)
 Sets active status of the object Triggers OnActivate or OnDeactivate appropriately. More...
 
void Activate ()
 Activates the object Triggers OnActivate appropriately.
 
void Deactivate ()
 Deactivates the object Triggers OnDeactivate appropriately.
 
 operator bool () const
 Converts Object to bool by calling Valid Example: ``` Object o; while (o) o(); ```.
 
virtual void End ()
 Shuts down and invalidates Object and all of its children An invalid child Object will be deleted by their parent after they update.
 
void PrintTree (Log::Log &log) const
 Uses Log::Log to print the parent/children tree of this Object. More...
 
void PrintTree () const
 Uses Log::Log to print the parent/children tree of this Object Uses Log::Debug.
 
std::string Name () const
 Gets the Object's name. More...
 
unsigned ChildrenCount () const
 Determines the number of immediate children the Object has. More...
 
std::vector< Object * > & Children ()
 Gets the list of Objects that are children of this Object. More...
 
bool HasAncestor (const Object *other) const
 Determines if the provided Object is an ancestor of this Object. More...
 
virtual void OnStart ()
 Run when the Object is created.
 
virtual void OnActivate ()
 Run when the Object is activated Run after OnStart.
 
virtual void OnUpdate ()
 Run every frame.
 
virtual void OnEarlyUpdate ()
 Run before OnUpdate.
 
virtual void OnLateUpdate ()
 Run after OnUpdate.
 
virtual void OnDeactivate ()
 Run when the Object is deactivated Run before OnEnd.
 
virtual void OnEnd ()
 Run when the Object is ended/destroyed.
 
virtual void OnCollision (Physics::Collision c)
 Run when a collision occurs. More...
 
virtual void OnMouseEnter ()
 Run when the mouse enters the Object.
 
virtual void OnMouseOver ()
 Run while the mouse is over the Object.
 
virtual void OnMouseExit ()
 Run when the mouse leaves the Object.
 
virtual void OnMouseClick ()
 Run when the mouse is clicked while over the Object.
 
virtual void OnMouseRelease ()
 Run when the mouse is released while over the Object.
 

Private Attributes

double _mass
 Mass of the object.
 
double _velocityStrength
 Strength of velocity.
 
double _velocityDirection
 Direction of velocity.
 
double _accelerationStrength
 Strength of acceleration.
 
double _accelerationDirection
 Direction of acceleration.
 
double _gravityScale
 Amount gravity affects this object.
 

Additional Inherited Members

- Protected Member Functions inherited from Aspen::Object::Object
void SetParent (Object *parent)
 Sets _parent to the given Object Used by AddChild, CreateChild, etc.
 
void TriggerOnStart ()
 Runs OnStart if the object is currently active for the first time.
 
void TriggerOnActivate ()
 Runs OnActivate if the object is currently active.
 
void TriggerOnDeactivate ()
 Runs OnDeactivate if the object is currently active (being deactivated)
 
- Protected Attributes inherited from Aspen::Object::Object
const std::string _name
 Name of object.
 
Object_parent
 Parent/owner of this Object.
 
std::vector< Object * > _children
 List of children Objects.
 
bool _valid
 Determines if the Object is valid Derived classes can set this to false in their Constructors if they couldn't be created properly.
 
bool _active
 Determines if the Object is currently updated.
 
bool _started
 Determines if the Object has been started Set to true during the first update.
 
Transform::Transform_transform
 First child Transform::Transform.
 
Physics::Collider_collider
 First child Physics::Collider.
 
Physics::Rigidbody_rigidbody
 First child Physics::Rigidbody.
 
- Static Protected Attributes inherited from Aspen::Object::Object
static int _count
 Total number of Objects in existence.
 

Detailed Description

Rigidbody class.

Constructor & Destructor Documentation

◆ Rigidbody() [1/2]

Aspen::Physics::Rigidbody::Rigidbody ( Object parent = nullptr,
std::string  name = "Rigidbody" 
)

Constructor.

Parameters
parentParent Object to be passed to Object constructor
nameObject name Set by derived classes to a string representation of their type

◆ Rigidbody() [2/2]

Aspen::Physics::Rigidbody::Rigidbody ( double  mass,
Object parent = nullptr,
std::string  name = "Rigidbody" 
)

Constructor Derived classes should call this in their constructors' initialization list.

Parameters
massMass of the object
parentParent Object to be passed to Object constructor
nameObject name Set by derived classes to a string representation of their type

Member Function Documentation

◆ ApplyCartesianForce()

void Aspen::Physics::Rigidbody::ApplyCartesianForce ( double  x,
double  y 
)

Applies a cartesian force to the Rigidbody.

Parameters
xHorizontal strength of the force
yVertical strength of the force

◆ ApplyForce()

void Aspen::Physics::Rigidbody::ApplyForce ( double  force,
double  angle 
)

Applies a force to the Rigidbody.

Parameters
forceStrength of the force
angleAngle of the force

◆ GetAccelerationDirection()

double Aspen::Physics::Rigidbody::GetAccelerationDirection ( )

Gets the current acceleration direction.

Returns
Acceleration direction

◆ GetAccelerationStrength()

double Aspen::Physics::Rigidbody::GetAccelerationStrength ( )

Gets the current acceleration strength.

Returns
Acceleration strength

◆ GetAccelerationX()

double Aspen::Physics::Rigidbody::GetAccelerationX ( )

Gets the current horizontal cartesian acceleration strength.

Returns
Horizontal cartesian acceleration strength

◆ GetAccelerationY()

double Aspen::Physics::Rigidbody::GetAccelerationY ( )

Gets the current vertical cartesian acceleration strength.

Returns
Vertical cartesian acceleration strength

◆ GetGravityScale()

double Aspen::Physics::Rigidbody::GetGravityScale ( )

Sets the object's gravity scale.

Returns
Object's gravity scale

◆ GetMass()

double Aspen::Physics::Rigidbody::GetMass ( )

Gets the object's mass.

Returns
Object's mass

◆ GetVelocityDirection()

double Aspen::Physics::Rigidbody::GetVelocityDirection ( )

Gets the current velocity direction.

Returns
Velocity direction

◆ GetVelocityStrength()

double Aspen::Physics::Rigidbody::GetVelocityStrength ( )

Gets the current velocity strength.

Returns
Velocity strength

◆ GetVelocityX()

double Aspen::Physics::Rigidbody::GetVelocityX ( )

Gets the current horizontal cartesian velocity strength.

Returns
Horizontal cartesian velocity strength

◆ GetVelocityY()

double Aspen::Physics::Rigidbody::GetVelocityY ( )

Gets the current vertical cartesian velocity strength.

Returns
Vertical cartesian velocity strength

◆ SetAcceleration()

void Aspen::Physics::Rigidbody::SetAcceleration ( double  strength,
double  direction 
)

Sets the acceleration.

Parameters
strengthNew acceleration strength
directionNew acceleration direction

◆ SetAccelerationDirection()

void Aspen::Physics::Rigidbody::SetAccelerationDirection ( double  direction)

Sets the acceleration direction.

Parameters
directionNew acceleration direction

◆ SetAccelerationStrength()

void Aspen::Physics::Rigidbody::SetAccelerationStrength ( double  strength)

Sets the acceleration strength.

Parameters
strengthNew acceleration strength

◆ SetCartesianAcceleration()

void Aspen::Physics::Rigidbody::SetCartesianAcceleration ( double  x,
double  y 
)

Sets the acceleration strength and direction via cartesian coordinates.

Parameters
xHorizontal cartesian acceleration strength
yVertical cartesian acceleration strength

◆ SetCartesianVelocity()

void Aspen::Physics::Rigidbody::SetCartesianVelocity ( double  x,
double  y 
)

Sets the velocity strength and direction via cartesian coordinates.

Parameters
xHorizontal cartesian velocity strength
yVertical cartesian velocity strength

◆ SetGravityScale()

void Aspen::Physics::Rigidbody::SetGravityScale ( double  scale)

Sets the object's gravity scale.

Parameters
massNew gravity scale

◆ SetMass()

void Aspen::Physics::Rigidbody::SetMass ( double  mass)

Sets the object's mass.

Parameters
massNew mass

◆ SetVelocity()

void Aspen::Physics::Rigidbody::SetVelocity ( double  strength,
double  direction 
)

Sets the velocity.

Parameters
strengthNew velocity strength
directionNew velocity direction

◆ SetVelocityDirection()

void Aspen::Physics::Rigidbody::SetVelocityDirection ( double  direction)

Sets the velocity direction.

Parameters
directionNew velocity direction

◆ SetVelocityStrength()

void Aspen::Physics::Rigidbody::SetVelocityStrength ( double  strength)

Sets the velocity strength.

Parameters
strengthNew velocity strength

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