Jagguar Game Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
RigidbodyComponent Class Reference

#include <RigidbodyComponent.hpp>

Inheritance diagram for RigidbodyComponent:
Inheritance graph
[legend]
Collaboration diagram for RigidbodyComponent:
Collaboration graph
[legend]

Public Member Functions

 RigidbodyComponent (TransformComponent *pos, Vec2D dim, Vec2D vel, float m, bool elastic=false, bool grav=false)
 
 ~RigidbodyComponent ()
 
void ApplyForce (Vec2D force) override
 
void ApplyAcceleration (Vec2D acceleration) override
 
void ApplyVelocity () override
 
void Update (SDL_Event e, int frame, std::vector< std::string > broadcastList) override
 
void ShowComponentEditor (bool *showEditor) override
 
const char * ComponentTypeName () override
 
void SetVelocity (Vec2D vel) override
 
bool IsKinematic () override
 
bool IsElastic () override
 
bool UsesGravity () override
 
Vec2D GetVelocity () override
 
float GetMass () override
 
- Public Member Functions inherited from IPhysicsComponent
 IPhysicsComponent (TransformComponent *pos, Vec2D dim)
 
 ~IPhysicsComponent ()
 
bool IsColliding (IPhysicsComponent *other)
 
virtual void ApplyForce (Vec2D force)
 
virtual void ApplyAcceleration (Vec2D acceleration)
 
virtual void ApplyVelocity ()
 
virtual void SetVelocity (Vec2D vel)
 
virtual bool IsKinematic ()
 
virtual bool IsElastic ()
 
virtual bool UsesGravity ()
 
Vec2D GetPosition ()
 
Vec2D GetDimensions ()
 
virtual Vec2D GetVelocity ()
 
virtual float GetMass ()
 
- Public Member Functions inherited from Component
 Component ()
 
 ~Component ()
 
virtual void Update (SDL_Event e, int frame, std::vector< std::string > broadcastList)
 
virtual void Render (SDL_Renderer *ren)
 
virtual void ShowComponentEditor (bool *showEditor)
 
virtual bool HasTag (ComponentTag t)
 
virtual const char * ComponentTypeName ()
 
void ParseAndUpdateBroadcast (std::vector< std::string > broadcastList)
 

Private Attributes

Vec2D velocity
 
float mass
 
bool isElastic
 
bool usesGravity
 

Additional Inherited Members

- Protected Attributes inherited from IPhysicsComponent
TransformComponentm_position
 
Vec2D dimensions
 
std::vector< ComponentTag > tags = {ComponentTag::Physics}
 
- Protected Attributes inherited from Component
std::vector< ComponentTag > tags
 
std::vector< std::string > previousBroadcasts
 
std::vector< std::string > pendingBroadcasts
 

Detailed Description

An implementation of IPhysicsComponent to allow for physics-based collisions.

See also
PhysicsEngine

Constructor & Destructor Documentation

◆ RigidbodyComponent()

RigidbodyComponent::RigidbodyComponent ( TransformComponent pos,
Vec2D  dim,
Vec2D  vel,
float  m,
bool  elastic = false,
bool  grav = false 
)

Construct a new Rigidbody Component object.

Parameters
posthe TransformComponent of the parent GameObject
dimthe dimensions of the Rigidbody
velthe velocity of the Rigidbody
mthe mass of the Rigidbody
elasticwhether the Rigidbody uses elastic collisions. Defaults to false.
gravwhether the Rigidbody is affected by gravity. Defaults to false.

◆ ~RigidbodyComponent()

RigidbodyComponent::~RigidbodyComponent ( )

Destroy the Rigidbody Component object.

Member Function Documentation

◆ ApplyAcceleration()

void RigidbodyComponent::ApplyAcceleration ( Vec2D  acceleration)
overridevirtual

Change the velocity of the Component. Adds the acceleration value to the current velocity.

Reimplemented from IPhysicsComponent.

Here is the caller graph for this function:

◆ ApplyForce()

void RigidbodyComponent::ApplyForce ( Vec2D  force)
overridevirtual

Apply a force to the Component. Handles forces outside of collisions (such as from scripts).

Parameters
forcethe force to be applied to the IPhysicsComponent
See also
SetVelocity() to directly change the velocity
ApplyAcceleration() to modify the acceleration
ApplyVelocity() to finalize movement

Reimplemented from IPhysicsComponent.

Here is the call graph for this function:

◆ ApplyVelocity()

void RigidbodyComponent::ApplyVelocity ( )
overridevirtual

Moves the Component. The IPhysicsComponent will not move until this is called.

See also
ApplyForce() to use force to change the velocity
SetVelocity() to directly change the velocity
ApplyAcceleration() to modify the acceleration

Reimplemented from IPhysicsComponent.

Here is the call graph for this function:

◆ ComponentTypeName()

const char * RigidbodyComponent::ComponentTypeName ( )
inlineoverridevirtual

The name of the component type. Used by the GUI

See also
GameMakerGUI::CreateComponent()
Returns
the name of the component

Reimplemented from Component.

◆ GetMass()

float RigidbodyComponent::GetMass ( )
overridevirtual

Get the mass of the IPhysicsComponent.

Returns
the mass of the Component

Reimplemented from IPhysicsComponent.

Here is the caller graph for this function:

◆ GetVelocity()

Vec2D RigidbodyComponent::GetVelocity ( )
overridevirtual

Get the velocity of the IPhysicsComponent.

Returns
the velocity of the Component

Reimplemented from IPhysicsComponent.

◆ IsElastic()

bool RigidbodyComponent::IsElastic ( )
overridevirtual

Get whether the IPhysicsComponent bounces or just stops on collision.

Returns
whether the IPhysicsComponent uses elastic collisions
See also
PhysicsEngine::Update()

Reimplemented from IPhysicsComponent.

◆ IsKinematic()

bool RigidbodyComponent::IsKinematic ( )
overridevirtual
Returns
true for all RigidbodyComponents

Reimplemented from IPhysicsComponent.

◆ SetVelocity()

void RigidbodyComponent::SetVelocity ( Vec2D  vel)
overridevirtual

Set the velocity of the IPhysicsComponent.

Parameters
velthe new velocity

Reimplemented from IPhysicsComponent.

Here is the caller graph for this function:

◆ ShowComponentEditor()

void RigidbodyComponent::ShowComponentEditor ( bool *  showEditor)
overridevirtual

Using Imgui, render an editor for this component

See also
GameMakerGUI::RenderEditor()
Parameters
showEditor

Reimplemented from Component.

◆ Update()

void RigidbodyComponent::Update ( SDL_Event  e,
int  frame,
std::vector< std::string >  broadcastList 
)
overridevirtual

Move the RigidbodyComponent every frame. Updates the state of the component object. Called by the Engine every tick

Parameters
eany inputs given by the user
framewhat frame is the game currently displaying
broadcastLista list to be used to send messages between components
See also
ParseAndUpdateBroadcast()

Reimplemented from Component.

Here is the call graph for this function:

◆ UsesGravity()

bool RigidbodyComponent::UsesGravity ( )
overridevirtual

Get whether the PhysicsEngine will apply gravity forces to the IPhysicsComponent.

Returns
whether the IPhysicsComponent uses gravity

Reimplemented from IPhysicsComponent.


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