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:
[legend]
Collaboration diagram for RigidbodyComponent:
[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
TransformComponent * | m_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

  pos | the TransformComponent of the parent GameObject
  dim | the dimensions of the Rigidbody
  vel | the velocity of the Rigidbody
  m | the mass of the Rigidbody
  elastic | whether the Rigidbody uses elastic collisions. Defaults to false.
  grav | whether 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 | ) |
| override virtual

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 | ) |
| override virtual

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

Parameters

  force | the 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 | ( |  | ) |
| override virtual

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 | ( |  | ) |
| inline override virtual

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 | ( |  | ) |
| override virtual

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 | ( |  | ) |
| override virtual

Get the velocity of the IPhysicsComponent.

Returns
  the velocity of the Component

Reimplemented from IPhysicsComponent.

## ◆ IsElastic()

bool RigidbodyComponent::IsElastic | ( |  | ) |
| override virtual

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 | ( |  | ) |
| override virtual

Returns
  true for all RigidbodyComponents

Reimplemented from IPhysicsComponent.

## ◆ SetVelocity()

void RigidbodyComponent::SetVelocity | ( | Vec2D | vel | ) |
| override virtual

Set the velocity of the IPhysicsComponent.

Parameters

  vel | the new velocity

Reimplemented from IPhysicsComponent.

Here is the caller graph for this function:

## ◆ ShowComponentEditor()

void RigidbodyComponent::ShowComponentEditor | ( | bool * | showEditor | ) |
| override virtual

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
| ) |  |
| override virtual

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

Parameters

  e | any inputs given by the user
  frame | what frame is the game currently displaying
  broadcastList | a 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 | ( |  | ) |
| override virtual

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:

- include/RigidbodyComponent.hpp
- src/RigidbodyComponent.cpp