Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
PhysicsSystem.hpp
Go to the documentation of this file.
1#pragma once
2#include "ecs/System.hpp"
3#include "ecs/Registry.hpp"
9#include <glm/glm.hpp>
10#include <glm/gtc/quaternion.hpp>
11#include <glm/gtx/quaternion.hpp>
12#include <algorithm>
13#include <vector>
14#include <cmath>
15#include <limits>
16#include <iostream>
17
18namespace Engine {
19
21 bool collided = false;
22 glm::vec3 normal{0.0f}; // Points from A to B
23 float penetration = 0.0f;
24 glm::vec3 contactPoints[8]{};
26 int contactCount = 0;
27 };
28
29 struct Ray {
30 glm::vec3 origin;
31 glm::vec3 direction; // Normalized
32 };
33
34 struct RaycastHit {
35 bool hit = false;
37 float distance = std::numeric_limits<float>::max();
38 glm::vec3 position{0.0f};
39 glm::vec3 normal{0.0f};
40 };
41
46 class PhysicsSystem : public System {
47 public:
50
51 void applyAngularDisplacement(Transform& transform, const glm::vec3& deltaTheta) {
52 if (glm::length(deltaTheta) < 1e-6f) return;
53
54 // 1. Get current native quaternion directly from transform
55 glm::quat qCurrent = transform.rotation.getQuat();
56
57 // 2. Compute incremental rotation quaternion in world space (deltaTheta is in world coordinates)
58 float angle = glm::length(deltaTheta);
59 glm::quat qDelta = glm::angleAxis(angle, glm::normalize(deltaTheta));
60
61 // 3. Pre-multiply since deltaTheta is in world coordinates and assign directly
62 transform.rotation = glm::normalize(qDelta * qCurrent);
63 }
64
65 void update(float dt) override {
66 if (!editorMode.isPlaying) return;
67 if (dt <= 0.0f) return;
68 dt = std::min(dt, 1.0f / 30.0f);
69
70 glm::vec3 gravityVector{0.0f, -9.81f, 0.0f};
71
72 // 1. Integration Pass (Gravity and Force accumulation)
73 for (auto [entity, transform, rb] : registry.view<Transform, RigidBodyComponent>()) {
74 if (rb.type == RigidBodyType::Static) continue;
75
76 rb.hadContactThisFrame = false;
77 rb.unstableContactThisFrame = false;
78
79 // --- Sleeping body handling ---
80 if (rb.sleeping) {
81 bool externalVel = glm::length(rb.velocity) > 0.08f;
82 bool externalAngVel= glm::length(rb.angularVelocity) > 0.15f;
83 bool externalForce = glm::length(rb.force) > 0.01f ||
84 glm::length(rb.torque) > 0.01f;
85 if (externalVel || externalAngVel || externalForce) {
86 rb.sleeping = false;
87 rb.sleepTimer = 0.0f;
88 } else {
89 rb.force = glm::vec3(0.0f);
90 rb.torque = glm::vec3(0.0f);
91 continue;
92 }
93 }
94
95 float massVal = rb.mass;
96 if (massVal < 1e-4f || std::isnan(massVal) || std::isinf(massVal)) {
97 rb.mass = 1.0f;
98 massVal = 1.0f;
99 }
100
101 glm::vec3 gravityForce = gravityVector * rb.gravityScale * massVal;
102 glm::vec3 totalForce = rb.force + gravityForce;
103
104 if (rb.freezePositionX) { totalForce.x = 0.0f; rb.velocity.x = 0.0f; }
105 if (rb.freezePositionY) { totalForce.y = 0.0f; rb.velocity.y = 0.0f; }
106 if (rb.freezePositionZ) { totalForce.z = 0.0f; rb.velocity.z = 0.0f; }
107
108 glm::vec3 accel = totalForce / massVal;
109 if (std::isnan(accel.x) || std::isinf(accel.x)) accel = glm::vec3(0.0f);
110
111 rb.velocity += accel * dt;
112 rb.velocity *= std::exp(-rb.linearDrag * dt);
113
114 if (rb.freezePositionX) rb.velocity.x = 0.0f;
115 if (rb.freezePositionY) rb.velocity.y = 0.0f;
116 if (rb.freezePositionZ) rb.velocity.z = 0.0f;
117
118 if (std::isnan(rb.velocity.x) || std::isinf(rb.velocity.x)) rb.velocity = glm::vec3(0.0f);
119
120 transform.position += rb.velocity * dt;
121
122 if (std::isnan(transform.position.x) || std::isinf(transform.position.x) ||
123 std::isnan(transform.position.y) || std::isinf(transform.position.y) ||
124 std::isnan(transform.position.z) || std::isinf(transform.position.z)) {
125 transform.position = glm::vec3(0.0f);
126 rb.velocity = glm::vec3(0.0f);
127 }
128
129 if (std::isnan(rb.angularVelocity.x) || std::isinf(rb.angularVelocity.x)) {
130 rb.angularVelocity = glm::vec3(0.0f);
131 }
132
133 if (rb.freezeRotationX) { rb.torque.x = 0.0f; rb.angularVelocity.x = 0.0f; }
134 if (rb.freezeRotationY) { rb.torque.y = 0.0f; rb.angularVelocity.y = 0.0f; }
135 if (rb.freezeRotationZ) { rb.torque.z = 0.0f; rb.angularVelocity.z = 0.0f; }
136
137 float inertiaScale = 0.5f * massVal;
138 glm::vec3 angularAccel = rb.torque / (inertiaScale > 1e-4f ? inertiaScale : 1.0f);
139 rb.angularVelocity += angularAccel * dt;
140
141 rb.angularVelocity *= std::exp(-rb.angularDrag * dt);
142
143 if (rb.freezeRotationX) rb.angularVelocity.x = 0.0f;
144 if (rb.freezeRotationY) rb.angularVelocity.y = 0.0f;
145 if (rb.freezeRotationZ) rb.angularVelocity.z = 0.0f;
146
147 applyAngularDisplacement(transform, rb.angularVelocity * dt);
148
149 rb.force = glm::vec3(0.0f);
150 rb.torque = glm::vec3(0.0f);
151 }
152
153 // 2. Collision Detection & Resolution Pass
154 struct ColliderEntry {
155 Entity entity;
156 Transform* transform;
157 ColliderComponent* collider;
158 };
159
160 std::vector<ColliderEntry> colliders;
161 for (auto [entity, transform, collider] : registry.view<Transform, ColliderComponent>()) {
162 colliders.push_back({entity, &transform, &collider});
163 }
164
165 const int passes = 6;
166 const float solverDt = dt / static_cast<float>(passes);
167 for (int pass = 0; pass < passes; ++pass) {
168 for (size_t i = 0; i < colliders.size(); ++i) {
169 for (size_t j = i + 1; j < colliders.size(); ++j) {
170 auto& entryA = colliders[i];
171 auto& entryB = colliders[j];
172
174 entryA.entity, *entryA.collider,
175 entryB.entity, *entryB.collider
176 );
177
178 if (colInfo.collided) {
180 entryA.entity, *entryA.transform, *entryA.collider,
181 entryB.entity, *entryB.transform, *entryB.collider,
182 colInfo,
183 solverDt
184 );
185 }
186 }
187 }
188 }
189
190 // 3. Post-collision Sleep / Velocity-Floor Pass
191 {
192 const float sleepLinThresh = 0.08f; // m/s
193 const float sleepAngThresh = 0.15f; // rad/s
194
195 for (auto [entity, transform, rb] : registry.view<Transform, RigidBodyComponent>()) {
196 if (rb.type == RigidBodyType::Static) continue;
197 if (rb.sleeping) continue;
198
199 float linSpeed = glm::length(rb.velocity);
200 float angSpeed = glm::length(rb.angularVelocity);
201
202 if (linSpeed < sleepLinThresh && angSpeed < sleepAngThresh) {
203 if (rb.hadContactThisFrame && !rb.unstableContactThisFrame) {
204 rb.sleepTimer += dt;
205 if (rb.sleepTimer >= 0.5f) {
206 rb.velocity = glm::vec3(0.0f);
207 rb.angularVelocity = glm::vec3(0.0f);
208 rb.sleeping = true;
209 rb.sleepTimer = 0.0f;
210 }
211 } else {
212 rb.sleepTimer = 0.0f;
213 }
214 } else {
215 rb.sleeping = false;
216 rb.sleepTimer = 0.0f;
217 }
218 }
219 }
220 }
221
222 RaycastHit raycast(const Ray& ray) {
223 RaycastHit closestHit;
224 closestHit.distance = std::numeric_limits<float>::max();
225
226 for (auto [entity, transform, collider] : registry.view<Transform, ColliderComponent>()) {
227 glm::mat4 worldM = getEntityWorldMatrix(entity);
228 glm::vec3 colPos = glm::vec3(worldM * glm::vec4(collider.offset, 1.0f));
229 RaycastHit hit;
230
231 if (collider.shape == ColliderShape::Sphere) {
232 float scaleX = glm::length(glm::vec3(worldM[0]));
233 float scaleY = glm::length(glm::vec3(worldM[1]));
234 float scaleZ = glm::length(glm::vec3(worldM[2]));
235 float worldRadius = collider.radius * std::max({scaleX, scaleY, scaleZ});
236
237 glm::vec3 oc = ray.origin - colPos;
238 float b = glm::dot(oc, ray.direction);
239 float c = glm::dot(oc, oc) - worldRadius * worldRadius;
240
241 if (c > 0.0f && b > 0.0f) continue;
242 float discriminant = b * b - c;
243
244 if (discriminant >= 0.0f) {
245 float t = -b - std::sqrt(discriminant);
246 if (t < 0.0f) t = -b + std::sqrt(discriminant);
247 if (t >= 0.0f) {
248 hit.hit = true;
249 hit.distance = t;
250 hit.position = ray.origin + ray.direction * t;
251 hit.normal = glm::normalize(hit.position - colPos);
252 }
253 }
254 } else if (collider.shape == ColliderShape::AABB) {
255 glm::vec3 aabbMin = colPos - collider.extents;
256 glm::vec3 aabbMax = colPos + collider.extents;
257
258 float tmin = 0.0f, tmax = std::numeric_limits<float>::max();
259 bool intersect = true;
260
261 for (int i = 0; i < 3; ++i) {
262 if (std::abs(ray.direction[i]) < 1e-6f) {
263 if (ray.origin[i] < aabbMin[i] || ray.origin[i] > aabbMax[i]) {
264 intersect = false;
265 break;
266 }
267 } else {
268 float invD = 1.0f / ray.direction[i];
269 float t1 = (aabbMin[i] - ray.origin[i]) * invD;
270 float t2 = (aabbMax[i] - ray.origin[i]) * invD;
271 if (t1 > t2) std::swap(t1, t2);
272 tmin = std::max(tmin, t1);
273 tmax = std::min(tmax, t2);
274 if (tmin > tmax) {
275 intersect = false;
276 break;
277 }
278 }
279 }
280
281 if (intersect && tmax >= 0.0f) {
282 hit.hit = true;
283 hit.distance = tmin;
284 hit.position = ray.origin + ray.direction * tmin;
285
286 glm::vec3 hitLocal = hit.position - colPos;
287 glm::vec3 normal(0.0f);
288 float minDist = std::numeric_limits<float>::max();
289 for (int i = 0; i < 3; ++i) {
290 float distToMax = std::abs(collider.extents[i] - hitLocal[i]);
291 if (distToMax < minDist) {
292 minDist = distToMax;
293 normal = glm::vec3(0.0f);
294 normal[i] = 1.0f;
295 }
296 float distToMin = std::abs(-collider.extents[i] - hitLocal[i]);
297 if (distToMin < minDist) {
298 minDist = distToMin;
299 normal = glm::vec3(0.0f);
300 normal[i] = -1.0f;
301 }
302 }
303 hit.normal = normal;
304 }
305 } else if (collider.shape == ColliderShape::OBB) {
306 glm::mat4 invM = glm::inverse(worldM);
307 glm::vec3 localOrigin = glm::vec3(invM * glm::vec4(ray.origin, 1.0f));
308 glm::vec3 localDir = glm::normalize(glm::vec3(invM * glm::vec4(ray.direction, 0.0f)));
309
310 glm::vec3 boxMin = collider.offset - collider.extents;
311 glm::vec3 boxMax = collider.offset + collider.extents;
312
313 float tmin = 0.0f, tmax = std::numeric_limits<float>::max();
314 bool intersect = true;
315
316 for (int i = 0; i < 3; ++i) {
317 if (std::abs(localDir[i]) < 1e-6f) {
318 if (localOrigin[i] < boxMin[i] || localOrigin[i] > boxMax[i]) {
319 intersect = false;
320 break;
321 }
322 } else {
323 float invD = 1.0f / localDir[i];
324 float t1 = (boxMin[i] - localOrigin[i]) * invD;
325 float t2 = (boxMax[i] - localOrigin[i]) * invD;
326 if (t1 > t2) std::swap(t1, t2);
327 tmin = std::max(tmin, t1);
328 tmax = std::min(tmax, t2);
329 if (tmin > tmax) {
330 intersect = false;
331 break;
332 }
333 }
334 }
335
336 if (intersect && tmax >= 0.0f) {
337 glm::vec3 localHitPos = localOrigin + localDir * tmin;
338 glm::vec3 worldHitPos = glm::vec3(worldM * glm::vec4(localHitPos, 1.0f));
339
340 hit.hit = true;
341 hit.distance = glm::distance(ray.origin, worldHitPos);
342 hit.position = worldHitPos;
343
344 glm::vec3 hitLocal = localHitPos - collider.offset;
345 glm::vec3 localNormal(0.0f);
346 float minDist = std::numeric_limits<float>::max();
347 for (int i = 0; i < 3; ++i) {
348 float distToMax = std::abs(collider.extents[i] - hitLocal[i]);
349 if (distToMax < minDist) {
350 minDist = distToMax;
351 localNormal = glm::vec3(0.0f);
352 localNormal[i] = 1.0f;
353 }
354 float distToMin = std::abs(-collider.extents[i] - hitLocal[i]);
355 if (distToMin < minDist) {
356 minDist = distToMin;
357 localNormal = glm::vec3(0.0f);
358 localNormal[i] = -1.0f;
359 }
360 }
361 hit.normal = glm::normalize(glm::vec3(worldM * glm::vec4(localNormal, 0.0f)));
362 }
363 }
364
365 if (hit.hit && hit.distance < closestHit.distance) {
366 closestHit = hit;
367 closestHit.entity = entity;
368 }
369 }
370
371 return closestHit;
372 }
373
374 private:
375 struct OBB {
376 glm::vec3 center{0.0f};
377 glm::vec3 axes[3]{glm::vec3(1,0,0), glm::vec3(0,1,0), glm::vec3(0,0,1)};
378 glm::vec3 extents{0.5f};
379 };
380
381 glm::mat4 getEntityWorldMatrix(Entity entity, int depth = 0) {
382 if (depth > 100) return glm::mat4(1.0f);
383 glm::mat4 m = glm::mat4(1.0f);
384 if (auto* t = registry.get<Transform>(entity)) {
385 m = t->matrix();
386 }
387 if (auto* h = registry.get<HierarchyComponent>(entity)) {
388 if (h->parent.getId() != Entity::INVALID_ENTITY && registry.isValid(h->parent)) {
389 m = getEntityWorldMatrix(h->parent, depth + 1) * m;
390 }
391 }
392 return m;
393 }
394
395 OBB getOBB(Entity entity, const ColliderComponent& col) {
396 glm::mat4 worldM = getEntityWorldMatrix(entity);
397
398 OBB obb;
399 obb.center = glm::vec3(worldM * glm::vec4(col.offset, 1.0f));
400
401 glm::vec3 baseExtents = col.extents;
402 if (col.shape == ColliderShape::Capsule) {
403 baseExtents = glm::vec3(col.radius, col.height * 0.5f, col.radius);
404 }
405
406 for (int i = 0; i < 3; ++i) {
407 glm::vec3 colAxis = glm::vec3(worldM[i]);
408 float axisLen = glm::length(colAxis);
409 obb.axes[i] = (axisLen > 1e-4f) ? (colAxis / axisLen) : glm::vec3(i == 0, i == 1, i == 2);
410 obb.extents[i] = baseExtents[i] * (axisLen > 1e-4f ? axisLen : 1.0f);
411 }
412 return obb;
413 }
414
415 OBB getOBBFromAABB(const ColliderComponent& col, const glm::vec3& pos) {
416 OBB obb;
417 obb.center = pos;
418 obb.axes[0] = glm::vec3(1.0f, 0.0f, 0.0f);
419 obb.axes[1] = glm::vec3(0.0f, 1.0f, 0.0f);
420 obb.axes[2] = glm::vec3(0.0f, 0.0f, 1.0f);
421
422 if (col.shape == ColliderShape::Capsule) {
423 obb.extents = glm::vec3(col.radius, col.height * 0.5f, col.radius);
424 } else {
425 obb.extents = col.extents;
426 }
427 return obb;
428 }
429
430 CollisionInfo checkSphereAABB(const ColliderComponent& sphere, const glm::vec3& sPos,
431 const ColliderComponent& aabb, const glm::vec3& aPos,
432 bool flipNormal) {
433 CollisionInfo info;
434 glm::vec3 closestPoint = glm::clamp(sPos, aPos - aabb.extents, aPos + aabb.extents);
435 float dist = glm::distance(sPos, closestPoint);
436
437 if (dist < sphere.radius) {
438 info.collided = true;
439 info.penetration = sphere.radius - dist;
440
441 glm::vec3 dir = sPos - closestPoint;
442 float dirLen = glm::length(dir);
443 if (dirLen > 1e-4f) {
444 info.normal = glm::normalize(dir);
445 } else {
446 glm::vec3 offset = sPos - aPos;
447 float minOverlap = std::numeric_limits<float>::max();
448 glm::vec3 pushNormal(0.0f, 1.0f, 0.0f);
449
450 for (int i = 0; i < 3; ++i) {
451 float overlap = aabb.extents[i] - std::abs(offset[i]);
452 if (overlap < minOverlap) {
453 minOverlap = overlap;
454 pushNormal = glm::vec3(0.0f);
455 pushNormal[i] = (offset[i] > 0.0f) ? 1.0f : -1.0f;
456 }
457 }
458 info.penetration = sphere.radius + minOverlap;
459 info.normal = pushNormal;
460 }
461
462 if (flipNormal) {
463 info.normal = -info.normal;
464 }
465 info.contactPoints[0] = closestPoint;
466 info.contactPenetrations[0] = info.penetration;
467 info.contactCount = 1;
468 }
469 return info;
470 }
471
472 CollisionInfo checkOBBSphere(const OBB& obb, const glm::vec3& sphereCenter, float sphereRadius, bool flipNormal) {
473 CollisionInfo info;
474
475 glm::vec3 relCenter = sphereCenter - obb.center;
476 glm::vec3 localSpherePos(
477 glm::dot(relCenter, obb.axes[0]),
478 glm::dot(relCenter, obb.axes[1]),
479 glm::dot(relCenter, obb.axes[2])
480 );
481
482 glm::vec3 localClosestPoint = glm::clamp(localSpherePos, -obb.extents, obb.extents);
483
484 glm::vec3 worldClosestPoint = obb.center +
485 localClosestPoint.x * obb.axes[0] +
486 localClosestPoint.y * obb.axes[1] +
487 localClosestPoint.z * obb.axes[2];
488
489 float dist = glm::distance(sphereCenter, worldClosestPoint);
490
491 if (dist < sphereRadius) {
492 info.collided = true;
493 info.penetration = sphereRadius - dist;
494
495 glm::vec3 dir = sphereCenter - worldClosestPoint;
496 float dirLen = glm::length(dir);
497 if (dirLen > 1e-4f) {
498 info.normal = dir / dirLen;
499 } else {
500 float minOverlap = std::numeric_limits<float>::max();
501 glm::vec3 localPushNormal(0.0f, 1.0f, 0.0f);
502
503 for (int i = 0; i < 3; ++i) {
504 float overlap = obb.extents[i] - std::abs(localSpherePos[i]);
505 if (overlap < minOverlap) {
506 minOverlap = overlap;
507 localPushNormal = glm::vec3(0.0f);
508 localPushNormal[i] = (localSpherePos[i] > 0.0f) ? 1.0f : -1.0f;
509 }
510 }
511 info.penetration = sphereRadius + minOverlap;
512 info.normal = glm::normalize(obb.center +
513 localPushNormal.x * obb.axes[0] +
514 localPushNormal.y * obb.axes[1] +
515 localPushNormal.z * obb.axes[2] - obb.center);
516 }
517
518 if (flipNormal) {
519 info.normal = -info.normal;
520 }
521 info.contactPoints[0] = worldClosestPoint;
522 info.contactPenetrations[0] = info.penetration;
523 info.contactCount = 1;
524 }
525
526 return info;
527 }
528
529 CollisionInfo checkOBBOBB(const OBB& obbA, const OBB& obbB) {
530 CollisionInfo info;
531
532 glm::vec3 T = obbB.center - obbA.center;
533 glm::vec3 candidateAxes[15];
534 int axisCount = 0;
535
536 for (int i = 0; i < 3; ++i) candidateAxes[axisCount++] = obbA.axes[i];
537 for (int i = 0; i < 3; ++i) candidateAxes[axisCount++] = obbB.axes[i];
538 for (int i = 0; i < 3; ++i) {
539 for (int j = 0; j < 3; ++j) {
540 glm::vec3 axis = glm::cross(obbA.axes[i], obbB.axes[j]);
541 float axisLen = glm::length(axis);
542 if (axisLen > 1e-4f) {
543 candidateAxes[axisCount++] = axis / axisLen;
544 }
545 }
546 }
547
548 float minBiasedOverlap = std::numeric_limits<float>::max();
549 float bestUnbiasedOverlap = 0.0f;
550 glm::vec3 bestAxis(0.0f);
551
552 for (int i = 0; i < axisCount; ++i) {
553 glm::vec3 L = candidateAxes[i];
554 float d = std::abs(glm::dot(T, L));
555
556 float rA = obbA.extents.x * std::abs(glm::dot(obbA.axes[0], L)) +
557 obbA.extents.y * std::abs(glm::dot(obbA.axes[1], L)) +
558 obbA.extents.z * std::abs(glm::dot(obbA.axes[2], L));
559
560 float rB = obbB.extents.x * std::abs(glm::dot(obbB.axes[0], L)) +
561 obbB.extents.y * std::abs(glm::dot(obbB.axes[1], L)) +
562 obbB.extents.z * std::abs(glm::dot(obbB.axes[2], L));
563
564 float overlap = (rA + rB) - d;
565 if (overlap <= 0.0f) return info;
566
567 float biasedOverlap = overlap;
568 if (i >= 6) biasedOverlap *= 1.15f; // Face preference bias
569
570 if (biasedOverlap < minBiasedOverlap) {
571 minBiasedOverlap = biasedOverlap;
572 bestUnbiasedOverlap = overlap;
573 bestAxis = L;
574 }
575 }
576
577 info.collided = true;
578 info.penetration = bestUnbiasedOverlap;
579 if (glm::dot(T, bestAxis) < 0.0f) bestAxis = -bestAxis;
580 info.normal = bestAxis;
581
582 int bestAxisIndex = -1;
583 for (int i = 0; i < axisCount; ++i) {
584 if (glm::length(candidateAxes[i] - bestAxis) < 1e-3f || glm::length(candidateAxes[i] + bestAxis) < 1e-3f) {
585 bestAxisIndex = i;
586 break;
587 }
588 }
589
590 if (bestAxisIndex >= 0 && bestAxisIndex < 6) {
591 // Face contact: project vertices of both boxes to construct a stable manifold
592 glm::vec3 planePointA = obbA.center;
593 for (int i = 0; i < 3; ++i) {
594 planePointA += (glm::dot(obbA.axes[i], bestAxis) >= 0.0f ? 1.0f : -1.0f) * obbA.extents[i] * obbA.axes[i];
595 }
596
597 glm::vec3 planePointB = obbB.center;
598 for (int i = 0; i < 3; ++i) {
599 planePointB += (glm::dot(obbB.axes[i], -bestAxis) >= 0.0f ? 1.0f : -1.0f) * obbB.extents[i] * obbB.axes[i];
600 }
601
602 // Collect vertices of Box B penetrating A's face boundary bounds
603 glm::vec3 verticesB[8];
604 int idx = 0;
605 for (float x : {-1.0f, 1.0f}) {
606 for (float y : {-1.0f, 1.0f}) {
607 for (float z : {-1.0f, 1.0f}) {
608 verticesB[idx++] = obbB.center + x * obbB.extents.x * obbB.axes[0] + y * obbB.extents.y * obbB.axes[1] + z * obbB.extents.z * obbB.axes[2];
609 }
610 }
611 }
612 for (const auto& V : verticesB) {
613 float depth = glm::dot(planePointA - V, bestAxis);
614 if (depth > -1e-4f) {
615 glm::vec3 toV = V - obbA.center;
616 bool inside = true;
617 for (int i = 0; i < 3; ++i) {
618 if (std::abs(glm::dot(toV, obbA.axes[i])) > obbA.extents[i] + 0.05f) { inside = false; break; }
619 }
620 if (inside && info.contactCount < 8) {
621 info.contactPoints[info.contactCount] = V;
622 info.contactPenetrations[info.contactCount++] = std::max(0.0f, depth);
623 }
624 }
625 }
626
627 // Collect vertices of Box A penetrating B's face boundary bounds
628 glm::vec3 verticesA[8];
629 idx = 0;
630 for (float x : {-1.0f, 1.0f}) {
631 for (float y : {-1.0f, 1.0f}) {
632 for (float z : {-1.0f, 1.0f}) {
633 verticesA[idx++] = obbA.center + x * obbA.extents.x * obbA.axes[0] + y * obbA.extents.y * obbA.axes[1] + z * obbA.extents.z * obbA.axes[2];
634 }
635 }
636 }
637 for (const auto& V : verticesA) {
638 float depth = glm::dot(V - planePointB, bestAxis);
639 if (depth > -1e-4f) {
640 glm::vec3 toV = V - obbB.center;
641 bool inside = true;
642 for (int i = 0; i < 3; ++i) {
643 if (std::abs(glm::dot(toV, obbB.axes[i])) > obbB.extents[i] + 0.05f) { inside = false; break; }
644 }
645 if (inside && info.contactCount < 8) {
646 info.contactPoints[info.contactCount] = V;
647 info.contactPenetrations[info.contactCount++] = std::max(0.0f, depth);
648 }
649 }
650 }
651 }
652
653 // Fallback for edge-edge contacts or missed feature clipping pairs
654 if (info.contactCount == 0) {
655 glm::vec3 supportA = obbA.center;
656 for (int i = 0; i < 3; ++i) supportA += (glm::dot(obbA.axes[i], bestAxis) >= 0.0f ? 1.0f : -1.0f) * obbA.extents[i] * obbA.axes[i];
657 glm::vec3 supportB = obbB.center;
658 for (int i = 0; i < 3; ++i) supportB += (glm::dot(obbB.axes[i], -bestAxis) >= 0.0f ? 1.0f : -1.0f) * obbB.extents[i] * obbB.axes[i];
659
660 if (bestAxisIndex >= 0 && bestAxisIndex < 3) info.contactPoints[0] = supportB;
661 else if (bestAxisIndex >= 3 && bestAxisIndex < 6) info.contactPoints[0] = supportA;
662 else info.contactPoints[0] = 0.5f * (supportA + supportB);
663
664 info.contactPenetrations[0] = bestUnbiasedOverlap;
665 info.contactCount = 1;
666 }
667
668 return info;
669 }
670
672 Entity entityB, const ColliderComponent& colB) {
673 CollisionInfo info;
674 glm::mat4 worldMatrixA = getEntityWorldMatrix(entityA);
675 glm::mat4 worldMatrixB = getEntityWorldMatrix(entityB);
676 glm::vec3 posA = glm::vec3(worldMatrixA * glm::vec4(colA.offset, 1.0f));
677 glm::vec3 posB = glm::vec3(worldMatrixB * glm::vec4(colB.offset, 1.0f));
678
680 float rSum = colA.radius + colB.radius;
681 float dist = glm::distance(posA, posB);
682 if (dist < rSum) {
683 info.collided = true;
684 info.penetration = rSum - dist;
685 glm::vec3 dir = posB - posA;
686 float dirLen = glm::length(dir);
687 info.normal = (dirLen > 1e-4f) ? glm::normalize(dir) : glm::vec3(0.0f, 1.0f, 0.0f);
688 info.contactPoints[0] = (dirLen > 1e-4f) ? (posA + info.normal * colA.radius) : (0.5f * (posA + posB));
689 info.contactPenetrations[0] = info.penetration;
690 info.contactCount = 1;
691 }
692 } else if (colA.shape == ColliderShape::Sphere && colB.shape == ColliderShape::AABB) {
693 return checkSphereAABB(colA, posA, colB, posB, true);
694 } else if (colA.shape == ColliderShape::AABB && colB.shape == ColliderShape::Sphere) {
695 return checkSphereAABB(colB, posB, colA, posA, false);
696 } else if (colA.shape == ColliderShape::AABB && colB.shape == ColliderShape::AABB) {
697 float overlapX = (colA.extents.x + colB.extents.x) - std::abs(posB.x - posA.x);
698 float overlapY = (colA.extents.y + colB.extents.y) - std::abs(posB.y - posA.y);
699 float overlapZ = (colA.extents.z + colB.extents.z) - std::abs(posB.z - posA.z);
700 if (overlapX > 0.0f && overlapY > 0.0f && overlapZ > 0.0f) {
701 info.collided = true;
702 if (overlapX < overlapY && overlapX < overlapZ) {
703 info.penetration = overlapX;
704 info.normal = glm::vec3((posB.x > posA.x) ? 1.0f : -1.0f, 0.0f, 0.0f);
705 } else if (overlapY < overlapX && overlapY < overlapZ) {
706 info.penetration = overlapY;
707 info.normal = glm::vec3(0.0f, (posB.y > posA.y) ? 1.0f : -1.0f, 0.0f);
708 } else {
709 info.penetration = overlapZ;
710 info.normal = glm::vec3(0.0f, 0.0f, (posB.z > posA.z) ? 1.0f : -1.0f);
711 }
712 glm::vec3 supportA = posA + info.normal * colA.extents;
713 glm::vec3 supportB = posB - info.normal * colB.extents;
714 info.contactPoints[0] = 0.5f * (supportA + supportB);
715 info.contactPenetrations[0] = info.penetration;
716 info.contactCount = 1;
717 }
718 } else if (colA.shape == ColliderShape::Sphere && colB.shape == ColliderShape::OBB) {
719 return checkOBBSphere(getOBB(entityB, colB), posA, colA.radius, true);
720 } else if (colA.shape == ColliderShape::OBB && colB.shape == ColliderShape::Sphere) {
721 return checkOBBSphere(getOBB(entityA, colA), posB, colB.radius, false);
722 } else {
723 OBB obbA = (colA.shape == ColliderShape::OBB) ? getOBB(entityA, colA) : getOBBFromAABB(colA, posA);
724 OBB obbB = (colB.shape == ColliderShape::OBB) ? getOBB(entityB, colB) : getOBBFromAABB(colB, posB);
725 return checkOBBOBB(obbA, obbB);
726 }
727 return info;
728 }
729
731 Entity entityB, Transform& transB, ColliderComponent& colB,
732 const CollisionInfo& colInfo, float dt) {
735
736 bool staticA = !rbA || (rbA->type == RigidBodyType::Static);
737 bool staticB = !rbB || (rbB->type == RigidBodyType::Static);
738 if (staticA && staticB) return;
739
740 glm::mat4 worldMatrixA = getEntityWorldMatrix(entityA);
741 glm::mat4 worldMatrixB = getEntityWorldMatrix(entityB);
742 OBB obbA = (colA.shape == ColliderShape::OBB) ? getOBB(entityA, colA) : getOBBFromAABB(colA, glm::vec3(worldMatrixA * glm::vec4(colA.offset, 1.0f)));
743 OBB obbB = (colB.shape == ColliderShape::OBB) ? getOBB(entityB, colB) : getOBBFromAABB(colB, glm::vec3(worldMatrixB * glm::vec4(colB.offset, 1.0f)));
744
745 glm::vec3 normal = glm::normalize(colInfo.normal);
746
747 if (staticA || staticB) {
748 const OBB& staticOBB = staticA ? obbA : obbB;
749 float maxDot = 0.0f; int bestAxisIndex = -1; float bestSign = 1.0f;
750 for (int i = 0; i < 3; ++i) {
751 float dotVal = glm::dot(normal, staticOBB.axes[i]);
752 if (std::abs(dotVal) > maxDot) { maxDot = std::abs(dotVal); bestAxisIndex = i; bestSign = (dotVal >= 0.0f) ? 1.0f : -1.0f; }
753 }
754 if (maxDot > 0.95f) normal = bestSign * staticOBB.axes[bestAxisIndex];
755 }
756
757 if (!staticA) rbA->hadContactThisFrame = true;
758 if (!staticB) rbB->hadContactThisFrame = true;
759
760 bool aSleeping = rbA && rbA->sleeping;
761 bool bSleeping = rbB && rbB->sleeping;
762 auto wakeIfMoving = [](RigidBodyComponent* rb, RigidBodyComponent* other, bool otherStatic) {
763 if (!rb || !rb->sleeping || otherStatic || !other || other->sleeping) return;
764 rb->sleeping = false; rb->sleepTimer = 0.0f;
765 };
766 wakeIfMoving(rbA, rbB, staticB); wakeIfMoving(rbB, rbA, staticA);
767
768 aSleeping = rbA && rbA->sleeping; bSleeping = rbB && rbB->sleeping;
769 bool skipVelocityA = aSleeping && (staticB || bSleeping);
770 bool skipVelocityB = bSleeping && (staticA || aSleeping);
771
772 // --- Compute Proper Inertia Tensors (1/12th scale factor) ---
773 glm::mat3 invInertiaWorldA(0.0f);
774 float invMassA = (staticA || rbA->mass < 1e-4f) ? 0.0f : 1.0f / rbA->mass;
775 if (!staticA && rbA->mass > 1e-4f) {
776 glm::mat3 R = glm::mat3(obbA.axes[0], obbA.axes[1], obbA.axes[2]);
777 glm::mat3 invInertiaLocal(0.0f);
778 if (colA.shape == ColliderShape::Sphere) {
779 invInertiaLocal = glm::mat3(2.5f / (rbA->mass * colA.radius * colA.radius));
780 } else {
781 float ex = obbA.extents.x; float ey = obbA.extents.y; float ez = obbA.extents.z;
782 invInertiaLocal[0][0] = 1.0f / ((1.0f / 12.0f) * rbA->mass * (ey * ey + ez * ez));
783 invInertiaLocal[1][1] = 1.0f / ((1.0f / 12.0f) * rbA->mass * (ex * ex + ez * ez));
784 invInertiaLocal[2][2] = 1.0f / ((1.0f / 12.0f) * rbA->mass * (ex * ex + ey * ey));
785 }
786 invInertiaWorldA = R * invInertiaLocal * glm::transpose(R);
787 }
788
789 glm::mat3 invInertiaWorldB(0.0f);
790 float invMassB = (staticB || rbB->mass < 1e-4f) ? 0.0f : 1.0f / rbB->mass;
791 if (!staticB && rbB->mass > 1e-4f) {
792 glm::mat3 R = glm::mat3(obbB.axes[0], obbB.axes[1], obbB.axes[2]);
793 glm::mat3 invInertiaLocal(0.0f);
794 if (colB.shape == ColliderShape::Sphere) {
795 invInertiaLocal = glm::mat3(2.5f / (rbB->mass * colB.radius * colB.radius));
796 } else {
797 float ex = obbB.extents.x; float ey = obbB.extents.y; float ez = obbB.extents.z;
798 invInertiaLocal[0][0] = 1.0f / ((1.0f / 12.0f) * rbB->mass * (ey * ey + ez * ez));
799 invInertiaLocal[1][1] = 1.0f / ((1.0f / 12.0f) * rbB->mass * (ex * ex + ez * ez));
800 invInertiaLocal[2][2] = 1.0f / ((1.0f / 12.0f) * rbB->mass * (ex * ex + ey * ey));
801 }
802 invInertiaWorldB = R * invInertiaLocal * glm::transpose(R);
803 }
804
805 auto computeK = [&](float invM_A, float invM_B, const glm::mat3& invI_A, const glm::mat3& invI_B, const glm::vec3& r_A, const glm::vec3& r_B, const glm::vec3& dir) {
806 float K = invM_A + invM_B;
807 if (invM_A > 0.0f) K += glm::dot(glm::cross(invI_A * glm::cross(r_A, dir), r_A), dir);
808 if (invM_B > 0.0f) K += glm::dot(glm::cross(invI_B * glm::cross(r_B, dir), r_B), dir);
809 return K;
810 };
811
812 int contactCount = colInfo.contactCount;
813 if (contactCount == 0) return;
814
815 // --- 1. Instant Position Projection ---
816 float slop = 0.0001f;
817 float baumgarte = 0.5f;
818 for (int cp = 0; cp < contactCount; ++cp) {
819 glm::vec3 rA = colInfo.contactPoints[cp] - transA.position;
820 glm::vec3 rB = colInfo.contactPoints[cp] - transB.position;
821 float penetration = colInfo.contactPenetrations[cp];
822
823 if (penetration > slop) {
824 float K_pos = computeK(invMassA, invMassB, invInertiaWorldA, invInertiaWorldB, rA, rB, normal);
825 if (K_pos > 1e-4f) {
826 float J_p = ((penetration - slop) * baumgarte / K_pos) / static_cast<float>(contactCount);
827 glm::vec3 C_p = J_p * normal;
828 if (!staticA) {
829 transA.position -= invMassA * C_p;
830 applyAngularDisplacement(transA, -invInertiaWorldA * glm::cross(rA, C_p));
831 }
832 if (!staticB) {
833 transB.position += invMassB * C_p;
834 applyAngularDisplacement(transB, invInertiaWorldB * glm::cross(rB, C_p));
835 }
836 }
837 }
838 }
839
840 if (skipVelocityA && skipVelocityB) return;
841
842 // --- 2. Cache Initial Velocities for Stable Manifold Pass Evaluation ---
843 glm::vec3 initialVelA = rbA ? rbA->velocity : glm::vec3(0.0f);
844 glm::vec3 initialVelB = rbB ? rbB->velocity : glm::vec3(0.0f);
845 glm::vec3 initialAngVelA = rbA ? rbA->angularVelocity : glm::vec3(0.0f);
846 glm::vec3 initialAngVelB = rbB ? rbB->angularVelocity : glm::vec3(0.0f);
847
848 glm::vec3 accumulatedVelA{0.0f}, accumulatedVelB{0.0f};
849 glm::vec3 accumulatedAngVelA{0.0f}, accumulatedAngVelB{0.0f};
850 float totalImpulseScalar = 0.0f;
851
852 for (int cp = 0; cp < contactCount; ++cp) {
853 glm::vec3 rA = colInfo.contactPoints[cp] - transA.position;
854 glm::vec3 rB = colInfo.contactPoints[cp] - transB.position;
855
856 glm::vec3 contactVelA = initialVelA + glm::cross(initialAngVelA, rA);
857 glm::vec3 contactVelB = initialVelB + glm::cross(initialAngVelB, rB);
858 glm::vec3 relativeVel = contactVelB - contactVelA;
859
860 float velAlongNormal = glm::dot(relativeVel, normal);
861 float restitutionA = rbA ? rbA->restitution : 0.5f;
862 float restitutionB = rbB ? rbB->restitution : 0.5f;
863 float e = std::min(restitutionA, restitutionB);
864
865 if (velAlongNormal > -0.25f || glm::dot(initialVelB - initialVelA, normal) > -0.25f) e = 0.0f;
866
867 float K_vel = computeK(invMassA, invMassB, invInertiaWorldA, invInertiaWorldB, rA, rB, normal);
868 float impulseScalar = 0.0f;
869
870 if (K_vel > 1e-4f && velAlongNormal < 0.0f) {
871 impulseScalar = (-(1.0f + e) * velAlongNormal / K_vel) / static_cast<float>(contactCount);
872 }
873
874 if (impulseScalar > 0.0f) {
875 glm::vec3 impulse = impulseScalar * normal;
876 if (!staticA && !skipVelocityA) {
877 accumulatedVelA -= invMassA * impulse;
878 accumulatedAngVelA -= invInertiaWorldA * glm::cross(rA, impulse);
879 }
880 if (!staticB && !skipVelocityB) {
881 accumulatedVelB += invMassB * impulse;
882 accumulatedAngVelB += invInertiaWorldB * glm::cross(rB, impulse);
883 }
884 totalImpulseScalar += impulseScalar;
885 }
886
887 // --- Friction Processing ---
888 glm::vec3 tangent = relativeVel - glm::dot(relativeVel, normal) * normal;
889 float tangentLen = glm::length(tangent);
890 if (tangentLen > 1e-5f) {
891 tangent = glm::normalize(tangent);
892 float K_tangent = computeK(invMassA, invMassB, invInertiaWorldA, invInertiaWorldB, rA, rB, tangent);
893 if (K_tangent > 1e-4f) {
894 float tangentImpulseScalar = (-tangentLen / K_tangent) / static_cast<float>(contactCount);
895 float frictionA = rbA ? rbA->friction : 0.3f;
896 float frictionB = rbB ? rbB->friction : 0.3f;
897 float mu = std::sqrt(frictionA * frictionB);
898
899 float effectiveNormalImpulse = impulseScalar;
900 if (effectiveNormalImpulse < 1e-5f && colInfo.contactPenetrations[cp] > 1e-5f) {
901 float activeMass = (rbA && !staticA) ? rbA->mass : ((rbB && !staticB) ? rbB->mass : 1.0f);
902 effectiveNormalImpulse = (activeMass * 9.81f * dt) / static_cast<float>(contactCount);
903 }
904 float maxFriction = mu * effectiveNormalImpulse;
905
906 if (std::abs(tangentImpulseScalar) > maxFriction) {
907 tangentImpulseScalar = (tangentImpulseScalar > 0.0f) ? maxFriction : -maxFriction;
908 }
909
910 glm::vec3 tangentImpulse = tangentImpulseScalar * tangent;
911 if (!staticA && !skipVelocityA) {
912 accumulatedVelA -= invMassA * tangentImpulse;
913 accumulatedAngVelA -= invInertiaWorldA * glm::cross(rA, tangentImpulse);
914 }
915 if (!staticB && !skipVelocityB) {
916 accumulatedVelB += invMassB * tangentImpulse;
917 accumulatedAngVelB += invInertiaWorldB * glm::cross(rB, tangentImpulse);
918 }
919 }
920 }
921 }
922
923 // Flush stacked velocity changes to bodies
924 if (rbA && !staticA && !skipVelocityA) { rbA->velocity += accumulatedVelA; rbA->angularVelocity += accumulatedAngVelA; }
925 if (rbB && !staticB && !skipVelocityB) { rbB->velocity += accumulatedVelB; rbB->angularVelocity += accumulatedAngVelB; }
926
927 // --- 3. Torsional Friction ---
928 glm::vec3 relAngVel = (rbB ? rbB->angularVelocity : glm::vec3(0.0f)) - (rbA ? rbA->angularVelocity : glm::vec3(0.0f));
929 float angVelAlongN = glm::dot(relAngVel, normal);
930 if (std::abs(angVelAlongN) > 1e-5f) {
931 float K_rot = 0.0f;
932 if (!staticA) K_rot += glm::dot(invInertiaWorldA * normal, normal);
933 if (!staticB) K_rot += glm::dot(invInertiaWorldB * normal, normal);
934
935 if (K_rot > 1e-5f) {
936 float rotImpulseScalar = -angVelAlongN / K_rot;
937 float frictionA = rbA ? rbA->friction : 0.3f;
938 float frictionB = rbB ? rbB->friction : 0.3f;
939 float maxRotFriction = std::sqrt(frictionA * frictionB) * 0.1f * totalImpulseScalar;
940
941 if (std::abs(rotImpulseScalar) > maxRotFriction) rotImpulseScalar = (rotImpulseScalar > 0.0f) ? maxRotFriction : -maxRotFriction;
942 glm::vec3 rotImpulse = rotImpulseScalar * normal;
943
944 if (!staticA && !skipVelocityA) rbA->angularVelocity -= invInertiaWorldA * rotImpulse;
945 if (!staticB && !skipVelocityB) rbB->angularVelocity += invInertiaWorldB * rotImpulse;
946 }
947 }
948
949 // Enforce hard constraints back on velocities
950 auto applyVelocityConstraints = [](RigidBodyComponent* rb) {
951 if (!rb) return;
952 if (rb->freezePositionX) rb->velocity.x = 0.0f;
953 if (rb->freezePositionY) rb->velocity.y = 0.0f;
954 if (rb->freezePositionZ) rb->velocity.z = 0.0f;
955 if (rb->freezeRotationX) rb->angularVelocity.x = 0.0f;
956 if (rb->freezeRotationY) rb->angularVelocity.y = 0.0f;
957 if (rb->freezeRotationZ) rb->angularVelocity.z = 0.0f;
958 };
959 if (!staticA) applyVelocityConstraints(rbA);
960 if (!staticB) applyVelocityConstraints(rbB);
961 }
962
965 };
966
967} // namespace Engine
@ AABB
Axis-Aligned Bounding Box volume.
Definition Collider.hpp:16
@ Capsule
Capsule volume defined by radius and height.
Definition Collider.hpp:20
@ OBB
Oriented Bounding Box volume.
Definition Collider.hpp:18
@ Sphere
Spherical collision volume defined by radius.
Definition Collider.hpp:14
@ Static
Definition RigidBody.hpp:10
CollisionInfo checkSphereAABB(const ColliderComponent &sphere, const glm::vec3 &sPos, const ColliderComponent &aabb, const glm::vec3 &aPos, bool flipNormal)
Definition PhysicsSystem.hpp:430
glm::mat4 getEntityWorldMatrix(Entity entity, int depth=0)
Definition PhysicsSystem.hpp:381
EditorModeState & editorMode
Definition PhysicsSystem.hpp:964
void applyAngularDisplacement(Transform &transform, const glm::vec3 &deltaTheta)
Definition PhysicsSystem.hpp:51
OBB getOBB(Entity entity, const ColliderComponent &col)
Definition PhysicsSystem.hpp:395
RaycastHit raycast(const Ray &ray)
Definition PhysicsSystem.hpp:222
OBB getOBBFromAABB(const ColliderComponent &col, const glm::vec3 &pos)
Definition PhysicsSystem.hpp:415
CollisionInfo checkCollision(Entity entityA, const ColliderComponent &colA, Entity entityB, const ColliderComponent &colB)
Definition PhysicsSystem.hpp:671
PhysicsSystem(Registry &reg, EditorModeState &editorMode)
Definition PhysicsSystem.hpp:48
void resolveCollision(Entity entityA, Transform &transA, ColliderComponent &colA, Entity entityB, Transform &transB, ColliderComponent &colB, const CollisionInfo &colInfo, float dt)
Definition PhysicsSystem.hpp:730
CollisionInfo checkOBBOBB(const OBB &obbA, const OBB &obbB)
Definition PhysicsSystem.hpp:529
Registry & registry
Definition PhysicsSystem.hpp:963
void update(float dt) override
Pure virtual update function to implement system behaviors.
Definition PhysicsSystem.hpp:65
CollisionInfo checkOBBSphere(const OBB &obb, const glm::vec3 &sphereCenter, float sphereRadius, bool flipNormal)
Definition PhysicsSystem.hpp:472
Lightweight identifier representing a game object in the Entity Component System.
Definition Entity.hpp:11
static constexpr IdType INVALID_ENTITY
Constant representing a null or invalid entity.
Definition Entity.hpp:16
Coordinates entities and components, providing creation, removal, lookup, and views.
Definition Registry.hpp:30
Base class for ECS systems that process sets of entities.
Definition System.hpp:12
Definition Application.hpp:16
Represents a collision volume (Sphere, Axis-Aligned Bounding Box, Oriented Bounding Box,...
Definition Collider.hpp:28
float radius
Radius used for Sphere and Capsule colliders.
Definition Collider.hpp:33
glm::vec3 offset
Local position offset relative to entity transform origin.
Definition Collider.hpp:42
float height
Total height (including hemispherical caps) for Capsule colliders.
Definition Collider.hpp:36
glm::vec3 extents
Half-extents vector for AABB and OBB colliders.
Definition Collider.hpp:39
ColliderShape shape
Active primitive collision shape.
Definition Collider.hpp:30
Struct keeping track of active editor states (e.g. fly mode vs editor UI interaction).
Definition EditorModeState.hpp:7
Definition PhysicsSystem.hpp:20
bool collided
Definition PhysicsSystem.hpp:21
float penetration
Definition PhysicsSystem.hpp:23
int contactCount
Definition PhysicsSystem.hpp:26
glm::vec3 contactPoints[8]
Definition PhysicsSystem.hpp:24
float contactPenetrations[8]
Definition PhysicsSystem.hpp:25
glm::vec3 normal
Definition PhysicsSystem.hpp:22
Definition PhysicsSystem.hpp:375
glm::vec3 center
Definition PhysicsSystem.hpp:376
glm::vec3 extents
Definition PhysicsSystem.hpp:378
glm::vec3 axes[3]
Definition PhysicsSystem.hpp:377
Definition PhysicsSystem.hpp:29
glm::vec3 origin
Definition PhysicsSystem.hpp:30
glm::vec3 direction
Definition PhysicsSystem.hpp:31
Definition PhysicsSystem.hpp:34
bool hit
Definition PhysicsSystem.hpp:35
glm::vec3 position
Definition PhysicsSystem.hpp:38
float distance
Definition PhysicsSystem.hpp:37
Entity entity
Definition PhysicsSystem.hpp:36
glm::vec3 normal
Definition PhysicsSystem.hpp:39
Represents a parent-child relationship between ECS entities.
Definition Hierarchy.hpp:8
Holds mass, velocity, acceleration, forces, restitution, bounciness, and gravity settings.
Definition RigidBody.hpp:18
RigidBodyType type
Definition RigidBody.hpp:19
float friction
Definition RigidBody.hpp:33
float sleepTimer
Definition RigidBody.hpp:46
bool freezePositionZ
Definition RigidBody.hpp:58
bool freezePositionY
Definition RigidBody.hpp:56
bool hadContactThisFrame
Definition RigidBody.hpp:48
bool freezeRotationY
Definition RigidBody.hpp:62
bool freezeRotationX
Definition RigidBody.hpp:60
bool freezeRotationZ
Definition RigidBody.hpp:64
glm::vec3 angularVelocity
Definition RigidBody.hpp:37
float restitution
Definition RigidBody.hpp:31
float mass
Definition RigidBody.hpp:21
bool sleeping
Definition RigidBody.hpp:47
glm::vec3 velocity
Definition RigidBody.hpp:23
bool freezePositionX
Definition RigidBody.hpp:54
glm::quat getQuat() const
Definition Transform.hpp:111
Represents the position, rotation, and scale of an entity in 3D space.
Definition Transform.hpp:127
RotationField rotation
Definition Transform.hpp:132
glm::vec3 position
Definition Transform.hpp:130
static ufbxi_noinline int depth
Definition ufbx.cpp:7467
static ufbxi_noinline bool axis
Definition ufbx.cpp:28305
uint64_t offset
Definition ufbx.cpp:9361