ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1
11
12#ifndef TOYMAKERENGINE_SPATIALQUERYTYPES_H
13#define TOYMAKERENGINE_SPATIALQUERYTYPES_H
14
15#include <cmath>
16#include <array>
17#include <queue>
18#include <glm/glm.hpp>
19#include <glm/gtc/quaternion.hpp>
20
21#include "../core/ecs_world.hpp"
22
23namespace ToyMaker {
24 struct AreaTriangle;
25
26 inline float squareDistance(const glm::vec3& vector) {
27 return glm::dot(vector, vector);
28 }
29
35 using BoxCorner = uint8_t;
36
43 RIGHT=0x1,
44 TOP=0x2,
45 FRONT=0x4
46 };
47
48
57 inline bool isFinite(float number) {
58 return std::isfinite(number);
59 }
60
68 inline bool isFinite(const glm::vec3& vector) {
69 return isFinite(vector.x) && isFinite(vector.y) && isFinite(vector.z);
70 }
71
80 inline bool isPositiveStrict(float number) {
81 return number > 0.f;
82 }
83
91 inline bool isPositiveStrict(const glm::vec3& vector) {
92 return isPositiveStrict(vector.x) && isPositiveStrict(vector.y) && isPositiveStrict(vector.z);
93 }
94
103 inline bool isNonNegative(float number) {
104 return number >= 0.f;
105 }
106
115 inline bool isNonNegative(const glm::vec3& vector) {
116 return isNonNegative(vector.x) && isNonNegative(vector.y) && isNonNegative(vector.z);
117 }
118
119
120 template <typename TDerived>
121 struct Volume;
122
123
131 struct VolumeBase_ {
140 inline static constexpr std::array<glm::vec3, 8> GetCornerSignsArray() {
141 std::array<glm::vec3, 8> cornerSigns {};
142 for(BoxCorner corner {0}; corner < 8; ++corner) {
143 cornerSigns[corner].x = corner&BoxCornerSpecifier::RIGHT? 1.f: -1.f;
144 cornerSigns[corner].y = corner&BoxCornerSpecifier::TOP? 1.f: -1.f;
145 cornerSigns[corner].z = corner&BoxCornerSpecifier::FRONT? 1.f: -1.f;
146 }
147 return cornerSigns;
148 }
149
156 inline static std::array<glm::vec3, 8> ComputeBoxCorners(const glm::vec3& boxDimensions) {
157 const std::array<glm::vec3, 8> cornerSignsArray { GetCornerSignsArray() };
158 glm::vec3 absoluteCornerOffset { .5f * boxDimensions };
159 std::array<glm::vec3, 8> cornerArray { .5f * boxDimensions };
160 for(uint8_t corner{0}; corner < 8; ++corner) {
161 cornerArray[corner] = cornerSignsArray[corner] * absoluteCornerOffset;
162 }
163 return cornerArray;
164 }
165
175 template <typename TDerived>
176 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const {
178 }
179
190 template <typename TDerived>
191 inline bool isSensible() const {
193 }
194
203 template <typename TDerived>
204 inline bool isPositiveStrict() const {
206 }
207 };
208
210 template <typename TDerived>
211 struct Volume: public VolumeBase_ {
218 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const {
219 return TDerived::getVolumeRelativeBoxCorners();
220 }
221
228 inline bool isSensible() const {
229 return TDerived::isSensible();
230 }
231
238 inline bool isPositiveStrict() const {
239 return TDerived::isPositiveStrict();
240 }
241 };
242
248 struct VolumeBox: public Volume<VolumeBox> {
253 glm::vec3 mDimensions {0.f, 0.f, 0.f};
254
260 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
262 }
263
270 inline bool isSensible() const {
272 }
273
280 inline bool isPositiveStrict() const {
282 }
283 };
284
290 struct VolumeCapsule: public Volume<VolumeCapsule> {
295 float mHeight {0.f};
296
301 float mRadius {0.f};
302
308 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
309 const glm::vec3 boxDimensions { 2.f*mRadius, mHeight + 2.f*mRadius, 2.f*mRadius};
310 return ComputeBoxCorners(boxDimensions);
311 }
312
321 inline bool isSensible() const {
322 return (
325 );
326 }
327
335 inline bool isPositiveStrict() const {
336 return (
338 // You can still have a capsule which occupies space even if its
339 // spine is length 0, so no test for mHeight
340 );
341 }
342 };
343
349 struct VolumeSphere: public Volume<VolumeSphere> {
354 float mRadius {0.f};
355
361 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
362 return ComputeBoxCorners(glm::vec3{2*mRadius});
363 }
364
371 inline bool isSensible() const {
373 }
374
382 inline bool isPositiveStrict() const {
384 }
385 };
386
397 std::array<glm::vec3, 3> mPoints {};
398
405 inline bool isSensible() const {
406 return (
407 (
409 ) && (
411 glm::length(glm::cross(
412 mPoints[2] - mPoints[0], mPoints[1] - mPoints[0]
413 ))
414 )
415 )
416 );
417 }
418
426 inline bool isPositiveStrict() const {
427 return (
429 glm::length(
430 glm::cross(
431 mPoints[2] - mPoints[0], mPoints[1] - mPoints[0]
432 )
433 )
434 )
435 );
436 }
437 };
438
448 std::array<AreaTriangle, 12> computeBoxFaceTriangles(const std::array<glm::vec3, 8>& boxCorners);
449
455 struct AreaCircle {
460 float mRadius { 0.f };
461
466 glm::vec3 mCenter { 0.f };
467
472 glm::vec3 mNormal { 0.f, -1.f, 0.f };
473
480 inline bool isSensible() const {
481 return (
482 (
484 ) && (
486 ) && (
488 )
489 );
490 }
491
499 inline bool isPositiveStrict() const {
500 return (
502 );
503 }
504 };
505
511 struct Ray {
516 glm::vec3 mStart { 0.f };
517
522 glm::vec3 mDirection { 0.f, 0.f, -1.f };
523
528 float mLength { std::numeric_limits<float>::infinity() };
529
536 inline bool isSensible() const {
537 return (
538 (
540 ) && (
542 ) && (
544 )
545 );
546 }
547
554 inline bool isPositiveStrict() const {
556 }
557 };
558
564 struct Plane {
569 glm::vec3 mPointOnPlane { 0.f };
570
575 glm::vec3 mNormal { 0.f, 0.f, -1.f };
576
583 inline bool isSensible() const {
584 return (
585 (
587 ) && (
589 )
590 );
591 }
592
601 inline bool isPositiveStrict() const {
602 return isSensible();
603 }
604 };
605
613 struct Simplex {
619 std::array<glm::vec3, 4> mPoints;
620
625 std::array<glm::vec3, 4> mPointsSupportA;
626
631 std::array<glm::vec3, 4> mPointsSupportB;
632
637 uint8_t mNPoints { 0 };
638
645 inline bool append(const glm::vec3& candidatePoint, const glm::vec3& supportA, const glm::vec3& supportB) {
646 assert(mNPoints < 4 && "We already have 4 (or more) points, there's no more needed");
647 assert(supportA - supportB == candidatePoint && "The difference in supports should yield the candidate point");
648
649 // Hackery to ensure that we don't add the same point twice (which is a possibility
650 // since the hackery to force 3-simplex might cause us to look in the same direction
651 // twice)
652 for(uint8_t index { 0 }; index < mNPoints; ++index) {
653 if(mPoints[index] == candidatePoint) {
654 return false;
655 }
656 }
657 mPoints[mNPoints] = candidatePoint;
658 mPointsSupportA[mNPoints] = supportA;
659 mPointsSupportB[mNPoints] = supportB;
660 ++mNPoints;
661
662 return true;
663 }
664
669 inline void reorder(const std::vector<uint8_t> reorderedIndices) {
670 assert(reorderedIndices.size() <= 4 && "Invalid point list provided");
671 const std::array<glm::vec3, 4> oldPoints { mPoints };
672 const std::array<glm::vec3, 4> oldPointsSupportA { mPointsSupportA };
673 const std::array<glm::vec3, 4> oldPointsSupportB { mPointsSupportB };
674 mNPoints = 0;
675 for(const auto& index: reorderedIndices) {
676 const bool pointAddedSuccessfully{ append(oldPoints[index], oldPointsSupportA[index], oldPointsSupportB[index]) };
677 assert(pointAddedSuccessfully && "Invalid point list provided");
678 }
679 }
680
692 std::pair<bool, glm::vec3> evaluate();
693
694 private:
695 std::pair<bool, glm::vec3> doSimplex4();
696 glm::vec3 doSimplex3();
697 glm::vec3 doSimplex2();
698 };
699
708 class Polytope {
709 private:
713 struct Face {
714 std::array<uint16_t, 3> mIndices {};
715 };
716
720 Polytope();
721
722
727 std::priority_queue<Face, std::vector<Face>, std::function<bool(const Face&, const Face&)>> mFaces;
728
732 std::vector<glm::vec3> mPoints {};
737 std::vector<glm::vec3> mPointsSupportA {};
738
743 std::vector<glm::vec3> mPointsSupportB {};
744
745 inline glm::vec3 getTriangleCross(const Face& face) const {
746 return glm::cross(
747 mPoints[face.mIndices[1]] - mPoints[face.mIndices[0]],
748 mPoints[face.mIndices[2]] - mPoints[face.mIndices[0]]
749 );
750 }
751
752 inline glm::vec3 getTriangleNorm(const Face& face) const {
753 return glm::normalize(getTriangleCross(face));
754 }
755
756 public:
762 Polytope(const Simplex& simplex);
763
768 glm::vec3 getNextSearch() const;
769
773 std::size_t getNumFaces() const {
774 return mFaces.size();
775 }
776
777 std::size_t getNumPoints() const {
778 return mPoints.size();
779 }
780
786 glm::vec3 getClosestPoint() const;
787
795 glm::vec3 getClosestTriangleNormal() const;
796
804 AreaTriangle getClosestTriangle() const;
805
811 AreaTriangle getClosestTriangleSupportA() const;
812
818 AreaTriangle getClosestTriangleSupportB() const;
819
832 bool append(const glm::vec3& newPoint, const glm::vec3& supportA, const glm::vec3& supportB);
833 };
834
843 struct Contact {
848 glm::vec3 mPoint;
849
855 glm::vec3 mNormal;
856
861 glm::vec3 mTangent1;
862
867 glm::vec3 mTangent2;
868
875 };
876
907
923 inline static std::string getComponentTypeName() { return "ObjectBounds"; }
924
929 enum class TrueVolumeType: uint8_t {
930 BOX=0,
931 SPHERE,
932 CAPSULE,
933 };
934
940 VolumeBox mBox { .mDimensions{ glm::vec3{0.f} } };
941 VolumeCapsule mCapsule;
942 VolumeSphere mSphere;
943 };
944
956 static ObjectBounds create(const VolumeBox& box, const glm::vec3& positionOffset, const glm::quat& orientationOffset);
957
969 static ObjectBounds create(const VolumeCapsule& capsule, const glm::vec3& positionOffset, const glm::quat& orientationOffset);
970
982 static ObjectBounds create(const VolumeSphere& sphere, const glm::vec3& positionOffset, const glm::quat& orientationOffset);
983
988 TrueVolumeType mType { TrueVolumeType::BOX };
989
995
1000 glm::vec3 mPosition { 0.f };
1001
1006 glm::vec3 mPositionOffset { 0.f };
1007
1012 glm::quat mOrientation { glm::vec3{ 0.f } };
1013
1019 glm::quat mOrientationOffset { glm::vec3{ 0.f } };
1020
1026 void applyModelMatrix(const glm::mat4& modelMatrix);
1027
1033 inline glm::mat3 getLocalRotationTransform() const {
1034 return glm::mat3_cast(glm::normalize(mOrientationOffset));
1035 }
1036
1042 inline glm::mat3 getWorldRotationTransform() const {
1043 return glm::mat3_cast(glm::normalize(mOrientation));
1044 }
1045
1051 glm::vec3 getComputedWorldPosition() const;
1052
1058 glm::quat getComputedWorldOrientation() const;
1059
1065 std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const;
1066
1072 std::array<glm::vec3, 8> getLocalOrientedBoxCorners() const;
1073
1079 std::array<glm::vec3, 8> getWorldOrientedBoxCorners() const;
1080
1090
1101 glm::vec3 getSupportAlong(const glm::vec3& axis) const;
1102
1109 std::pair<float, float> getProjectionAlong(const glm::vec3& axis) const;
1110
1116 bool isSensible() const;
1117
1123 bool isPositiveStrict() const;
1124 protected:
1125 };
1126
1139 public:
1145 inline static std::string getComponentTypeName() { return "AxisAlignedBounds"; }
1146
1151 using Extents = std::pair<glm::vec3, glm::vec3>;
1152
1158
1164 AxisAlignedBounds(const ObjectBounds& objectBounds);
1165
1171 AxisAlignedBounds(const Extents& axisAlignedExtents);
1172
1179 AxisAlignedBounds(const glm::vec3& position, const glm::vec3& dimensions):
1180 AxisAlignedBounds { Extents{{position + .5f*dimensions}, {position - .5f*dimensions}} }
1181 {}
1182
1189 AxisAlignedBounds operator+(const AxisAlignedBounds& other) const;
1190
1196 std::array<glm::vec3, 8> getAxisAlignedBoxCorners() const;
1197
1203 inline std::array<AreaTriangle, 12> getAxisAlignedBoxFaceTriangles() const { return computeBoxFaceTriangles(getAxisAlignedBoxCorners()); }
1204
1210 Extents getAxisAlignedBoxExtents() const;
1211
1217 inline glm::vec3 getDimensions() const { return mExtents.first - mExtents.second; }
1218
1224 inline glm::vec3 getComputedWorldPosition() const { return mExtents.second + .5f * getDimensions(); }
1225
1232 inline bool isSensible() const {
1233 return (
1234 isFinite(mExtents.first) && isFinite(mExtents.second)
1235 && isNonNegative(mExtents.first - mExtents.second)
1236 );
1237 }
1238
1247 glm::vec3 getSupportAlong(const glm::vec3& axis) const;
1248
1255 inline bool isPositiveStrict() const {
1256 return (
1258 );
1259 }
1260
1266 inline void setPosition(const glm::vec3& position) {
1267 assert(isFinite(position) && "Invalid position specified. Position must be finite");
1268 const glm::vec3 deltaPosition { position - getComputedWorldPosition() };
1269 mExtents.first += deltaPosition;
1270 mExtents.second += deltaPosition;
1271 }
1272
1278 inline void setDimensions(const glm::vec3& dimensions) {
1279 assert(isNonNegative(dimensions) && isFinite(dimensions) && "Invalid dimensions provided. Dimensions must be non negative and finite");
1280 const glm::vec3 position { getComputedWorldPosition() };
1281 const glm::vec3 deltaDimensions { dimensions - getDimensions() };
1282 mExtents.first += .5f * deltaDimensions;
1283 mExtents.second -= .5f * deltaDimensions;
1284 }
1285 private:
1291 void setByExtents(const Extents& axisAlignedExtents);
1292
1297 Extents mExtents {glm::vec3{0.f}, glm::vec3{0.f}};
1298 };
1299
1304 NLOHMANN_JSON_SERIALIZE_ENUM( ObjectBounds::TrueVolumeType, {
1305 {ObjectBounds::TrueVolumeType::BOX, "box"},
1306 {ObjectBounds::TrueVolumeType::SPHERE, "sphere"},
1307 {ObjectBounds::TrueVolumeType::CAPSULE, "capsule"},
1308 })
1309
1314 inline void to_json(nlohmann::json& json, const ObjectBounds& objectBounds) {
1315 json = {
1316 {"type", ObjectBounds::getComponentTypeName()},
1317 {"volume_type", objectBounds.mType},
1318 {"position_offset", { objectBounds.mPositionOffset.x, objectBounds.mPositionOffset.y, objectBounds.mPositionOffset.z}},
1319 {"orientation_offset", { objectBounds.mOrientationOffset.w, objectBounds.mOrientationOffset.x, objectBounds.mOrientationOffset.y, objectBounds.mOrientationOffset.z }},
1320 };
1321 switch(objectBounds.mType) {
1322 case ObjectBounds::TrueVolumeType::BOX:
1323 json["volume_properties"] = {
1324 {"width", objectBounds.mTrueVolume.mBox.mDimensions.x},
1325 {"height", objectBounds.mTrueVolume.mBox.mDimensions.y},
1326 {"depth", objectBounds.mTrueVolume.mBox.mDimensions.z},
1327 };
1328 break;
1329 case ObjectBounds::TrueVolumeType::SPHERE:
1330 json["volume_properties"] = {
1331 {"radius", objectBounds.mTrueVolume.mSphere.mRadius},
1332 };
1333 break;
1334 case ObjectBounds::TrueVolumeType::CAPSULE:
1335 json["volume_properties"] = {
1336 {"radius", objectBounds.mTrueVolume.mCapsule.mRadius},
1337 {"height", objectBounds.mTrueVolume.mCapsule.mHeight},
1338 };
1339 break;
1340 };
1341 }
1342
1344 inline void from_json(const nlohmann::json& json, ObjectBounds& objectBounds) {
1345 assert(json.at("type") == ObjectBounds::getComponentTypeName() && "Incorrect type property for an objectBounds component");
1346 const glm::vec3 positionOffset {
1347 json.at("position_offset")[0],
1348 json.at("position_offset")[1],
1349 json.at("position_offset")[2],
1350 };
1351 const glm::vec3 orientationOffset {
1352 glm::eulerAngles(glm::normalize(glm::quat {
1353 json.at("orientation_offset")[0],
1354 json.at("orientation_offset")[1],
1355 json.at("orientation_offset")[2],
1356 json.at("orientation_offset")[3]
1357 }))
1358 };
1359
1360 switch (static_cast<ObjectBounds::TrueVolumeType>(json.at("volume_type"))) {
1361 case ObjectBounds::TrueVolumeType::BOX:
1362 objectBounds = ObjectBounds::create(
1363 VolumeBox{ .mDimensions {
1364 json.at("volume_properties").at("width").get<float>(),
1365 json.at("volume_properties").at("height").get<float>(),
1366 json.at("volume_properties").at("depth").get<float>(),
1367 } },
1368 positionOffset,
1369 orientationOffset
1370 );
1371 break;
1372
1373 case ObjectBounds::TrueVolumeType::SPHERE:
1374 objectBounds = ObjectBounds::create(
1375 VolumeSphere { .mRadius { json.at("volume_properties").at("radius").get<float>() }},
1376 positionOffset,
1377 orientationOffset
1378 );
1379 break;
1380
1381 case ObjectBounds::TrueVolumeType::CAPSULE:
1382 objectBounds = ObjectBounds::create(
1383 VolumeCapsule {
1384 .mHeight { json.at("volume_properties").at("height").get<float>() },
1385 .mRadius { json.at("volume_properties").at("radius").get<float>() },
1386 },
1387 positionOffset,
1388 orientationOffset
1389 );
1390 break;
1391 }
1392 }
1393
1395 inline void to_json(nlohmann::json& json, const AxisAlignedBounds& axisAlignedBounds) { /* never used, so pass */
1396 (void)json; // prevent unused parameter warnings
1397 (void)axisAlignedBounds; // prevent unused parameter warnings
1398 }
1399
1401 inline void from_json(const nlohmann::json& json, AxisAlignedBounds& objectBounds) { /* never used, so pass */
1402 (void)json; // prevent unused parameter warnings
1403 (void)objectBounds; // prevent unused parameter warnings
1404 }
1405}
1406
1407#endif
std::array< AreaTriangle, 12 > getAxisAlignedBoxFaceTriangles() const
Gets an array of triangles in the world which make up the surface of this box.
Definition types.hpp:1203
void setPosition(const glm::vec3 &position)
Sets the position of this box.
Definition types.hpp:1266
void setDimensions(const glm::vec3 &dimensions)
Sets the dimensions of this box.
Definition types.hpp:1278
AxisAlignedBounds(const glm::vec3 &position, const glm::vec3 &dimensions)
Constructs a new Axis Aligned Bounds object based on the position of the origin and the dimensions of...
Definition types.hpp:1179
std::pair< glm::vec3, glm::vec3 > Extents
Pair where first: right top front corner; second: left back bottom corner of an AABB.
Definition types.hpp:1151
glm::vec3 getDimensions() const
Gets the dimensions of this box.
Definition types.hpp:1217
Extents mExtents
The pair of coordinates at the extreme corners of this box (i.e., the top-right-front and bottom-left...
Definition types.hpp:1297
std::array< glm::vec3, 8 > getAxisAlignedBoxCorners() const
Gets an array of coordinates of the corners of this box.
Definition types.cpp:333
glm::vec3 getComputedWorldPosition() const
Gets the coordinates of the center of this box.
Definition types.hpp:1224
AxisAlignedBounds()
Constructs a new empty Axis Aligned Bounds object.
Definition types.cpp:313
bool isSensible() const
Tests whether this box is sensible (it has a finite position, and finite non-negative dimensions).
Definition types.hpp:1232
bool isPositiveStrict() const
Tests whether this box has strictly positive parameters and hence encloses some region in space.
Definition types.hpp:1255
static std::string getComponentTypeName()
Gets the component type string for this object.
Definition types.hpp:1145
AreaTriangle getClosestTriangle() const
Returns the closest polytope triangle.
Definition types.cpp:88
AreaTriangle getClosestTriangleSupportB() const
Gets the points of shape B that were responsible for generating the closest triangle of the polytope.
Definition types.cpp:106
bool append(const glm::vec3 &newPoint, const glm::vec3 &supportA, const glm::vec3 &supportB)
Appends a new point, replacing the topmost triangle in the polygon with 3 more triangles including th...
Definition types.cpp:138
std::size_t getNumFaces() const
Definition types.hpp:773
std::vector< glm::vec3 > mPointsSupportA
List of points representing support point A, where each point corresponds to the polytope point it ge...
Definition types.hpp:737
glm::vec3 getClosestPoint() const
Returns the closest point to the origin on the triangle face closest to the origin.
Definition types.cpp:74
AreaTriangle getClosestTriangleSupportA() const
Gets the points of shape A that were responsible for generating the closest triangle of the polytope.
Definition types.cpp:97
Polytope()
Definition types.cpp:115
glm::vec3 getClosestTriangleNormal() const
Returns the direction to the closest point on the polytope's surface from the origin.
Definition types.cpp:80
std::vector< glm::vec3 > mPointsSupportB
List of points representing support point B, where each point corresponds to the polytope point it ge...
Definition types.hpp:743
glm::vec3 getNextSearch() const
Returns the next search direction for a point to add to the polytope.
Definition types.cpp:63
std::priority_queue< Face, std::vector< Face >, std::function< bool(const Face &, const Face &)> > mFaces
The list of triangle faces representing this polytope.
Definition types.hpp:727
std::vector< glm::vec3 > mPoints
List of points representing this polytope.
Definition types.hpp:732
ToyMaker Engine's implementation of an ECS system.
bool isPositiveStrict(float number)
Tests whether a number is strictly positive.
Definition types.hpp:80
bool isPositiveStrict() const
Checks whether underlying bounds is non-trivial, as in each important parameter that represents the v...
Definition types.cpp:18
uint8_t BoxCorner
Type used to represent the name of the corner of a box.
Definition types.hpp:35
BoxCornerSpecifier
Enum values correspond to bits on a BoxCorner which help specify which side of the box on each axis i...
Definition types.hpp:42
bool isNonNegative(float number)
Tests whether a number is non-negative.
Definition types.hpp:103
std::array< AreaTriangle, 12 > computeBoxFaceTriangles(const std::array< glm::vec3, 8 > &boxCorners)
Generates a list of triangles making up the surface of a box situated somewhere in the world,...
Definition types.cpp:442
bool isFinite(float number)
Tests whether a given number is finite.
Definition types.hpp:57
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:24
A set of numbers representing a single circle situated somewhere in the world.
Definition types.hpp:455
glm::vec3 mCenter
The real-world coordinates of the center of the circle.
Definition types.hpp:466
glm::vec3 mNormal
A vector normal to the surface of the circle, in whose direction it may be assumed the circle is faci...
Definition types.hpp:472
bool isSensible() const
Tests whether the circle described by these parameters is valid (as opposed to invalid or infinite).
Definition types.hpp:480
bool isPositiveStrict() const
Tests whether the circle's parameters are strictly positive, and hence whether the circle encloses so...
Definition types.hpp:499
float mRadius
The radius of the circle.
Definition types.hpp:460
A set of 3 points located in the world forming a (hopefully sensible) triangle.
Definition types.hpp:392
std::array< glm::vec3, 3 > mPoints
The points of the triangle, where each point has 3 components.
Definition types.hpp:397
bool isPositiveStrict() const
Tests whether the points of this triangle encapsulate some area in space.
Definition types.hpp:426
bool isSensible() const
Tests whether the points describing the triangle are sensible (as opposed to invalid or infinite).
Definition types.hpp:405
Data representing everything about a collision.
Definition types.hpp:888
Contact mContactA
Contact information relative to the first collision shape.
Definition types.hpp:899
Contact mContactB
Contact information relative to the second collision shape.
Definition types.hpp:905
bool mCollided
Whether a collision occurred.
Definition types.hpp:893
Object representing contact information between a pair of convex shapes from the perspective of one o...
Definition types.hpp:843
float mPenetrationDepth
The length by which to move this object in the direction of the contact normal to separate the collid...
Definition types.hpp:874
glm::vec3 mTangent1
Worldspace tangent orthogonal to the contact normal and the other contact tangent.
Definition types.hpp:861
glm::vec3 mNormal
Worldspace normal pointing inward from the surface of this shape such that moving in this direction b...
Definition types.hpp:855
glm::vec3 mPoint
The worldspace point on the surface of this shape that made contact with the other shape.
Definition types.hpp:848
glm::vec3 mTangent2
Worldspace tangent orthogonal to the contact normal and the other contact tangent.
Definition types.hpp:867
A component defining the true bounds of a spatially queryable object situated somewhere in the world.
Definition types.hpp:917
glm::quat getComputedWorldOrientation() const
The final orientation of the object bounds in the world.
Definition types.cpp:224
TrueVolume mTrueVolume
The data defining the volume itself, independent of its position.
Definition types.hpp:994
bool isSensible() const
Returns whether the underlying volume has sensible parameters (i.e., finite, non-degenerate,...
Definition types.cpp:244
static std::string getComponentTypeName()
Fetches the component type string associated with this class.
Definition types.hpp:923
glm::vec3 getComputedWorldPosition() const
The final position of the origin of the object bounds in the world.
Definition types.cpp:221
std::pair< float, float > getProjectionAlong(const glm::vec3 &axis) const
Returns this shape's projection along some unit vector.
Definition types.cpp:271
static ObjectBounds create(const VolumeBox &box, const glm::vec3 &positionOffset, const glm::quat &orientationOffset)
Creates bounds for an object in the shape of a box.
Definition types.cpp:36
std::array< glm::vec3, 8 > getLocalOrientedBoxCorners() const
Gets the corners of the box just encapsulating this object's true volume and sharing its position and...
Definition types.cpp:228
std::array< glm::vec3, 8 > getWorldOrientedBoxCorners() const
Gets the corners of the box just encapsulating this object's true volume relative to the origin of th...
Definition types.cpp:236
TrueVolumeType mType
Value indicating the type of the volume represented by this object.
Definition types.hpp:988
void applyModelMatrix(const glm::mat4 &modelMatrix)
Computes new mPosition and mOrientation offsets based on (presumably) the model transform of the unde...
Definition types.cpp:202
glm::quat mOrientation
The orientation in the real world of the scene node this bounds component is attached to.
Definition types.hpp:1012
glm::vec3 mPosition
The position, in the real world, of the scene node this data is attached to.
Definition types.hpp:1000
std::array< AreaTriangle, 12 > getWorldOrientedBoxFaceTriangles() const
Gets an array of triangles that make up the faces of the bounds-aligned box corners in world space.
Definition types.hpp:1089
glm::vec3 getSupportAlong(const glm::vec3 &axis) const
Returns the point on this object's surface furthest along a given axis from the origin of this object...
Definition types.cpp:289
glm::vec3 mPositionOffset
The position of the origin of the spatial query volume relative to the origin of the node it is attac...
Definition types.hpp:1006
glm::mat3 getWorldRotationTransform() const
Gets the rotation matrix associated with the underlying scene object's orientation,...
Definition types.hpp:1042
glm::mat3 getLocalRotationTransform() const
Gets the rotation matrix associated with this object's orientation offset.
Definition types.hpp:1033
glm::quat mOrientationOffset
The transformation mapping forward as known by the underlying scene node, to forward as known by the ...
Definition types.hpp:1019
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets the corners of the box just encapsulating this object's true volume, relative to the origin of t...
Definition types.cpp:207
TrueVolumeType
The types of volumes supported by the engine.
Definition types.hpp:929
A set of numbers describing a plane situated somewhere in the world.
Definition types.hpp:564
bool isPositiveStrict() const
Same as Plane::isSensible().
Definition types.hpp:601
glm::vec3 mNormal
A vector normal to the plane.
Definition types.hpp:575
glm::vec3 mPointOnPlane
A known point on the plane.
Definition types.hpp:569
bool isSensible() const
Tests whether the plane described is sensible (as opposed to invalid, infinite, or degenerate).
Definition types.hpp:583
Stores the indices of a single face of this polytope.
Definition types.hpp:713
A set of numbers describing a ray with its source at some finite point in the world,...
Definition types.hpp:511
float mLength
The length of the ray, infinite by default.
Definition types.hpp:528
glm::vec3 mStart
A point representing the starting point of the ray.
Definition types.hpp:516
glm::vec3 mDirection
The direction the ray is pointing in.
Definition types.hpp:522
bool isPositiveStrict() const
Tests whether the ray actually travels any distance from its origin.
Definition types.hpp:554
bool isSensible() const
Tests whether the ray is sensible (as opposed to invalid).
Definition types.hpp:536
Primitive for GJK algorithm.
Definition types.hpp:613
std::array< glm::vec3, 4 > mPointsSupportA
The point on the LHS of the Minkowski difference, where each index corresponds to a point on mPoints.
Definition types.hpp:625
std::array< glm::vec3, 4 > mPointsSupportB
The point on the RHS of the Minkowski difference, where each index corresponds to a point on mPoints.
Definition types.hpp:631
std::pair< bool, glm::vec3 > evaluate()
Tries to find a 3-simplex that encloses the origin.
Definition types.cpp:581
bool append(const glm::vec3 &candidatePoint, const glm::vec3 &supportA, const glm::vec3 &supportB)
Adds a new point to the simplex.
Definition types.hpp:645
uint8_t mNPoints
The number of points in this simplex.
Definition types.hpp:637
void reorder(const std::vector< uint8_t > reorderedIndices)
Replaces the current simplex with points from a new list (which will usually have as many or fewer po...
Definition types.hpp:669
std::array< glm::vec3, 4 > mPoints
Points representing the simplex, derived by finding the Minksowski difference of support points on tw...
Definition types.hpp:619
The base class of all spatial query volumes.
Definition types.hpp:131
bool isSensible() const
Returns whether or not the derived volume has sensible parameters (i.e., isn't infinite or invalid).
Definition types.hpp:191
static std::array< glm::vec3, 8 > ComputeBoxCorners(const glm::vec3 &boxDimensions)
Computes the model relative corners of a box, given the dimensions of the box.
Definition types.hpp:156
static constexpr std::array< glm::vec3, 8 > GetCornerSignsArray()
Returns an array populated with axis-wise sign multipliers, where the positions on the array correspo...
Definition types.hpp:140
bool isPositiveStrict() const
Returns whether or not the derived volume has strictly positive parameters.
Definition types.hpp:204
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets corners of the object-relative bounding box that encapsulates the derived volume.
Definition types.hpp:176
Holds the parameters describing the spatial query volume of a simple three-dimensionsal box.
Definition types.hpp:248
bool isSensible() const
Tests whether the values representing the box are valid (as opposed to invalid or infinite).
Definition types.hpp:270
glm::vec3 mDimensions
The dimensions of the box, its width, height, and depth.
Definition types.hpp:253
bool isPositiveStrict() const
Tests whether the values representing the box are strictly positive.
Definition types.hpp:280
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Returns an array of coordinates corresponding to the corners of the box.
Definition types.hpp:260
Holds the parameters describing the spatial query volume of a simple three-dimensionsal capsule (or p...
Definition types.hpp:290
float mRadius
The radius of the hemispheres on either end of the capsule.
Definition types.hpp:301
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets an array containing the coordinates of the corners of the volume aligned box just containing the...
Definition types.hpp:308
float mHeight
The height of the cylindrical section of the capsule.
Definition types.hpp:295
bool isPositiveStrict() const
Tests whether the values representing the capsule are all strictly positive.
Definition types.hpp:335
bool isSensible() const
Tests whether the values representing the capsule make sense (as opposed to being invalid or infinite...
Definition types.hpp:321
Holds parameters describing a spherical spatial query volume.
Definition types.hpp:349
float mRadius
The radius of the sphere.
Definition types.hpp:354
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets an array of coordinates of corners of a box just encapsulating the sphere.
Definition types.hpp:361
bool isPositiveStrict() const
Tests whether this volume's parameters are strictly positive.
Definition types.hpp:382
bool isSensible() const
Tests whether this volume's parameters are sensible (as opposed to invalid or infinite).
Definition types.hpp:371
Definition types.hpp:211
bool isPositiveStrict() const
Poor man's vtable cont'd.
Definition types.hpp:238
bool isSensible() const
Poor man's vtable cont'd.
Definition types.hpp:228
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Poor man's vtable cont'd.
Definition types.hpp:218
A union of supported volume structs.
Definition types.hpp:939