1 #ifndef PHYSICS_COMPONENT_HPP 2 #define PHYSICS_COMPONENT_HPP 4 #include "Component.hpp" 7 #include <Box2D/Box2D.h> 11 enum class BodyType { DYNAMIC, STATIC, KINEMATIC };
32 std::vector<Vector2> points,
104 float32 restitution);
107 std::shared_ptr<b2BodyWrapper>
body;
b2Body * body
The Box2D body of this wrapper.
Definition: PhysicsComponent.hpp:22
const float physicsScale
The scale of the physics relative to the world size.
Definition: PhysicsComponent.hpp:113
void Update() override
Updates this component.
Definition: PhysicsComponent.cpp:69
void SetActive(bool active)
Sets the active state of the body of this physics component.
Definition: PhysicsComponent.cpp:94
void ApplyForceToCenter(Vector2 force)
Applies the given force to the center of this object.
Definition: PhysicsComponent.cpp:81
void Init() override
Initializes this component.
Definition: PhysicsComponent.cpp:64
void ApplyForce(Vector2 force, Vector2 point)
Applies the given force to the given point relative to this object.
Definition: PhysicsComponent.cpp:76
void SetLinearVelocity(Vector2 linear)
Sets the linear velocity of this object.
Definition: PhysicsComponent.cpp:90
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.
Definition: PhysicsComponent.cpp:12
Basic class representation of a vector 2 with an x and y coordinate.
Definition: Vector2.hpp:8
Class representing a component of a GameObject.
Definition: Component.hpp:12
b2BodyWrapper(b2Body *body)
Constructs a Box2D body wrapper.
Definition: PhysicsComponent.cpp:6
~b2BodyWrapper()
Destructs a Box2D body wrapper.
Definition: PhysicsComponent.cpp:8
std::shared_ptr< b2BodyWrapper > body
The Box2D body of this physics component.
Definition: PhysicsComponent.hpp:107
Vector2 GetLinearVelocity()
Gets the linear velocity of this object.
Definition: PhysicsComponent.cpp:85
PhysicsComponent(BodyType type, std::vector< Vector2 > points, float32 density, float32 friction, float32 restitution, bool managedByPhysics)
Constructs a new physics component.
Definition: PhysicsComponent.cpp:37
A wrapper class for a Box2D Body.
Definition: PhysicsComponent.hpp:14
void SetManagedByPhysics(bool managed)
Sets whether this physics component is managed by physics.
Definition: PhysicsComponent.cpp:96
A component that generates physics for a GameObject.
Definition: PhysicsComponent.hpp:26
bool managedByPhysics
Whether or not this physics component is managed by physics.
Definition: PhysicsComponent.hpp:110