VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
PhysicsSystem.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#ifndef GLM_ENABLE_EXPERIMENTAL
10 #define GLM_ENABLE_EXPERIMENTAL 1
11#endif
13#include <glm/glm.hpp>
14#include <glm/gtc/matrix_transform.hpp>
15#include <glm/gtx/euler_angles.hpp>
16#include <glm/gtx/quaternion.hpp>
17#include <mutex>
18#include <optional>
19#include <vector>
20#include <unordered_map>
21#include <functional>
22#include <memory>
23
25#include <components/GameComponents/CharacterComponent.hpp>
26
28
29namespace vex {
30
32 struct BodyIDHasher {
33 std::size_t operator()(const JPH::BodyID& id) const {
34 return std::hash<uint32_t>{}(id.GetIndexAndSequenceNumber());
35 }
36 };
37
39 class BPLayerInterfaceImpl final : public JPH::BroadPhaseLayerInterface {
40 public:
41 // @brief Returns the number of broad phase layers.
42 unsigned int GetNumBroadPhaseLayers() const override { return 1; }
43 // @brief Returns the broad phase layer for a given object layer.
44 JPH::BroadPhaseLayer GetBroadPhaseLayer(JPH::ObjectLayer inLayer) const override { return JPH::BroadPhaseLayer(0); }
45#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
46 // @brief Returns the name of a broad phase layer for profiling purposes.
47 const char* GetBroadPhaseLayerName(JPH::BroadPhaseLayer inLayer) const override { return "Default"; }
48#endif
49 };
50
52 class ObjectVsBroadPhaseLayerFilterImpl final : public JPH::ObjectVsBroadPhaseLayerFilter {
53 public:
54 // @brief Determines if an object layer should collide with a broad phase layer.
55 bool ShouldCollide(JPH::ObjectLayer, JPH::BroadPhaseLayer) const override { return true; }
56 };
57
59 class ObjectLayerPairFilterImpl final : public JPH::ObjectLayerPairFilter {
60 public:
61 // @brief Determines if two object layers should collide.
62 bool ShouldCollide(JPH::ObjectLayer, JPH::ObjectLayer) const override { return true; }
63 };
64
66 class MyActivationListener : public JPH::BodyActivationListener {
67 public:
68 // @brief Called when a body is activated.
69 void OnBodyActivated(const JPH::BodyID& inBodyID, JPH::uint64 inBodyUserData) override {}
70 // @brief Called **change** Called when a body is deactivated.
71 void OnBodyDeactivated(const JPH::BodyID& inBodyID, JPH::uint64 inBodyUserData) override {}
72 };
73
75 enum class ShapeType {
76 BOX, ROUNDED_BOX, SPHERE, CAPSULE, CYLINDER, CONVEX_HULL, MESH
77 };
78
80 enum class BodyType {
81 STATIC, DYNAMIC, KINEMATIC, SENSOR
82 };
83
85 struct CollisionHit {
86 glm::vec3 position;
87 glm::vec3 normal;
88 float impulse;
89 };
90
92 struct RaycastHit {
93 JPH::BodyID bodyId;
94 float distance;
95 glm::vec3 position;
96 glm::vec3 normal;
97 };
98
101 ShapeType shape = ShapeType::BOX;
102 BodyType bodyType = BodyType::STATIC;
103 float mass = 1.0f;
104 float friction = 0.5f;
105 float bounce = 0.1f;
106 uint8_t objectLayer = 0;
107 JPH::BodyID bodyId = JPH::BodyID(JPH::BodyID::cInvalidBodyID);
108 float linearDamping = 0.05f;
109 float angularDamping = 0.05f;
110 bool isSensor = false;
111 bool allowSleeping = true;
112 bool debugDraw = true;
113
114 glm::vec3 boxHalfExtents = {0.5f, 0.5f, 0.5f};
115 float roundedRadius = 0.05f;
116 float sphereRadius = 0.5f;
117 float capsuleRadius = 0.5f;
118 float capsuleHeight = 1.0f;
119 float cylinderRadius = 0.5f;
120 float cylinderHeight = 1.0f;
121 std::vector<JPH::Vec3> convexPoints;
122 std::vector<glm::vec3> meshVertices;
123 std::vector<uint32_t> meshIndices;
124
125 // Collision callbacks
126 std::function<void(vex::Entity self, vex::Entity other, const CollisionHit& hit)> onCollisionEnter;
127 std::function<void(vex::Entity self, vex::Entity other, const CollisionHit& hit)> onCollisionStay;
128 std::function<void(vex::Entity self, vex::Entity other)> onCollisionExit;
129
130 #if DEBUG
131 bool updated = false;
132 #endif
133
135 PhysicsComponent() = default;
136
137 explicit PhysicsComponent(ShapeType s) : shape(s) {}
138
145 static PhysicsComponent Box(glm::vec3 halfExtents = {0.5f, 0.5f, 0.5f}, BodyType bodyType = BodyType::STATIC, float mass = 1.0f, float friction = 0.5f, float bounce = 0.1f) {
147 pc.shape = ShapeType::BOX;
148 pc.boxHalfExtents = halfExtents;
149 pc.mass = mass;
150 pc.bodyType = bodyType;
151 pc.friction = friction;
152 pc.bounce = bounce;
153 return pc;
154 }
155
163 static PhysicsComponent RoundedBox(glm::vec3 halfExtents, float radius = 0.05f, BodyType bodyType = BodyType::DYNAMIC, float mass = 1.0f, float friction = 0.5f, float bounce = 0.1f) {
165 pc.shape = ShapeType::ROUNDED_BOX;
166 pc.boxHalfExtents = halfExtents;
167 pc.roundedRadius = radius;
168 pc.mass = mass;
169 pc.bodyType = bodyType;
170 pc.friction = friction;
171 pc.bounce = bounce;
172 return pc;
173 }
174
181 static PhysicsComponent Sphere(float radius = 0.5f, BodyType bodyType = BodyType::STATIC, float mass = 1.0f, float friction = 0.5f, float bounce = 0.1f) {
183 pc.shape = ShapeType::SPHERE;
184 pc.sphereRadius = radius;
185 pc.mass = mass;
186 pc.bodyType = bodyType;
187 pc.friction = friction;
188 pc.bounce = bounce;
189 return pc;
190 }
191
199 static PhysicsComponent Capsule(float radius = 0.5f, float height = 1.0f, BodyType bodyType = BodyType::STATIC, float mass = 1.0f, float friction = 0.5f, float bounce = 0.1f) {
201 pc.shape = ShapeType::CAPSULE;
202 pc.capsuleRadius = radius;
203 pc.capsuleHeight = height;
204 pc.mass = mass;
205 pc.bodyType = bodyType;
206 pc.friction = friction;
207 pc.bounce = bounce;
208 return pc;
209 }
210
218 static PhysicsComponent Cylinder(float radius = 0.5f, float height = 1.0f, BodyType bodyType = BodyType::STATIC, float mass = 1.0f, float friction = 0.5f, float bounce = 0.1f) {
220 pc.shape = ShapeType::CYLINDER;
221 pc.cylinderRadius = radius;
222 pc.cylinderHeight = height;
223 pc.mass = mass;
224 pc.bodyType = bodyType;
225 pc.friction = friction;
226 pc.bounce = bounce;
227 return pc;
228 }
229
236 static PhysicsComponent ConvexHull(std::vector<JPH::Vec3> points, BodyType bodyType = BodyType::STATIC, float mass = 1.0f, float friction = 0.5f, float bounce = 0.1f) {
238 pc.shape = ShapeType::CONVEX_HULL;
239 pc.convexPoints = points;
240 pc.mass = mass;
241 pc.bodyType = bodyType;
242 pc.friction = friction;
243 pc.bounce = bounce;
244 return pc;
245 }
246
253 static PhysicsComponent Mesh(MeshComponent& mesh, BodyType bodyType = BodyType::STATIC, float mass = 1.0f, float friction = 0.5f, float bounce = 0.1f) {
255 pc.shape = ShapeType::MESH;
256 pc.bodyType = bodyType;
257 pc.mass = mass;
258 pc.friction = friction;
259 pc.bounce = bounce;
260 if (!mesh.meshData.submeshes.empty()) {
261 pc.meshVertices.clear();
262 pc.meshIndices.clear();
263
264 size_t vertexOffset = 0;
265
266 for (const auto& sm : mesh.meshData.submeshes) {
267 for (const auto& v : sm.vertices) {
268 pc.meshVertices.push_back(v.position);
269 }
270 for (auto idx : sm.indices) {
271 pc.meshIndices.push_back(static_cast<uint32_t>(idx + vertexOffset));
272 }
273 vertexOffset += sm.vertices.size();
274 }
275 }
276 return pc;
277 }
278
281 void addCollisionEnterBinding(std::function<void(vex::Entity, vex::Entity, const CollisionHit&)> callback) {
282 onCollisionEnter = callback;
283 }
284
287 void addCollisionStayBinding(std::function<void(vex::Entity, vex::Entity, const CollisionHit&)> callback) {
288 onCollisionStay = callback;
289 }
290
293 void addCollisionExitBinding(std::function<void(vex::Entity, vex::Entity)> callback) {
294 onCollisionExit = callback;
295 }
296 };
297
300 public:
303 PhysicsSystem(vex::Registry& registry) : m_registry(registry) {}
304
307
310 void setDebugRenderer(JPH::DebugRenderer* renderer);
311
315 void drawDebug(bool drawConstraints = true, bool drawWireframe = true);
316
319 bool init(size_t maxBodies = 1024);
320
322 void shutdown();
323
326 void update(float deltaTime);
327
329 void SyncBodies();
330
333 void SetGravityVector(const glm::vec3& gravity) {
334 m_physicsSystem->SetGravity(JPH::Vec3(gravity.x, gravity.y, gravity.z));
335 }
336
340 void SetGravityFactor(JPH::BodyID bodyId, float gravityFactor) {
341 m_physicsSystem->GetBodyInterface().SetGravityFactor(bodyId, gravityFactor);
342 }
343
347 void SetFriction(JPH::BodyID bodyId, float friction);
348
351 float GetFriction(JPH::BodyID bodyId);
352
356 void SetBounciness(JPH::BodyID bodyId, float bounciness);
357
360 float GetBounciness(JPH::BodyID bodyId);
361
365 void SetLinearVelocity(JPH::BodyID bodyId, const glm::vec3& velocity);
366
369 glm::vec3 GetLinearVelocity(JPH::BodyID bodyId);
370
374 glm::vec3 GetVelocityAtPosition(JPH::BodyID bodyId, const glm::vec3& point);
375
379 void AddLinearVelocity(JPH::BodyID bodyId, const glm::vec3& velocity);
380
384 void SetAngularVelocity(JPH::BodyID bodyId, const glm::vec3& velocity);
385
388 glm::vec3 GetAngularVelocity(JPH::BodyID bodyId);
389
393 void AddAngularVelocity(JPH::BodyID bodyId, const glm::vec3& velocity);
394
398 void AddTorque(JPH::BodyID bodyId, const glm::vec3& torque);
399
403 void AddForce(JPH::BodyID bodyId, const glm::vec3& force);
404
409 void AddForceAtPosition(JPH::BodyID bodyId, const glm::vec3& force, const glm::vec3& position);
410
414 void AddImpulse(JPH::BodyID bodyId, const glm::vec3& impulse);
415
420 void AddImpulseAtPosition(JPH::BodyID bodyId, const glm::vec3& impulse, const glm::vec3& position);
421
425 void AddAngularImpulse(JPH::BodyID bodyId, const glm::vec3& impulse);
426
430 void SetBodyActive(JPH::BodyID bodyId, bool active);
431
435 bool GetBodyActive(JPH::BodyID bodyId);
436
442 std::optional<JPH::BodyID> CreateBodyForEntity(vex::Entity e, vex::Registry& r, PhysicsComponent& pc);
443
448 std::optional<JPH::BodyID> RecreateBodyForEntity(vex::Entity e, PhysicsComponent& pc);
449
453
460 bool raycast(const glm::vec3& origin, const glm::vec3& direction, float maxDistance, RaycastHit& hit);
461
464 int GetCollisionSteps() { return collisionSteps; }
465
468 void setCollisionSteps(int steps) { collisionSteps = steps; }
469
472 void setEnableSmoothing(bool enable) { enableSmoothing = enable; }
473
477 glm::vec3 GetPhysicsPosition(JPH::BodyID bodyId);
478
482 glm::quat GetPhysicsRotation(JPH::BodyID bodyId);
483
484 // @brief Retrieves the physics component associated with a body ID.
485 // @param JPH::BodyID id - the body ID to retrieve the physics component for
486 // @return PhysicsComponent& - the physics component associated with the body ID
487 PhysicsComponent& getPhysicsComponentByBodyId(JPH::BodyID id);
488
489 // @brief Retrieves the entity associated with a body ID.
490 // @param JPH::BodyID id - the body ID to retrieve the entity for
491 // @return vex::Entity - the entity associated with the body ID
492 vex::Entity getEntityByBodyId(JPH::BodyID id);
493
494 private:
495 friend class MyContactListener;
496
497 int collisionSteps = 3;
498 bool enableSmoothing = true;
499
500 JPH::TempAllocatorImpl* m_tempAllocator = nullptr;
501 JPH::JobSystem* m_jobSystem = nullptr;
502 JPH::PhysicsSystem* m_physicsSystem = nullptr;
503 JPH::DebugRenderer* m_debugRenderer = nullptr;
504
505 vex::Registry& m_registry;
506
507 BPLayerInterfaceImpl m_bpInterface;
508 ObjectVsBroadPhaseLayerFilterImpl m_objVsBpFilter;
509 ObjectLayerPairFilterImpl m_objLayerPairFilter;
510 std::unique_ptr<MyActivationListener> m_activationListener;
511 std::unique_ptr<JPH::ContactListener> m_contactListener;
512
513 std::unordered_map<JPH::BodyID, vex::Entity, BodyIDHasher> m_bodyToEntity;
514
515 struct InterpCache {
516 glm::vec3 prevPos = {0.0f, 0.0f, 0.0f};
517 glm::quat prevRot = {1.0f, 0.0f, 0.0f, 0.0f};
518 glm::vec3 currPos = {0.0f, 0.0f, 0.0f};
519 glm::quat currRot = {1.0f, 0.0f, 0.0f, 0.0f};
520 glm::vec3 lastVisualPos = {0.0f, 0.0f, 0.0f};
521 glm::quat lastVisualRot = {1.0f, 0.0f, 0.0f, 0.0f};
522 bool desynced = false;
523 };
524 std::unordered_map<JPH::BodyID, InterpCache, BodyIDHasher> m_interpCache;
525
526 float m_fixedDt = 1.0f / 60.0f;
527 float m_accumulator = 0.0f;
528
529 // @brief Converts Euler angles to a quaternion.
530 // @param glm::vec3 eulerDeg - the Euler angles in degrees
531 // @return JPH::Quat - the resulting quaternion
532 static JPH::Quat EulerToQuat(const glm::vec3& eulerDeg);
533 // @brief Converts a quaternion to Euler angles.
534 // @param JPH::Quat q - the quaternion to convert
535 // @return glm::vec3 - the resulting Euler angles in degrees
536 static glm::vec3 QuatToEuler(const JPH::Quat& q);
537 // @brief Synchronizes a body's transform with its entity's transform.
538 // @param vex::Entity e - the entity to synchronize
539 // @param vex::Registry& r - the registry containing the entity
540 // @param const JPH::BodyID& id - the ID of the body to synchronize
541 // @param float alpha - the interpolation factor (0.0f = no interpolation, 1.0f = full interpolation)
542 void SyncBodyToTransform(vex::Entity e, vex::Registry& r, const JPH::BodyID& id, float alpha = 1.0f);
543
544 // @brief Handles physics component destruction.
545 // @param vex::Registry& reg - the registry containing the entity
546 // @param vex::Entity e - the entity to destroy
547 void onPhysicsComponentDestroy(vex::Registry& reg, vex::Entity e);
548
549 // @brief Initializes a character component.
550 // @param vex::Entity e - the entity to initialize
551 // @param CharacterComponent& cc - the character component to initialize
552 void InitializeCharacter(vex::Entity e, CharacterComponent& cc);
553
554 #include <map>
555
561 void WeldVertices(const std::vector<glm::vec3>& inVerts, const std::vector<uint32_t>& inIndices,
562 JPH::VertexList& outVerts, JPH::IndexedTriangleList& outTris);
563 };
564
565 class MyContactListener : public JPH::ContactListener {
566 public:
567 MyContactListener(PhysicsSystem& system) : m_system(system) {}
568
569 // @brief Validates if a contact should be processed.
570 JPH::ValidateResult OnContactValidate(const JPH::Body& inBody1, const JPH::Body& inBody2, JPH::RVec3Arg inBaseOffset, const JPH::CollideShapeResult& inCollisionResult) override {
571 return JPH::ValidateResult::AcceptAllContactsForThisBodyPair;
572 }
573
574 // @brief Called when a new contact is added.
575 // @param const JPH::Body& inBody1 - the first body involved in the contact
576 // @param const JPH::Body& inBody2 - the second body involved in the contact
577 // @param const JPH::ContactManifold& inManifold - the contact manifold
578 // @param JPH::ContactSettings& ioSettings - the contact settings
579 void OnContactAdded(const JPH::Body& inBody1, const JPH::Body& inBody2, const JPH::ContactManifold& inManifold, JPH::ContactSettings& ioSettings) override;
580 // @brief Called when a contact persists.
581 // @param const JPH::Body& inBody1 - the first body involved in the contact
582 // @param const JPH::Body& inBody2 - the second body involved in the contact
583 // @param const JPH::ContactManifold& inManifold - the contact manifold
584 // @param JPH::ContactSettings& ioSettings - the contact settings
585 void OnContactPersisted(const JPH::Body& inBody1, const JPH::Body& inBody2, const JPH::ContactManifold& inManifold, JPH::ContactSettings& ioSettings) override;
586 // @brief Called when a contact is removed.
587 // @param const JPH::SubShapeIDPair& inSubShapePair - the sub shape pair involved in the contact
588 void OnContactRemoved(const JPH::SubShapeIDPair& inSubShapePair) override;
589
590 private:
591 PhysicsSystem& m_system;
592 };
593
595 class DebugDrawFilter : public JPH::BodyDrawFilter {
596 public:
597 DebugDrawFilter(PhysicsSystem& system) : m_system(system) {}
598
599 virtual bool ShouldDraw(const JPH::Body& body) const override {
600 auto& pc = m_system.getPhysicsComponentByBodyId(body.GetID());
601 return pc.debugDraw;
602 }
603
604 private:
605 PhysicsSystem& m_system;
606 };
607}
Contains basic components like transform, camera, name components..
Main header for the Entity Component System (ECS) framework.
This file exist only because of coliding macros.
Implementation of JPH::BroadPhaseLayerInterface for the default layer.
Implementation of JPH::BodyActivationListener for the default layer.
Implementation of JPH::ObjectLayerPairFilter for the default layer.
Implementation of JPH::ObjectVsBroadPhaseLayerFilter for the default layer.
Class representing a physics system.
int GetCollisionSteps()
Allows for getting collision steps (collision accuracy).
void setEnableSmoothing(bool enable)
Allows for enabling/disabling smoothing.
void SetLinearVelocity(JPH::BodyID bodyId, const glm::vec3 &velocity)
Allows for updating linear velocity.
void SyncBodies()
Scans registry for PhysicsComponents without bodies and creates them.
void SetBodyActive(JPH::BodyID bodyId, bool active)
Allows for setting body active state.
void AddForceAtPosition(JPH::BodyID bodyId, const glm::vec3 &force, const glm::vec3 &position)
Applies force at the given position of the body, it is reset next physics tick.
void SetFriction(JPH::BodyID bodyId, float friction)
Allows for updating friction.
PhysicsSystem(vex::Registry &registry)
Constructor, initializes physics system.
float GetFriction(JPH::BodyID bodyId)
Allows for getting friction.
void AddLinearVelocity(JPH::BodyID bodyId, const glm::vec3 &velocity)
Allows for adding to linear velocity.
void setDebugRenderer(JPH::DebugRenderer *renderer)
Sets the debug renderer for the physics system.
bool raycast(const glm::vec3 &origin, const glm::vec3 &direction, float maxDistance, RaycastHit &hit)
Performs a raycast in the physics world.
void WeldVertices(const std::vector< glm::vec3 > &inVerts, const std::vector< uint32_t > &inIndices, JPH::VertexList &outVerts, JPH::IndexedTriangleList &outTris)
Helper to weld vertices based on position ONLY (ignoring UVs/Normals which split render meshes).
void update(float deltaTime)
Updates physics, it is technically fixed time but needs delta to track if required time already passe...
void SetGravityVector(const glm::vec3 &gravity)
Allows for updating gravity.
void AddForce(JPH::BodyID bodyId, const glm::vec3 &force)
Applies force at the mass center of the body, it is reset next physics tick.
void AddAngularImpulse(JPH::BodyID bodyId, const glm::vec3 &impulse)
Applies angular impulse at the mass center of the body, it is reset next physics tick.
void AddTorque(JPH::BodyID bodyId, const glm::vec3 &torque)
Applies torque to the body, it is reset next physics tick.
void AddAngularVelocity(JPH::BodyID bodyId, const glm::vec3 &velocity)
Allows for adding to angular velocity.
void AddImpulse(JPH::BodyID bodyId, const glm::vec3 &impulse)
Applies impulse at the mass center of the body, it is reset next physics tick.
void shutdown()
clears all physics objects
void SetAngularVelocity(JPH::BodyID bodyId, const glm::vec3 &velocity)
Allows for setting angular velocity.
glm::vec3 GetPhysicsPosition(JPH::BodyID bodyId)
Retrieves the physics position of a body.
glm::vec3 GetLinearVelocity(JPH::BodyID bodyId)
Allows for getting linear velocity.
std::optional< JPH::BodyID > CreateBodyForEntity(vex::Entity e, vex::Registry &r, PhysicsComponent &pc)
Allows to recreate physics body at runtime.
std::optional< JPH::BodyID > RecreateBodyForEntity(vex::Entity e, PhysicsComponent &pc)
Allows to recreate physics body at runtime.
bool init(size_t maxBodies=1024)
Initializes jolts physics system.
void AddImpulseAtPosition(JPH::BodyID bodyId, const glm::vec3 &impulse, const glm::vec3 &position)
Applies impulse at the given position of the body, it is reset next physics tick.
void drawDebug(bool drawConstraints=true, bool drawWireframe=true)
Draws debug information for the physics system.
void DestroyBodyForEntity(PhysicsComponent &pc)
Destroys a physics body.
void SetBounciness(JPH::BodyID bodyId, float bounciness)
Allows for updating bounciness.
glm::vec3 GetAngularVelocity(JPH::BodyID bodyId)
Allows for getting angular velocity.
void setCollisionSteps(int steps)
Allows for setting collision steps (collision accuracy).
bool GetBodyActive(JPH::BodyID bodyId)
Allows for getting body active state.
glm::vec3 GetVelocityAtPosition(JPH::BodyID bodyId, const glm::vec3 &point)
Gets the velocity of a specific point on the body (in World Space).
~PhysicsSystem()
Destructor, simply calls shutdown().
void SetGravityFactor(JPH::BodyID bodyId, float gravityFactor)
Allows for updating gravity factor per object.
glm::quat GetPhysicsRotation(JPH::BodyID bodyId)
Retrieves the physics rotation of a body.
float GetBounciness(JPH::BodyID bodyId)
Allows for getting bounciness.
Central registry for managing entities and their components in the ECS system.
Definition Registry.hpp:29
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
Definition Types.hpp:11
BodyType
Enumeration of available body types for physics components.
ShapeType
Enumeration of available shape types for physics components.
Hasher for JPH::BodyID.
Character component for player or NPC characters.
Structure representing a collision hit.
Struct containing raw meshData, mesh id, texture paths and material properties. It just template and ...
Structure representing a physics component.
void addCollisionExitBinding(std::function< void(vex::Entity, vex::Entity)> callback)
Binds a callback for collision exit events.
static PhysicsComponent Mesh(MeshComponent &mesh, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
Creates a mesh-shaped physics component.
static PhysicsComponent Cylinder(float radius=0.5f, float height=1.0f, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
Creates a cylinder-shaped physics component.
PhysicsComponent()=default
— Constructors —
static PhysicsComponent Box(glm::vec3 halfExtents={0.5f, 0.5f, 0.5f}, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
Creates a box-shaped physics component.
void addCollisionStayBinding(std::function< void(vex::Entity, vex::Entity, const CollisionHit &)> callback)
Binds a callback for collision stay events.
void addCollisionEnterBinding(std::function< void(vex::Entity, vex::Entity, const CollisionHit &)> callback)
Binds a callback for collision enter events.
static PhysicsComponent ConvexHull(std::vector< JPH::Vec3 > points, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
Creates a convex hull-shaped physics component.
static PhysicsComponent Sphere(float radius=0.5f, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
Creates a sphere-shaped physics component.
static PhysicsComponent Capsule(float radius=0.5f, float height=1.0f, BodyType bodyType=BodyType::STATIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
Creates a capsule-shaped physics component.
static PhysicsComponent RoundedBox(glm::vec3 halfExtents, float radius=0.05f, BodyType bodyType=BodyType::DYNAMIC, float mass=1.0f, float friction=0.5f, float bounce=0.1f)
Creates a rounded box.
Structure representing a raycast hit.