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
10
11#ifndef TOYMAKERENGINE_SPATIALQUERYTYPES_H
12#define TOYMAKERENGINE_SPATIALQUERYTYPES_H
13
14#include <array>
15#include <queue>
16
17#include <glm/glm.hpp>
18#include <glm/gtc/quaternion.hpp>
19#include <nlohmann/json.hpp>
20#include <string>
21
22#include "../util.hpp"
23
24namespace ToyMaker {
25 struct AreaTriangle;
26
27
33 using BoxCorner = uint8_t;
34
41 RIGHT=0x1,
42 TOP=0x2,
43 FRONT=0x4
44 };
45
46
47
48 template <typename TDerived>
49 struct Volume;
50
57 using InteractionLayerMask = uint16_t;
58
66 struct VolumeBase_ {
75 inline static constexpr std::array<glm::vec3, 8> GetCornerSignsArray() {
76 std::array<glm::vec3, 8> cornerSigns {};
77 for(BoxCorner corner {0}; corner < 8; ++corner) {
78 cornerSigns[corner].x = corner&BoxCornerSpecifier::RIGHT? 1.f: -1.f;
79 cornerSigns[corner].y = corner&BoxCornerSpecifier::TOP? 1.f: -1.f;
80 cornerSigns[corner].z = corner&BoxCornerSpecifier::FRONT? 1.f: -1.f;
81 }
82 return cornerSigns;
83 }
84
91 inline static std::array<glm::vec3, 8> ComputeBoxCorners(const glm::vec3& boxDimensions) {
92 const std::array<glm::vec3, 8> cornerSignsArray { GetCornerSignsArray() };
93 glm::vec3 absoluteCornerOffset { .5f * boxDimensions };
94 std::array<glm::vec3, 8> cornerArray { .5f * boxDimensions };
95 for(uint8_t corner{0}; corner < 8; ++corner) {
96 cornerArray[corner] = cornerSignsArray[corner] * absoluteCornerOffset;
97 }
98 return cornerArray;
99 }
100
110 template <typename TDerived>
111 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const {
113 }
114
125 template <typename TDerived>
126 inline bool isSensible() const {
128 }
129
138 template <typename TDerived>
139 inline bool isPositiveStrict() const {
141 }
142 };
143
145 template <typename TDerived>
146 struct Volume: public VolumeBase_ {
153 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const {
154 return TDerived::getVolumeRelativeBoxCorners();
155 }
156
163 inline bool isSensible() const {
164 return TDerived::isSensible();
165 }
166
173 inline bool isPositiveStrict() const {
174 return TDerived::isPositiveStrict();
175 }
176 };
177
183 struct VolumeBox: public Volume<VolumeBox> {
188 glm::vec3 mDimensions {0.f, 0.f, 0.f};
189
195 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
197 }
198
205 inline bool isSensible() const {
207 }
208
215 inline bool isPositiveStrict() const {
217 }
218 };
219
225 struct VolumeCapsule: public Volume<VolumeCapsule> {
230 float mHeight {0.f};
231
236 float mRadius {0.f};
237
243 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
244 const glm::vec3 boxDimensions { 2.f*mRadius, mHeight + 2.f*mRadius, 2.f*mRadius};
245 return ComputeBoxCorners(boxDimensions);
246 }
247
256 inline bool isSensible() const {
257 return (
260 );
261 }
262
270 inline bool isPositiveStrict() const {
271 return (
273 // You can still have a capsule which occupies space even if its
274 // spine is length 0, so no test for mHeight
275 );
276 }
277 };
278
284 struct VolumeSphere: public Volume<VolumeSphere> {
289 float mRadius {0.f};
290
296 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
297 return ComputeBoxCorners(glm::vec3{2*mRadius});
298 }
299
306 inline bool isSensible() const {
308 }
309
317 inline bool isPositiveStrict() const {
319 }
320 };
321
332 std::array<glm::vec3, 3> mPoints {};
333
341 inline bool isSensible() const {
342 return (
343 (
345 ) && (
347 glm::length(glm::cross(
348 mPoints[2] - mPoints[0], mPoints[1] - mPoints[0]
349 ))
350 )
351 )
352 );
353 }
354
362 inline bool isPositiveStrict() const {
363 return (
365 glm::length(
366 glm::cross(
367 mPoints[2] - mPoints[0], mPoints[1] - mPoints[0]
368 )
369 )
370 )
371 );
372 }
373 };
374
384 std::array<AreaTriangle, 12> computeBoxFaceTriangles(const std::array<glm::vec3, 8>& boxCorners);
385
391 struct AreaCircle {
396 float mRadius { 0.f };
397
402 glm::vec3 mCenter { 0.f };
403
408 glm::vec3 mNormal { 0.f, -1.f, 0.f };
409
416 inline bool isSensible() const {
417 return (
418 (
420 ) && (
422 ) && (
424 )
425 );
426 }
427
435 inline bool isPositiveStrict() const {
436 return (
438 );
439 }
440 };
441
447 struct Ray {
452 glm::vec3 mStart { 0.f };
453
458 glm::vec3 mDirection { 0.f, 0.f, -1.f };
459
464 float mLength { std::numeric_limits<float>::infinity() };
465
472 inline bool isSensible() const {
473 return (
474 (
476 ) && (
478 ) && (
480 )
481 );
482 }
483
490 inline bool isPositiveStrict() const {
492 }
493 };
494
500 struct Plane {
505 glm::vec3 mPointOnPlane { 0.f };
506
511 glm::vec3 mNormal { 0.f, 0.f, -1.f };
512
519 inline bool isSensible() const {
520 return (
521 (
523 ) && (
525 )
526 );
527 }
528
537 inline bool isPositiveStrict() const {
538 return isSensible();
539 }
540 };
541
549 struct Simplex {
555 std::array<glm::vec3, 4> mPoints;
556
561 std::array<glm::vec3, 4> mPointsSupportA;
562
567 std::array<glm::vec3, 4> mPointsSupportB;
568
573 uint8_t mNPoints { 0 };
574
581 inline bool append(const glm::vec3& candidatePoint, const glm::vec3& supportA, const glm::vec3& supportB) {
582 assert(mNPoints < 4 && "We already have 4 (or more) points, there's no more needed");
583 assert(supportA - supportB == candidatePoint && "The difference in supports should yield the candidate point");
584
585 mPoints[mNPoints] = candidatePoint;
586 mPointsSupportA[mNPoints] = supportA;
587 mPointsSupportB[mNPoints] = supportB;
588 ++mNPoints;
589
590 return true;
591 }
592
597 inline void reorder(const std::vector<uint8_t> reorderedIndices) {
598 assert(reorderedIndices.size() <= 4 && "Invalid point list provided");
599 const std::array<glm::vec3, 4> oldPoints { mPoints };
600 const std::array<glm::vec3, 4> oldPointsSupportA { mPointsSupportA };
601 const std::array<glm::vec3, 4> oldPointsSupportB { mPointsSupportB };
602 mNPoints = 0;
603 for(const auto& index: reorderedIndices) {
604 const bool pointAddedSuccessfully{ append(oldPoints[index], oldPointsSupportA[index], oldPointsSupportB[index]) };
605 assert(pointAddedSuccessfully && "Invalid point list provided");
606 }
607 }
608
620 std::pair<bool, glm::vec3> evaluate();
621
622 private:
623 std::pair<bool, glm::vec3> doSimplex4();
624 glm::vec3 doSimplex3();
625 glm::vec3 doSimplex2();
626 };
627
636 class Polytope {
637 private:
641 struct Face {
642 std::array<uint16_t, 3> mIndices {};
643 };
644
648 Polytope();
649
650
655 std::priority_queue<Face, std::vector<Face>, std::function<bool(const Face&, const Face&)>> mFaces;
656
660 std::vector<glm::vec3> mPoints {};
665 std::vector<glm::vec3> mPointsSupportA {};
666
671 std::vector<glm::vec3> mPointsSupportB {};
672
673 inline glm::vec3 getTriangleCross(const Face& face) const {
674 return glm::cross(
675 mPoints[face.mIndices[1]] - mPoints[face.mIndices[0]],
676 mPoints[face.mIndices[2]] - mPoints[face.mIndices[0]]
677 );
678 }
679
680 inline glm::vec3 getTriangleNorm(const Face& face) const {
681 return glm::normalize(getTriangleCross(face));
682 }
683
684 public:
690 Polytope(const Simplex& simplex);
691
696 glm::vec3 getNextSearch() const;
697
701 std::size_t getNumFaces() const {
702 return mFaces.size();
703 }
704
705 std::size_t getNumPoints() const {
706 return mPoints.size();
707 }
708
714 glm::vec3 getClosestPoint() const;
715
723 glm::vec3 getClosestTriangleNormal() const;
724
732 AreaTriangle getClosestTriangle() const;
733
739 AreaTriangle getClosestTriangleSupportA() const;
740
746 AreaTriangle getClosestTriangleSupportB() const;
747
760 bool append(const glm::vec3& newPoint, const glm::vec3& supportA, const glm::vec3& supportB);
761 };
762
771 struct Contact {
776 glm::vec3 mPoint;
777
783 glm::vec3 mNormal;
784
789 glm::vec3 mTangent1;
790
795 glm::vec3 mTangent2;
796
803 };
804
835
851 inline static std::string getComponentTypeName() { return "ObjectBounds"; }
852
857 enum class TrueVolumeType: uint8_t {
858 BOX=0,
859 SPHERE,
860 CAPSULE,
861 };
862
868 VolumeBox mBox { .mDimensions{ glm::vec3{0.f} } };
869 VolumeCapsule mCapsule;
870 VolumeSphere mSphere;
871 };
872
886 static ObjectBounds create(
887 const VolumeBox& box,
888 const glm::vec3& positionOffset,
889 const glm::quat& orientationOffset,
890 InteractionLayerMask interactionLayers=0x1,
891 InteractionLayerMask interactionMask=std::numeric_limits<InteractionLayerMask>::max()
892 );
893
907 static ObjectBounds create(
908 const VolumeCapsule& capsule,
909 const glm::vec3& positionOffset,
910 const glm::quat& orientationOffset,
911 InteractionLayerMask interactionLayers=0x1,
912 InteractionLayerMask interactionMask=std::numeric_limits<InteractionLayerMask>::max()
913 );
914
928 static ObjectBounds create(
929 const VolumeSphere& sphere,
930 const glm::vec3& positionOffset,
931 const glm::quat& orientationOffset,
932 InteractionLayerMask interactionLayers=0x1,
933 InteractionLayerMask interactionMask=std::numeric_limits<InteractionLayerMask>::max()
934 );
935
940 TrueVolumeType mType { TrueVolumeType::BOX };
941
947
952 glm::vec3 mPositionWorld { 0.f };
953
958 glm::vec3 mPositionOrigin { 0.f };
959
964 glm::vec3 mPositionOffset { 0.f };
965
970 glm::quat mOrientationWorld { glm::vec3 { 0.f } };
971
976 glm::quat mOrientationOrigin { glm::vec3{ 0.f } };
977
982 glm::quat mOrientationOffset { glm::vec3{ 0.f } };
983
989
994 InteractionLayerMask mInteractionMask { std::numeric_limits<InteractionLayerMask>::max() };
995
1001
1008
1021
1030
1037
1043 void applyModelMatrix(const glm::mat4& modelMatrix);
1044
1050 inline glm::mat3 getRotationTransformLocal() const {
1051 return glm::mat3_cast(glm::normalize(mOrientationOffset));
1052 }
1053
1059 inline glm::mat4 getRotationTransformOrigin() const {
1060 return glm::mat4_cast(glm::normalize(mOrientationOrigin));
1061 }
1062
1068 inline glm::mat4 getTranslationTransformOrigin() const {
1069 return glm::mat4 {
1070 { 1.f, 0.f, 0.f, 0.f },
1071 { 0.f, 1.f, 0.f, 0.f },
1072 { 0.f, 0.f, 1.f, 0.f },
1073 { mPositionOrigin, 1.f },
1074 };
1075 }
1076
1082 glm::vec3 getPositionWorld() const;
1083
1092 void setPositionWorld(const glm::vec3& newPosition);
1093
1100 void setPositionOffset(const glm::vec3& newPosition);
1101
1108 void setPositionOrigin(const glm::vec3& newPosition);
1109
1115
1124 glm::quat getOrientationWorld() const;
1125
1136 void setOrientationWorld(const glm::quat& newOrientation);
1137
1143 void setOrientationOffset(const glm::quat& newOrientation);
1144
1150 void setOrientationOrigin(const glm::quat& newOrientation);
1151
1157 std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const;
1158
1165 std::array<glm::vec3, 8> getLocalOrientedBoxCorners() const;
1166
1172 std::array<glm::vec3, 8> getWorldOrientedBoxCorners() const;
1173
1183
1188 std::pair<TrueVolumeType, TrueVolume> getVolume() const {
1189 return { mType, mTrueVolume };
1190 }
1191
1196 inline void setVolume(TrueVolumeType type, const TrueVolume& volume) {
1197 mType = type;
1198 mTrueVolume = volume;
1200 }
1201
1206 inline void setVolumeBox(const glm::vec3& boxDimensions) {
1207 assert(
1208 isNonNegative(boxDimensions) && isFinite(boxDimensions)
1209 && "Invalid box parameters provided"
1210 );
1211 setVolume(TrueVolumeType::BOX,
1212 TrueVolume { .mBox { .mDimensions { boxDimensions } } }
1213 );
1214 }
1215
1220 inline void setVolumeCapsule(float radius, float height) {
1221 assert(
1222 isNonNegative(radius) && isNonNegative(height) && isFinite(radius) && isFinite(height)
1223 && "Invalid capsule parameters provided"
1224 );
1225 setVolume(TrueVolumeType::CAPSULE,
1226 TrueVolume {
1227 .mCapsule { .mHeight { height }, .mRadius { radius } }
1228 }
1229 );
1230 }
1231
1236 inline void setVolumeSphere(float radius) {
1237 assert(
1238 isNonNegative(radius) && isFinite(radius)
1239 && "Invalid sphere parameters provided"
1240 );
1241 setVolume(TrueVolumeType::SPHERE,
1242 TrueVolume {
1243 .mSphere { .mRadius { radius } }
1244 }
1245 );
1246 }
1247
1258 glm::vec3 getSupportAlong(const glm::vec3& axis) const;
1259
1266 std::pair<float, float> getProjectionAlong(const glm::vec3& axis) const;
1267
1273 bool isSensible() const;
1274
1280 bool isPositiveStrict() const;
1281
1288
1294 inline void setInteractionLayers(InteractionLayerMask newLayers) { mInteractionLayers = newLayers; }
1295
1302
1309 };
1310
1323 public:
1329 inline static std::string getComponentTypeName() { return "AxisAlignedBounds"; }
1330
1335 using Extents = std::pair<glm::vec3, glm::vec3>;
1336
1342
1348 AxisAlignedBounds(const ObjectBounds& objectBounds);
1349
1356 AxisAlignedBounds(const Extents& axisAlignedExtents, InteractionLayerMask interactionLayers=0x0);
1357
1364 AxisAlignedBounds(const glm::vec3& position, const glm::vec3& dimensions, InteractionLayerMask interactionLayers=0x0):
1365 AxisAlignedBounds { Extents{{position + .5f*dimensions}, {position - .5f*dimensions}}, interactionLayers }
1366 {}
1367
1374 AxisAlignedBounds operator+(const AxisAlignedBounds& other) const;
1375
1381 std::array<glm::vec3, 8> getAxisAlignedBoxCorners() const;
1382
1388 inline std::array<AreaTriangle, 12> getAxisAlignedBoxFaceTriangles() const { return computeBoxFaceTriangles(getAxisAlignedBoxCorners()); }
1389
1395 Extents getAxisAlignedBoxExtents() const;
1396
1402 inline glm::vec3 getDimensions() const { return mExtents.first - mExtents.second; }
1403
1409 inline glm::vec3 getPositionWorld() const { return mExtents.second + .5f * getDimensions(); }
1410
1417 inline bool isSensible() const {
1418 return (
1419 isFinite(mExtents.first) && isFinite(mExtents.second)
1420 && isNonNegative(mExtents.first - mExtents.second)
1421 );
1422 }
1423
1432 glm::vec3 getSupportAlong(const glm::vec3& axis) const;
1433
1440 inline bool isPositiveStrict() const {
1441 return (
1443 );
1444 }
1445
1452
1458 inline void setInteractionLayers(InteractionLayerMask newLayers) { mInteractionLayers = newLayers; }
1459
1465 inline void setPosition(const glm::vec3& position) {
1466 assert(isFinite(position) && "Invalid position specified. Position must be finite");
1467 const glm::vec3 deltaPosition { position - getPositionWorld() };
1468 mExtents.first += deltaPosition;
1469 mExtents.second += deltaPosition;
1470 }
1471
1477 inline void setDimensions(const glm::vec3& dimensions) {
1478 assert(isNonNegative(dimensions) && isFinite(dimensions) && "Invalid dimensions provided. Dimensions must be non negative and finite");
1479 const glm::vec3 position { getPositionWorld() };
1480 const glm::vec3 deltaDimensions { dimensions - getDimensions() };
1481 mExtents.first += .5f * deltaDimensions;
1482 mExtents.second -= .5f * deltaDimensions;
1483 }
1484 private:
1490 void setByExtents(const Extents& axisAlignedExtents);
1491
1496 Extents mExtents {glm::vec3{0.f}, glm::vec3{0.f}};
1497
1503 };
1504
1509 NLOHMANN_JSON_SERIALIZE_ENUM( ObjectBounds::TrueVolumeType, {
1510 {ObjectBounds::TrueVolumeType::BOX, "box"},
1511 {ObjectBounds::TrueVolumeType::SPHERE, "sphere"},
1512 {ObjectBounds::TrueVolumeType::CAPSULE, "capsule"},
1513 })
1514
1519 inline void to_json(nlohmann::json& json, const ObjectBounds& objectBounds) {
1520 json = {
1521 {"type", ObjectBounds::getComponentTypeName()},
1522 {"volume_type", objectBounds.mType},
1523 {"position_offset", { objectBounds.mPositionOffset.x, objectBounds.mPositionOffset.y, objectBounds.mPositionOffset.z}},
1524 {"orientation_offset", { objectBounds.mOrientationOffset.w, objectBounds.mOrientationOffset.x, objectBounds.mOrientationOffset.y, objectBounds.mOrientationOffset.z }},
1525 };
1526 switch(objectBounds.mType) {
1527 case ObjectBounds::TrueVolumeType::BOX:
1528 json["volume_properties"] = {
1529 {"width", objectBounds.mTrueVolume.mBox.mDimensions.x},
1530 {"height", objectBounds.mTrueVolume.mBox.mDimensions.y},
1531 {"depth", objectBounds.mTrueVolume.mBox.mDimensions.z},
1532 };
1533 break;
1534 case ObjectBounds::TrueVolumeType::SPHERE:
1535 json["volume_properties"] = {
1536 {"radius", objectBounds.mTrueVolume.mSphere.mRadius},
1537 };
1538 break;
1539 case ObjectBounds::TrueVolumeType::CAPSULE:
1540 json["volume_properties"] = {
1541 {"radius", objectBounds.mTrueVolume.mCapsule.mRadius},
1542 {"height", objectBounds.mTrueVolume.mCapsule.mHeight},
1543 };
1544 break;
1545 };
1546 }
1547
1549 inline void from_json(const nlohmann::json& json, ObjectBounds& objectBounds) {
1550 assert(json.at("type") == ObjectBounds::getComponentTypeName() && "Incorrect type property for an objectBounds component");
1551 const glm::vec3 positionOffset {
1552 json.at("position_offset")[0],
1553 json.at("position_offset")[1],
1554 json.at("position_offset")[2],
1555 };
1556 const glm::vec3 orientationOffset {
1557 glm::eulerAngles(glm::normalize(glm::quat {
1558 json.at("orientation_offset")[0],
1559 json.at("orientation_offset")[1],
1560 json.at("orientation_offset")[2],
1561 json.at("orientation_offset")[3]
1562 }))
1563 };
1564 const InteractionLayerMask interactionLayers { json.at("interaction_layers").get<InteractionLayerMask>() };
1565 const InteractionLayerMask interactionMask { json.at("interaction_mask").get<InteractionLayerMask>() };
1566
1567 switch (static_cast<ObjectBounds::TrueVolumeType>(json.at("volume_type"))) {
1568 case ObjectBounds::TrueVolumeType::BOX:
1569 objectBounds = ObjectBounds::create(
1570 VolumeBox{ .mDimensions {
1571 json.at("volume_properties").at("width").get<float>(),
1572 json.at("volume_properties").at("height").get<float>(),
1573 json.at("volume_properties").at("depth").get<float>(),
1574 } },
1575 positionOffset,
1576 orientationOffset,
1577 interactionLayers,
1578 interactionMask
1579 );
1580 break;
1581
1582 case ObjectBounds::TrueVolumeType::SPHERE:
1583 objectBounds = ObjectBounds::create(
1584 VolumeSphere { .mRadius { json.at("volume_properties").at("radius").get<float>() } },
1585 positionOffset,
1586 orientationOffset,
1587 interactionLayers,
1588 interactionMask
1589 );
1590 break;
1591
1592 case ObjectBounds::TrueVolumeType::CAPSULE:
1593 objectBounds = ObjectBounds::create(
1594 VolumeCapsule {
1595 .mHeight { json.at("volume_properties").at("height").get<float>() },
1596 .mRadius { json.at("volume_properties").at("radius").get<float>() },
1597 },
1598 positionOffset,
1599 orientationOffset,
1600 interactionLayers,
1601 interactionMask
1602 );
1603 break;
1604 }
1605 objectBounds.mVolumeSystemComputed = false;
1606 }
1607
1609 inline void to_json(nlohmann::json& json, const AxisAlignedBounds& axisAlignedBounds) { /* never used, so pass */
1610 (void)json; // prevent unused parameter warnings
1611 (void)axisAlignedBounds; // prevent unused parameter warnings
1612 }
1613
1615 inline void from_json(const nlohmann::json& json, AxisAlignedBounds& objectBounds) { /* never used, so pass */
1616 (void)json; // prevent unused parameter warnings
1617 (void)objectBounds; // prevent unused parameter warnings
1618 }
1619}
1620
1621#endif
1622
glm::vec3 getPositionWorld() const
Gets the coordinates of the center of this box.
Definition types.hpp:1409
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:1388
void setPosition(const glm::vec3 &position)
Sets the position of this box.
Definition types.hpp:1465
void setDimensions(const glm::vec3 &dimensions)
Sets the dimensions of this box.
Definition types.hpp:1477
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:1335
InteractionLayerMask mInteractionLayers
Determines which spatial queries and collisions this object participates in.
Definition types.hpp:1502
glm::vec3 getDimensions() const
Gets the dimensions of this box.
Definition types.hpp:1402
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:1496
std::array< glm::vec3, 8 > getAxisAlignedBoxCorners() const
Gets an array of coordinates of the corners of this box.
Definition types.cpp:417
AxisAlignedBounds()
Constructs a new empty Axis Aligned Bounds object.
Definition types.cpp:395
bool isSensible() const
Tests whether this box is sensible (it has a finite position, and finite non-negative dimensions).
Definition types.hpp:1417
bool isPositiveStrict() const
Tests whether this box has strictly positive parameters and hence encloses some region in space.
Definition types.hpp:1440
AxisAlignedBounds(const glm::vec3 &position, const glm::vec3 &dimensions, InteractionLayerMask interactionLayers=0x0)
Constructs a new Axis Aligned Bounds object based on the position of the origin and the dimensions of...
Definition types.hpp:1364
static std::string getComponentTypeName()
Gets the component type string for this object.
Definition types.hpp:1329
AreaTriangle getClosestTriangle() const
Returns the closest polytope triangle.
Definition types.cpp:105
AreaTriangle getClosestTriangleSupportB() const
Gets the points of shape B that were responsible for generating the closest triangle of the polytope.
Definition types.cpp:123
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:155
std::size_t getNumFaces() const
Definition types.hpp:701
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:665
glm::vec3 getClosestPoint() const
Returns the closest point to the origin on the triangle face closest to the origin.
Definition types.cpp:91
AreaTriangle getClosestTriangleSupportA() const
Gets the points of shape A that were responsible for generating the closest triangle of the polytope.
Definition types.cpp:114
Polytope()
Definition types.cpp:132
glm::vec3 getClosestTriangleNormal() const
Returns the direction to the closest point on the polytope's surface from the origin.
Definition types.cpp:97
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:671
glm::vec3 getNextSearch() const
Returns the next search direction for a point to add to the polytope.
Definition types.cpp:80
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:655
std::vector< glm::vec3 > mPoints
List of points representing this polytope.
Definition types.hpp:660
bool isPositiveStrict(float number)
Tests whether a number is strictly positive.
Definition util.hpp:71
bool isNonNegative(float number)
Tests whether a number is non-negative.
Definition util.hpp:113
bool isFinite(float number)
Tests whether a given number is finite.
Definition util.hpp:47
void setInteractionMask(InteractionLayerMask newMask)
Changes which set of interaction layers this object can trigger events with.
Definition types.hpp:1308
InteractionLayerMask getInteractionLayers() const
Returns an integer representing which spatial queries and collisions this object will participate in.
Definition types.hpp:1451
InteractionLayerMask getInteractionLayers() const
Returns an integer representing which spatial queries and collisions this object will participate in.
Definition types.hpp:1287
bool isPositiveStrict() const
Checks whether underlying bounds is non-trivial, as in each important parameter that represents the v...
Definition types.cpp:23
InteractionLayerMask getInteractionMask() const
Returns an integer representing which layers this object will generate spatial queries and collisions...
Definition types.hpp:1301
void setInteractionLayers(InteractionLayerMask newLayers)
Sets interaction layer mask for this object.
Definition types.hpp:1458
uint8_t BoxCorner
Type used to represent the name of the corner of a box.
Definition types.hpp:33
void setInteractionLayers(InteractionLayerMask newLayers)
Moves this object into a new group of interaction layers.
Definition types.hpp:1294
BoxCornerSpecifier
Enum values correspond to bits on a BoxCorner which help specify which side of the box on each axis i...
Definition types.hpp:40
uint16_t InteractionLayerMask
Bit field where each bit represents an interaction layer – a physics/spatial layer that can trigger o...
Definition types.hpp:57
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:526
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:26
A set of numbers representing a single circle situated somewhere in the world.
Definition types.hpp:391
glm::vec3 mCenter
The real-world coordinates of the center of the circle.
Definition types.hpp:402
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:408
bool isSensible() const
Tests whether the circle described by these parameters is valid (as opposed to invalid or infinite).
Definition types.hpp:416
bool isPositiveStrict() const
Tests whether the circle's parameters are strictly positive, and hence whether the circle encloses so...
Definition types.hpp:435
float mRadius
The radius of the circle.
Definition types.hpp:396
A set of 3 points located in the world forming a (hopefully sensible) triangle.
Definition types.hpp:327
std::array< glm::vec3, 3 > mPoints
The points of the triangle, where each point has 3 components.
Definition types.hpp:332
bool isPositiveStrict() const
Tests whether the points of this triangle encapsulate some area in space.
Definition types.hpp:362
bool isSensible() const
Tests whether the points describing the triangle are sensible (as opposed to invalid or infinite).
Definition types.hpp:341
Data representing everything about a collision.
Definition types.hpp:816
Contact mContactA
Contact information relative to the first collision shape.
Definition types.hpp:827
Contact mContactB
Contact information relative to the second collision shape.
Definition types.hpp:833
bool mCollided
Whether a collision occurred.
Definition types.hpp:821
Object representing contact information between a pair of convex shapes from the perspective of one o...
Definition types.hpp:771
float mPenetrationDepth
The length by which to move this object in the direction of the contact normal to separate the collid...
Definition types.hpp:802
glm::vec3 mTangent1
Worldspace tangent orthogonal to the contact normal and the other contact tangent.
Definition types.hpp:789
glm::vec3 mNormal
Worldspace normal pointing inward from the surface of this shape such that moving in this direction b...
Definition types.hpp:783
glm::vec3 mPoint
The worldspace point on the surface of this shape that made contact with the other shape.
Definition types.hpp:776
glm::vec3 mTangent2
Worldspace tangent orthogonal to the contact normal and the other contact tangent.
Definition types.hpp:795
A component defining the true bounds of a spatially queryable object situated somewhere in the world.
Definition types.hpp:845
static ObjectBounds create(const VolumeBox &box, const glm::vec3 &positionOffset, const glm::quat &orientationOffset, InteractionLayerMask interactionLayers=0x1, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max())
Creates bounds for an object in the shape of a box.
Definition types.cpp:41
void setVolumeBox(const glm::vec3 &boxDimensions)
Sets a box volume for this object.
Definition types.hpp:1206
TrueVolume mTrueVolume
The data defining the volume itself, independent of its position.
Definition types.hpp:946
bool isSensible() const
Returns whether the underlying volume has sensible parameters (i.e., finite, non-degenerate,...
Definition types.cpp:326
void setVolume(TrueVolumeType type, const TrueVolume &volume)
Sets the volume for these bounds.
Definition types.hpp:1196
void setOrientationOrigin(const glm::quat &newOrientation)
Sets orientation of the scene node.
Definition types.cpp:302
static std::string getComponentTypeName()
Fetches the component type string associated with this class.
Definition types.hpp:851
std::pair< float, float > getProjectionAlong(const glm::vec3 &axis) const
Returns this shape's projection along some unit vector.
Definition types.cpp:353
bool mVolumeSystemComputed
Flag set when these object bounds were set by the engine, through light bounds compute or model bound...
Definition types.hpp:1020
void setPositionWorld(const glm::vec3 &newPosition)
Sets the new world position for the object while keeping its offset relative to its entity fixed.
Definition types.cpp:247
glm::quat mOrientationOrigin
The orientation in the real world of the origin of the scene node this bounds component is attached t...
Definition types.hpp:976
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:310
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:318
InteractionLayerMask mInteractionMask
Determines which spatial queries and collisions this object will generate.
Definition types.hpp:994
TrueVolumeType mType
Value indicating the type of the volume represented by this object.
Definition types.hpp:940
void applyModelMatrix(const glm::mat4 &modelMatrix)
Computes new mPosition and mOrientation offsets based on (presumably) the model transform of the unde...
Definition types.cpp:217
glm::quat mOrientationWorld
The world orientation of the bounds of this object in the current frame.
Definition types.hpp:970
bool mTransformUpdateRequired
Flag set when object position or orientation has been set through this component, indicating that the...
Definition types.hpp:1007
glm::vec3 mPositionWorld
The world position of the bounds of this object in the current frame.
Definition types.hpp:952
glm::quat getOrientationWorld() const
The final orientation of the object bounds in the world.
Definition types.cpp:268
InteractionLayerMask mInteractionLayers
Determines which spatial queries and collisions this object participates in.
Definition types.hpp:988
void setPositionOrigin(const glm::vec3 &newPosition)
Sets the position of the scene node origin.
Definition types.cpp:261
glm::vec3 mPositionOrigin
The position, in the real world, of origin of the scene node this data is attached to.
Definition types.hpp:958
glm::mat4 getTranslationTransformOrigin() const
Gets the translation matrix associated with the underlying scene object's translation.
Definition types.hpp:1068
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:1182
void setPositionOffset(const glm::vec3 &newPosition)
Sets the offset of the bounds origin to the scene node origin.
Definition types.cpp:256
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:371
void recomputeWorldPositionOrientation()
Recomputes bounds world position based on origin and offsets.
Definition types.cpp:272
void setVolumeCapsule(float radius, float height)
Sets a capsule volume for this object.
Definition types.hpp:1220
std::pair< TrueVolumeType, TrueVolume > getVolume() const
Returns the volume and its type associated with these bounds.
Definition types.hpp:1188
void setOrientationOffset(const glm::quat &newOrientation)
Sets orientation offset relative to the scene node's orientation.
Definition types.cpp:295
glm::vec3 getPositionWorld() const
The final position of the origin of the object bounds in the world.
Definition types.cpp:243
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:964
bool mPhysicsRecomputeRequired
Flag set when this object's physics properties must be recomputed according to its new volume.
Definition types.hpp:1036
void setOrientationWorld(const glm::quat &newOrientation)
Sets the new world orientation for the object while keeping its offset relative to its entity fixed.
Definition types.cpp:277
glm::mat4 getRotationTransformOrigin() const
Gets the rotation matrix associated with the underlying scene object's orientation.
Definition types.hpp:1059
glm::quat mOrientationOffset
The transformation mapping forward as known by the underlying scene node, to forward as known by the ...
Definition types.hpp:982
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:229
bool mVolumeUpdateRequired
Flag set when this object's bounds must be recomputed by a related system.
Definition types.hpp:1029
bool mUpdatedFromTransform
Whether an update on the object's transform is allowed to modify object bounds properties.
Definition types.hpp:1000
void setVolumeSphere(float radius)
Sets a sphere volume for this object.
Definition types.hpp:1236
glm::mat3 getRotationTransformLocal() const
Gets the rotation matrix associated with this object's orientation offset.
Definition types.hpp:1050
TrueVolumeType
The types of volumes supported by the engine.
Definition types.hpp:857
A set of numbers describing a plane situated somewhere in the world.
Definition types.hpp:500
bool isPositiveStrict() const
Same as Plane::isSensible().
Definition types.hpp:537
glm::vec3 mNormal
A vector normal to the plane.
Definition types.hpp:511
glm::vec3 mPointOnPlane
A known point on the plane.
Definition types.hpp:505
bool isSensible() const
Tests whether the plane described is sensible (as opposed to invalid, infinite, or degenerate).
Definition types.hpp:519
Stores the indices of a single face of this polytope.
Definition types.hpp:641
A set of numbers describing a ray with its source at some finite point in the world,...
Definition types.hpp:447
float mLength
The length of the ray, infinite by default.
Definition types.hpp:464
glm::vec3 mStart
A point representing the starting point of the ray.
Definition types.hpp:452
glm::vec3 mDirection
The direction the ray is pointing in.
Definition types.hpp:458
bool isPositiveStrict() const
Tests whether the ray actually travels any distance from its origin.
Definition types.hpp:490
bool isSensible() const
Tests whether the ray is sensible (as opposed to invalid).
Definition types.hpp:472
Primitive for GJK algorithm.
Definition types.hpp:549
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:561
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:567
std::pair< bool, glm::vec3 > evaluate()
Tries to find a 3-simplex that encloses the origin.
Definition types.cpp:665
bool append(const glm::vec3 &candidatePoint, const glm::vec3 &supportA, const glm::vec3 &supportB)
Adds a new point to the simplex.
Definition types.hpp:581
uint8_t mNPoints
The number of points in this simplex.
Definition types.hpp:573
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:597
std::array< glm::vec3, 4 > mPoints
Points representing the simplex, derived by finding the Minksowski difference of support points on tw...
Definition types.hpp:555
The base class of all spatial query volumes.
Definition types.hpp:66
bool isSensible() const
Returns whether or not the derived volume has sensible parameters (i.e., isn't infinite or invalid).
Definition types.hpp:126
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:91
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:75
bool isPositiveStrict() const
Returns whether or not the derived volume has strictly positive parameters.
Definition types.hpp:139
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets corners of the object-relative bounding box that encapsulates the derived volume.
Definition types.hpp:111
Holds the parameters describing the spatial query volume of a simple three-dimensionsal box.
Definition types.hpp:183
bool isSensible() const
Tests whether the values representing the box are valid (as opposed to invalid or infinite).
Definition types.hpp:205
glm::vec3 mDimensions
The dimensions of the box, its width, height, and depth.
Definition types.hpp:188
bool isPositiveStrict() const
Tests whether the values representing the box are strictly positive.
Definition types.hpp:215
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Returns an array of coordinates corresponding to the corners of the box.
Definition types.hpp:195
Holds the parameters describing the spatial query volume of a simple three-dimensionsal capsule (or p...
Definition types.hpp:225
float mRadius
The radius of the hemispheres on either end of the capsule.
Definition types.hpp:236
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:243
float mHeight
The height of the cylindrical section of the capsule.
Definition types.hpp:230
bool isPositiveStrict() const
Tests whether the values representing the capsule are all strictly positive.
Definition types.hpp:270
bool isSensible() const
Tests whether the values representing the capsule make sense (as opposed to being invalid or infinite...
Definition types.hpp:256
Holds parameters describing a spherical spatial query volume.
Definition types.hpp:284
float mRadius
The radius of the sphere.
Definition types.hpp:289
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets an array of coordinates of corners of a box just encapsulating the sphere.
Definition types.hpp:296
bool isPositiveStrict() const
Tests whether this volume's parameters are strictly positive.
Definition types.hpp:317
bool isSensible() const
Tests whether this volume's parameters are sensible (as opposed to invalid or infinite).
Definition types.hpp:306
Definition types.hpp:146
bool isPositiveStrict() const
Poor man's vtable cont'd.
Definition types.hpp:173
bool isSensible() const
Poor man's vtable cont'd.
Definition types.hpp:163
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Poor man's vtable cont'd.
Definition types.hpp:153
A union of supported volume structs.
Definition types.hpp:867
Contains a couple of classes not tied to any part of the engine in particular, but useful to those pa...