3#include <entt/entt.hpp>
10constexpr float pi = 3.14159265;
12constexpr float inf = 2e5;
55 AABB(
const glm::vec2& lb,
const glm::vec2& ub);
137 void move(
const glm::vec2& direction);
229using ShapeData = std::variant<PolygonGeometry, CircleGeometry>;
231namespace ColliderLayers {
232constexpr uint32_t
None = 0x0000;
238constexpr uint32_t
All = 0xFFFF;
254 template <
typename Geometry>
267 *
getCircle() = std::forward<Geometry>(geom);
356 float penetration,
bool isTriggerA,
bool isTriggerB);
Central event dispatcher connecting isolated engine systems.
Definition EventBus.hpp:90
EventBus * eventBus
pointer to the system event bus
Definition types.hpp:374
entt::registry * registry
pointer to the registry for fetching entities
Definition types.hpp:373
bool collideCircleVsCircle(entt::entity e1, const TransformComponent &tc1, const CircleGeometry &geometry1, entt::entity e2, const TransformComponent &tc2, const CircleGeometry &geometry2)
bool collidePolygonVsPolygon(entt::entity e1, const TransformComponent &tc1, const PolygonGeometry &geometry1, entt::entity e2, const TransformComponent &tc2, const PolygonGeometry &geometry2)
void setGravity(const glm::vec2 &g)
sets the global gravity vector for the physics world
void update(float dt)
updates the physics simulation for the current frame
void setRegistry(entt::registry *registry)
updates the pointer to the entt registry
glm::vec2 gravity
global gravity vector applied to dynamic bodies
Definition types.hpp:372
void integrateForcesAndVelocities(float dt)
bool collideCircleVsPolygon(entt::entity e1, const TransformComponent &tc1, const CircleGeometry &geometry1, entt::entity e2, const TransformComponent &tc2, const PolygonGeometry &geometry2, bool flipNormal)
glm::vec2 getGravity() const
gets the current global gravity vector
PhysicsSystem(entt::registry ®istry)
constructor for PhysicsSystem
void setEventBus(EventBus *eventBus)
sets the event bus for dispatching physics-related events (e.g., collisions)
void processImpulseAndPushback(entt::entity eA, entt::entity eB, const glm::vec2 &normal, float penetration, bool isTriggerA, bool isTriggerB)
constexpr uint32_t Enemy
Definition types.hpp:235
constexpr uint32_t Environment
Definition types.hpp:237
constexpr uint32_t Player
Definition types.hpp:233
constexpr uint32_t All
Definition types.hpp:238
constexpr uint32_t EnemyProjectile
Definition types.hpp:236
constexpr uint32_t PlayerProjectile
Definition types.hpp:234
constexpr uint32_t None
Definition types.hpp:232
constexpr bool cd_defaultTriggerStatus
Definition types.hpp:27
std::variant< PolygonGeometry, CircleGeometry > ShapeData
Definition types.hpp:229
constexpr float pi
Definition types.hpp:10
constexpr float rb_defaultInvMass
Definition types.hpp:21
constexpr glm::vec2 cd_defaultLocalOffset
Definition types.hpp:26
constexpr float inf
Definition types.hpp:12
constexpr float rb_defaultGravityScale
Definition types.hpp:23
BodyShape
Definition types.hpp:36
@ Circle
perfect geometric circle, has radius
@ Capsule
capsule form, is constructed of two circles with same radius and rectangle
@ Segment
simple segment, has length
@ Polygon
convex polygon, has an array of points
BodyType
Definition types.hpp:29
@ Kinematic
zero mass, velocity is set by user, is moved by System
@ Static
zero mass, zero velocity, can be manually moved
constexpr float rb_defaultRestitution
Definition types.hpp:19
bool checkCollision(const AABB &aabb1, const AABB &aabb2)
checks the collision between two AABB-objects
constexpr float epsilon
Definition types.hpp:15
constexpr float pi2
Definition types.hpp:11
constexpr float rb_defaultFriction
Definition types.hpp:20
constexpr float rb_defaultDamping
Definition types.hpp:18
constexpr float rb_defaultInvInertia
Definition types.hpp:22
AABB(const glm::vec2 &lb, const glm::vec2 &ub)
constructor for AABB-object
bool collidesWith(const AABB &other) const
checks the collision between two AABB-objects
glm::vec2 upperBound
point with the biggest coords
Definition types.hpp:46
glm::vec2 lowerBound
point with the smallest coords
Definition types.hpp:45
float radius
Definition types.hpp:217
float rectangleLen
Definition types.hpp:218
float radius
Definition types.hpp:213
bool isTrigger
flag that shows whether the object is trigger zone
Definition types.hpp:245
PolygonGeometry * getPolygon()
getter for accessing the PolygonGeometry data
ColliderComponent(const BodyShape &st)
ShapeData shapeData
shape data: vertices, radius, borders etc
Definition types.hpp:243
AABB getAABB(const TransformComponent &tc) const
getter for accessing the AABB object
const PolygonGeometry * getPolygon() const
getter for accessing the PolygonGeometry data
glm::vec2 localOffset
local offset of the center of the object
Definition types.hpp:244
uint32_t categoryBits
Definition types.hpp:246
const CircleGeometry * getCircle() const
getter for accessing the CircleGeometry data
uint32_t maskBits
Definition types.hpp:248
BodyShape shapeType
shape of the object: polygon, circle, segment etc
Definition types.hpp:242
ColliderComponent(Geometry &&geom, const glm::vec2 &offset=cd_defaultLocalOffset, bool trigger=cd_defaultTriggerStatus, uint32_t categoryBits=ColliderLayers::Player, uint32_t maskBits=ColliderLayers::All &~ColliderLayers::PlayerProjectile)
Definition types.hpp:255
CircleGeometry * getCircle()
getter for accessing the CircleGeometry data
std::vector< glm::vec2 > vertices
Definition types.hpp:209
BodyType bodyType
bodyType: Static, Kinematic or Dynamic
Definition types.hpp:155
float angularVelocity
angular velocity, in radians clockwise
Definition types.hpp:161
glm::vec2 force
force: two-dimensional vector
Definition types.hpp:158
float friction
friction of the object, 0.2 by default
Definition types.hpp:173
float restitution
restitution of the object, 0.5 by default
Definition types.hpp:172
float invMass
inverted mass coefficient, used for calculating linear acceleration
Definition types.hpp:164
float gravityScale
gravity scale, 1 by default
Definition types.hpp:159
float torque
torque, in radians clockwise
Definition types.hpp:162
glm::vec2 linearVelocity
velocity along some axis
Definition types.hpp:157
RigidBodyComponent()=default
default RigidBodyComponent constructor
RigidBodyComponent(phys2d::BodyType bt)
RigidBodyComponent c-tor that uses only BodyType parameter, other fields are set by default.
float angularDamping
angular damping of the object, from 0 to 1
Definition types.hpp:170
float linearDamping
linear damping of the object, from 0 to 1
Definition types.hpp:169
float invInertia
Definition types.hpp:166
RigidBodyComponent(BodyType bt, const glm::vec2 &linearVelocity, const glm::vec2 &force, float gravityScale, float angularVelocity, float torque, float mass, float inertia, float linearDamping, float angularDamping, float restitution, float friction)
RigidBody c-tor, requires all fields to be customly set.
std::vector< glm::vec2 > points
Definition types.hpp:226
glm::vec2 borders[2]
Definition types.hpp:222