Platformer
Platformer
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PhysicsComponent Class Reference

A component that generates physics for a GameObject. More...

#include <PhysicsComponent.hpp>

Inheritance diagram for PhysicsComponent:
Inheritance graph
Collaboration diagram for PhysicsComponent:
Collaboration graph

Public Member Functions

 PhysicsComponent (BodyType type, std::vector< Vector2 > points, float32 density, float32 friction, float32 restitution, bool managedByPhysics)
 Constructs a new physics component. More...
 
 PhysicsComponent (BodyType type, float32 width, float32 height, float32 density, float32 friction, float32 restitution, bool managedByPhysics)
 Constructs a new physics component. More...
 
void Init () override
 Initializes this component.
 
void Update () override
 Updates this component.
 
void ApplyForce (Vector2 force, Vector2 point)
 Applies the given force to the given point relative to this object. More...
 
void ApplyForceToCenter (Vector2 force)
 Applies the given force to the center of this object. More...
 
Vector2 GetLinearVelocity ()
 Gets the linear velocity of this object. More...
 
void SetLinearVelocity (Vector2 linear)
 Sets the linear velocity of this object. More...
 
void SetActive (bool active)
 Sets the active state of the body of this physics component. More...
 
void SetManagedByPhysics (bool managed)
 Sets whether this physics component is managed by physics. More...
 
- Public Member Functions inherited from Component
void SetParentGameObject (std::weak_ptr< GameObject > g)
 Sets the given GameObject as this component's parent. More...
 
std::shared_ptr< GameObjectGetGameObject ()
 Gets a shared ptr reference to this component's GameObject. More...
 

Private Member Functions

void SetupBodyWithShape (BodyType type, b2Shape *shape, float32 density, float32 friction, float32 restitution)
 Sets up the Box2D body of this physics component with the given characteristics. More...
 

Private Attributes

std::shared_ptr< b2BodyWrapperbody
 The Box2D body of this physics component.
 
bool managedByPhysics
 Whether or not this physics component is managed by physics.
 
const float physicsScale = 200.0
 The scale of the physics relative to the world size.
 

Additional Inherited Members

- Protected Attributes inherited from Component
std::weak_ptr< GameObjectgameObject
 This component's parent GameObject.
 

Detailed Description

A component that generates physics for a GameObject.

Constructor & Destructor Documentation

◆ PhysicsComponent() [1/2]

PhysicsComponent::PhysicsComponent ( BodyType  type,
std::vector< Vector2 points,
float32  density,
float32  friction,
float32  restitution,
bool  managedByPhysics 
)

Constructs a new physics component.

Parameters
typeThe body type of this physics component
pointsList of points to define the shape of this component
densityThe density of this physics component
frictionThe friction of this physics component
restitutionThe restitution of this physics component
managedByPhysicsWhether or not this physics component is managed by physics
Here is the call graph for this function:

◆ PhysicsComponent() [2/2]

PhysicsComponent::PhysicsComponent ( BodyType  type,
float32  width,
float32  height,
float32  density,
float32  friction,
float32  restitution,
bool  managedByPhysics 
)

Constructs a new physics component.

Parameters
typeThe body type of this physics component
widthThe width of this physics component
heightThe height of this physics component
densityThe density of this physics component
frictionThe friction of this physics component
restitutionThe restitution of this physics component
managedByPhysicsWhether or not this physics component is managed by physics
Here is the call graph for this function:

Member Function Documentation

◆ ApplyForce()

void PhysicsComponent::ApplyForce ( Vector2  force,
Vector2  point 
)

Applies the given force to the given point relative to this object.

Parameters
forceThe force to be applied.
pointThe point the force will be applied to.

◆ ApplyForceToCenter()

void PhysicsComponent::ApplyForceToCenter ( Vector2  force)

Applies the given force to the center of this object.

Parameters
forceThe force to be applied.

◆ GetLinearVelocity()

Vector2 PhysicsComponent::GetLinearVelocity ( )

Gets the linear velocity of this object.

Returns
The linear velocity of this object.

◆ SetActive()

void PhysicsComponent::SetActive ( bool  active)

Sets the active state of the body of this physics component.

Parameters
activeWhether or not the body is active

◆ SetLinearVelocity()

void PhysicsComponent::SetLinearVelocity ( Vector2  linear)

Sets the linear velocity of this object.

Parameters
linearThe linear velocity to be set

◆ SetManagedByPhysics()

void PhysicsComponent::SetManagedByPhysics ( bool  managed)

Sets whether this physics component is managed by physics.

Parameters
managedWhether or not this physics component is managed by physics

◆ SetupBodyWithShape()

void PhysicsComponent::SetupBodyWithShape ( BodyType  type,
b2Shape *  shape,
float32  density,
float32  friction,
float32  restitution 
)
private

Sets up the Box2D body of this physics component with the given characteristics.

Parameters
typeThe body type of the Box2D body.
shapeThe shape of the Box2D body.
densityThe density of the Box2D body.
frictionThe friction of the Box2D body.
restitutionThe restitution of the Box2D body.
Here is the caller graph for this function:

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