ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
ToyMaker::PhysicsState Struct Reference

Component representing the physics state of the body it's attached to at some particular point in time. More...

#include <types.hpp>

Public Types

enum  Mode : Traits { MODE_DYNAMIC =0x0 , MODE_KINEMATIC =0x1 , MODE_STATIC =0x2 }
 Defines how the object this component is attached to responds to physics updates. More...
enum  CollisionResponse : Traits { COLLISION_SEPARATE =0x4 , COLLISION_SIGNAL =0x8 }
 Defines how the object this component is attached to responds to collisions. More...
using Traits = uint8_t

Public Member Functions

void applyForceGlobal (const glm::vec3 &force, const glm::vec3 &atPosition, const ObjectBounds &bounds)
 Applies a force force at position atPosition, updating the torque and central force of an object whose state is represented by physics.
void applyForceLocal (const glm::vec3 &force, const glm::vec3 &atPosition, const ObjectBounds &bounds)
 Applies a force force at position atPosition, updating the torque and central force of an object whose state is represented by physics.
float getMass () const
 Gets the mass of this object.
void setMass (float mass)
 Sets the mass of this object.
glm::vec3 getRotationalInertia () const
 Gets the rotational inertia for this object along each axis in the object's local frame.
void setRotationalInertia (const glm::vec3 &rotationalInertia)
 Sets the rotational inertia for this object along each axis in the object's local frame.
void setCoefficientRestitution (float newCoefficient)
 Sets the coefficient of restitution for this object.
Mode getMode () const
 Returns the physics type associated with this object.
void setMode (Mode mode)
 Sets the physics type associated with this object.
bool separatesOnCollision () const
 Whether this object is configured to separate from another object it collides with.
bool signalsOnCollision () const
 Whether this object is configured to report when it makes contact with another object.
void setCollisionResponse (CollisionResponse response)
 Sets a flag related to this object's collision response behaviour.
void unsetCollisionResponse (CollisionResponse response)
 Unsets a flag related to this object's collision response behaviour.

Static Public Member Functions

static std::string getComponentTypeName ()
 Fetches the component type string associated with this class.

Public Attributes

glm::vec3 mForce { 0.f }
 The sum of all the forces acting on this object's center of mass, causing it to move through space.
glm::vec3 mTorque { 0.f }
 Proportional to sum of all forces acting perpendicular to the vector going from the point at which the forces are being applied to this object' center of mass, causing it to rotate about its axis.
glm::vec3 mVelocity { 0.f }
 The velocity of this object.
glm::vec3 mAngularVelocity { 0.f }
 The angular velocity of this object.
glm::vec3 mRotationalInertiaInverse { 1.f }
 The inverse of this object's resistance to rotational change.
float mMassInverse { 1.f }
 The inverse of this object's mass.
float mCoefficientFrictionStatic { 0.f }
 The friction coefficient of the force that prevents relative motion between the surface of two objects when they are stationary.
float mCoefficientFrictionDynamic { 0.f }
 The friction coefficient of the force that hinders motion between the surface of two objects when they are moving relative to each other.
float mCoefficientRestitution { .8f }
 The fraction of the net kinetic energy prior to a collision retained by a pair of objects after the collision has taken place.
Traits mTraits { static_cast<Traits>(COLLISION_SEPARATE) | static_cast<Traits>(MODE_DYNAMIC) }
 Defines a set of flags that determines how this object responds to physics updates.

Static Public Attributes

static const Traits MaskMode { 0x3 }
 Mask used to retrieve the section of an object's physics traits that indicate its update mode.
static const Traits MaskCollisionResponse { 0xC }
 Mask used to retrieve the section of an object's physics traits that indicate its collision response mode.

Detailed Description

Component representing the physics state of the body it's attached to at some particular point in time.

All vectors are expressed in terms of world space coordinates.

Rotational inertia alone is stored in the object's local frame.

Member Function Documentation

◆ applyForceGlobal()

void PhysicsState::applyForceGlobal ( const glm::vec3 & force,
const glm::vec3 & atPosition,
const ObjectBounds & bounds )

Applies a force force at position atPosition, updating the torque and central force of an object whose state is represented by physics.

Warning
All forces applied to an object are cleared once per simulation frame.
Parameters
forceThe force being applied to the object
atPositionThe world position at which the force is applied

◆ applyForceLocal()

void PhysicsState::applyForceLocal ( const glm::vec3 & force,
const glm::vec3 & atPosition,
const ObjectBounds & bounds )

Applies a force force at position atPosition, updating the torque and central force of an object whose state is represented by physics.

Warning
All forces applied to an object are cleared once per simulation frame.
Parameters
forceThe force being applied to the object
atPositionThe object-local position at which the force is applied
boundsThe bounds of the object to which the force is applied, used to find global frame force and position equivalents

◆ getComponentTypeName()

std::string ToyMaker::PhysicsState::getComponentTypeName ( )
inlinestatic

Fetches the component type string associated with this class.

Returns
std::string The component type string of this class

◆ separatesOnCollision()

bool ToyMaker::PhysicsState::separatesOnCollision ( ) const
inline

Whether this object is configured to separate from another object it collides with.

Can be changed through setCollisionResponse().

See also
setCollisionResponse()
CollisionResponse

◆ signalsOnCollision()

bool ToyMaker::PhysicsState::signalsOnCollision ( ) const
inline

Whether this object is configured to report when it makes contact with another object.

Can be changed through setCollisionResponse().

See also
CollisionResponse
setCollisionResponse()

Member Data Documentation

◆ mAngularVelocity

glm::vec3 ToyMaker::PhysicsState::mAngularVelocity { 0.f }

The angular velocity of this object.

Expressed as a vector in the world frame.

◆ mCoefficientRestitution

float ToyMaker::PhysicsState::mCoefficientRestitution { .8f }

The fraction of the net kinetic energy prior to a collision retained by a pair of objects after the collision has taken place.

Used to limit the separation velocity between the contact points of two objects participating in a collision.

◆ mForce

glm::vec3 ToyMaker::PhysicsState::mForce { 0.f }

The sum of all the forces acting on this object's center of mass, causing it to move through space.

Expressed as a vector in the world frame.

◆ mRotationalInertiaInverse

glm::vec3 ToyMaker::PhysicsState::mRotationalInertiaInverse { 1.f }

The inverse of this object's resistance to rotational change.

Expressed in terms of the object's local frame, and should be derived from the objects mass and shape.

◆ mTorque

glm::vec3 ToyMaker::PhysicsState::mTorque { 0.f }

Proportional to sum of all forces acting perpendicular to the vector going from the point at which the forces are being applied to this object' center of mass, causing it to rotate about its axis.

Expressed as a vector in the world frame.

◆ mVelocity

glm::vec3 ToyMaker::PhysicsState::mVelocity { 0.f }

The velocity of this object.

Expressed as a vector in the world frame.


The documentation for this struct was generated from the following files:
  • ToyMaker_Main/include/toymaker/engine/physics/types.hpp
  • ToyMaker_Main/src/physics/types.cpp