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 <cmath>
15#include <array>
16#include <queue>
17
18#include <glm/glm.hpp>
19#include <glm/gtc/quaternion.hpp>
20#include <nlohmann/json.hpp>
21#include <string>
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
69 inline bool isFinite(const glm::vec3& vector) {
70 return isFinite(vector.x) && isFinite(vector.y) && isFinite(vector.z);
71 }
72
81 inline bool isPositiveStrict(float number) {
82 return number > 0.f;
83 }
84
92 inline bool isPositiveStrict(const glm::vec3& vector) {
93 return isPositiveStrict(vector.x) && isPositiveStrict(vector.y) && isPositiveStrict(vector.z);
94 }
95
96 inline bool isNumber(float number) {
97 return !std::isnan(number);
98 };
99
100 inline bool isNumber(const glm::vec3& vector) {
101 return isNumber(vector.x) && isNumber(vector.y) && isNumber(vector.z);
102 };
103
112 inline bool isNonNegative(float number) {
113 return number >= 0.f;
114 }
115
124 inline bool isNonNegative(const glm::vec3& vector) {
125 return isNonNegative(vector.x) && isNonNegative(vector.y) && isNonNegative(vector.z);
126 }
127
128
129 template <typename TDerived>
130 struct Volume;
131
138 using InteractionLayerMask = uint16_t;
139
147 struct VolumeBase_ {
156 inline static constexpr std::array<glm::vec3, 8> GetCornerSignsArray() {
157 std::array<glm::vec3, 8> cornerSigns {};
158 for(BoxCorner corner {0}; corner < 8; ++corner) {
159 cornerSigns[corner].x = corner&BoxCornerSpecifier::RIGHT? 1.f: -1.f;
160 cornerSigns[corner].y = corner&BoxCornerSpecifier::TOP? 1.f: -1.f;
161 cornerSigns[corner].z = corner&BoxCornerSpecifier::FRONT? 1.f: -1.f;
162 }
163 return cornerSigns;
164 }
165
172 inline static std::array<glm::vec3, 8> ComputeBoxCorners(const glm::vec3& boxDimensions) {
173 const std::array<glm::vec3, 8> cornerSignsArray { GetCornerSignsArray() };
174 glm::vec3 absoluteCornerOffset { .5f * boxDimensions };
175 std::array<glm::vec3, 8> cornerArray { .5f * boxDimensions };
176 for(uint8_t corner{0}; corner < 8; ++corner) {
177 cornerArray[corner] = cornerSignsArray[corner] * absoluteCornerOffset;
178 }
179 return cornerArray;
180 }
181
191 template <typename TDerived>
192 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const {
194 }
195
206 template <typename TDerived>
207 inline bool isSensible() const {
209 }
210
219 template <typename TDerived>
220 inline bool isPositiveStrict() const {
222 }
223 };
224
226 template <typename TDerived>
227 struct Volume: public VolumeBase_ {
234 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const {
235 return TDerived::getVolumeRelativeBoxCorners();
236 }
237
244 inline bool isSensible() const {
245 return TDerived::isSensible();
246 }
247
254 inline bool isPositiveStrict() const {
255 return TDerived::isPositiveStrict();
256 }
257 };
258
264 struct VolumeBox: public Volume<VolumeBox> {
269 glm::vec3 mDimensions {0.f, 0.f, 0.f};
270
276 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
278 }
279
286 inline bool isSensible() const {
288 }
289
296 inline bool isPositiveStrict() const {
298 }
299 };
300
306 struct VolumeCapsule: public Volume<VolumeCapsule> {
311 float mHeight {0.f};
312
317 float mRadius {0.f};
318
324 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
325 const glm::vec3 boxDimensions { 2.f*mRadius, mHeight + 2.f*mRadius, 2.f*mRadius};
326 return ComputeBoxCorners(boxDimensions);
327 }
328
337 inline bool isSensible() const {
338 return (
341 );
342 }
343
351 inline bool isPositiveStrict() const {
352 return (
354 // You can still have a capsule which occupies space even if its
355 // spine is length 0, so no test for mHeight
356 );
357 }
358 };
359
365 struct VolumeSphere: public Volume<VolumeSphere> {
370 float mRadius {0.f};
371
377 inline std::array<glm::vec3, 8> getVolumeRelativeBoxCorners () const {
378 return ComputeBoxCorners(glm::vec3{2*mRadius});
379 }
380
387 inline bool isSensible() const {
389 }
390
398 inline bool isPositiveStrict() const {
400 }
401 };
402
413 std::array<glm::vec3, 3> mPoints {};
414
422 inline bool isSensible() const {
423 return (
424 (
426 ) && (
428 glm::length(glm::cross(
429 mPoints[2] - mPoints[0], mPoints[1] - mPoints[0]
430 ))
431 )
432 )
433 );
434 }
435
443 inline bool isPositiveStrict() const {
444 return (
446 glm::length(
447 glm::cross(
448 mPoints[2] - mPoints[0], mPoints[1] - mPoints[0]
449 )
450 )
451 )
452 );
453 }
454 };
455
465 std::array<AreaTriangle, 12> computeBoxFaceTriangles(const std::array<glm::vec3, 8>& boxCorners);
466
472 struct AreaCircle {
477 float mRadius { 0.f };
478
483 glm::vec3 mCenter { 0.f };
484
489 glm::vec3 mNormal { 0.f, -1.f, 0.f };
490
497 inline bool isSensible() const {
498 return (
499 (
501 ) && (
503 ) && (
505 )
506 );
507 }
508
516 inline bool isPositiveStrict() const {
517 return (
519 );
520 }
521 };
522
528 struct Ray {
533 glm::vec3 mStart { 0.f };
534
539 glm::vec3 mDirection { 0.f, 0.f, -1.f };
540
545 float mLength { std::numeric_limits<float>::infinity() };
546
553 inline bool isSensible() const {
554 return (
555 (
557 ) && (
559 ) && (
561 )
562 );
563 }
564
571 inline bool isPositiveStrict() const {
573 }
574 };
575
581 struct Plane {
586 glm::vec3 mPointOnPlane { 0.f };
587
592 glm::vec3 mNormal { 0.f, 0.f, -1.f };
593
600 inline bool isSensible() const {
601 return (
602 (
604 ) && (
606 )
607 );
608 }
609
618 inline bool isPositiveStrict() const {
619 return isSensible();
620 }
621 };
622
630 struct Simplex {
636 std::array<glm::vec3, 4> mPoints;
637
642 std::array<glm::vec3, 4> mPointsSupportA;
643
648 std::array<glm::vec3, 4> mPointsSupportB;
649
654 uint8_t mNPoints { 0 };
655
662 inline bool append(const glm::vec3& candidatePoint, const glm::vec3& supportA, const glm::vec3& supportB) {
663 assert(mNPoints < 4 && "We already have 4 (or more) points, there's no more needed");
664 assert(supportA - supportB == candidatePoint && "The difference in supports should yield the candidate point");
665
666 mPoints[mNPoints] = candidatePoint;
667 mPointsSupportA[mNPoints] = supportA;
668 mPointsSupportB[mNPoints] = supportB;
669 ++mNPoints;
670
671 return true;
672 }
673
678 inline void reorder(const std::vector<uint8_t> reorderedIndices) {
679 assert(reorderedIndices.size() <= 4 && "Invalid point list provided");
680 const std::array<glm::vec3, 4> oldPoints { mPoints };
681 const std::array<glm::vec3, 4> oldPointsSupportA { mPointsSupportA };
682 const std::array<glm::vec3, 4> oldPointsSupportB { mPointsSupportB };
683 mNPoints = 0;
684 for(const auto& index: reorderedIndices) {
685 const bool pointAddedSuccessfully{ append(oldPoints[index], oldPointsSupportA[index], oldPointsSupportB[index]) };
686 assert(pointAddedSuccessfully && "Invalid point list provided");
687 }
688 }
689
701 std::pair<bool, glm::vec3> evaluate();
702
703 private:
704 std::pair<bool, glm::vec3> doSimplex4();
705 glm::vec3 doSimplex3();
706 glm::vec3 doSimplex2();
707 };
708
717 class Polytope {
718 private:
722 struct Face {
723 std::array<uint16_t, 3> mIndices {};
724 };
725
729 Polytope();
730
731
736 std::priority_queue<Face, std::vector<Face>, std::function<bool(const Face&, const Face&)>> mFaces;
737
741 std::vector<glm::vec3> mPoints {};
746 std::vector<glm::vec3> mPointsSupportA {};
747
752 std::vector<glm::vec3> mPointsSupportB {};
753
754 inline glm::vec3 getTriangleCross(const Face& face) const {
755 return glm::cross(
756 mPoints[face.mIndices[1]] - mPoints[face.mIndices[0]],
757 mPoints[face.mIndices[2]] - mPoints[face.mIndices[0]]
758 );
759 }
760
761 inline glm::vec3 getTriangleNorm(const Face& face) const {
762 return glm::normalize(getTriangleCross(face));
763 }
764
765 public:
771 Polytope(const Simplex& simplex);
772
777 glm::vec3 getNextSearch() const;
778
782 std::size_t getNumFaces() const {
783 return mFaces.size();
784 }
785
786 std::size_t getNumPoints() const {
787 return mPoints.size();
788 }
789
795 glm::vec3 getClosestPoint() const;
796
804 glm::vec3 getClosestTriangleNormal() const;
805
813 AreaTriangle getClosestTriangle() const;
814
820 AreaTriangle getClosestTriangleSupportA() const;
821
827 AreaTriangle getClosestTriangleSupportB() const;
828
841 bool append(const glm::vec3& newPoint, const glm::vec3& supportA, const glm::vec3& supportB);
842 };
843
852 struct Contact {
857 glm::vec3 mPoint;
858
864 glm::vec3 mNormal;
865
870 glm::vec3 mTangent1;
871
876 glm::vec3 mTangent2;
877
884 };
885
916
932 inline static std::string getComponentTypeName() { return "ObjectBounds"; }
933
938 enum class TrueVolumeType: uint8_t {
939 BOX=0,
940 SPHERE,
941 CAPSULE,
942 };
943
949 VolumeBox mBox { .mDimensions{ glm::vec3{0.f} } };
950 VolumeCapsule mCapsule;
951 VolumeSphere mSphere;
952 };
953
967 static ObjectBounds create(
968 const VolumeBox& box,
969 const glm::vec3& positionOffset,
970 const glm::quat& orientationOffset,
971 InteractionLayerMask interactionLayers=0x1,
972 InteractionLayerMask interactionMask=std::numeric_limits<InteractionLayerMask>::max()
973 );
974
988 static ObjectBounds create(
989 const VolumeCapsule& capsule,
990 const glm::vec3& positionOffset,
991 const glm::quat& orientationOffset,
992 InteractionLayerMask interactionLayers=0x1,
993 InteractionLayerMask interactionMask=std::numeric_limits<InteractionLayerMask>::max()
994 );
995
1009 static ObjectBounds create(
1010 const VolumeSphere& sphere,
1011 const glm::vec3& positionOffset,
1012 const glm::quat& orientationOffset,
1013 InteractionLayerMask interactionLayers=0x1,
1014 InteractionLayerMask interactionMask=std::numeric_limits<InteractionLayerMask>::max()
1015 );
1016
1021 TrueVolumeType mType { TrueVolumeType::BOX };
1022
1028
1033 glm::vec3 mPositionWorld { 0.f };
1034
1039 glm::vec3 mPositionOrigin { 0.f };
1040
1045 glm::vec3 mPositionOffset { 0.f };
1046
1051 glm::quat mOrientationWorld { glm::vec3 { 0.f } };
1052
1057 glm::quat mOrientationOrigin { glm::vec3{ 0.f } };
1058
1063 glm::quat mOrientationOffset { glm::vec3{ 0.f } };
1064
1070
1075 InteractionLayerMask mInteractionMask { std::numeric_limits<InteractionLayerMask>::max() };
1076
1082
1089
1102
1111
1118
1124 void applyModelMatrix(const glm::mat4& modelMatrix);
1125
1131 inline glm::mat3 getRotationTransformLocal() const {
1132 return glm::mat3_cast(glm::normalize(mOrientationOffset));
1133 }
1134
1140 inline glm::mat4 getRotationTransformOrigin() const {
1141 return glm::mat4_cast(glm::normalize(mOrientationOrigin));
1142 }
1143
1149 inline glm::mat4 getTranslationTransformOrigin() const {
1150 return glm::mat4 {
1151 { 1.f, 0.f, 0.f, 0.f },
1152 { 0.f, 1.f, 0.f, 0.f },
1153 { 0.f, 0.f, 1.f, 0.f },
1154 { mPositionOrigin, 1.f },
1155 };
1156 }
1157
1163 glm::vec3 getPositionWorld() const;
1164
1173 void setPositionWorld(const glm::vec3& newPosition);
1174
1181 void setPositionOffset(const glm::vec3& newPosition);
1182
1189 void setPositionOrigin(const glm::vec3& newPosition);
1190
1196
1205 glm::quat getOrientationWorld() const;
1206
1217 void setOrientationWorld(const glm::quat& newOrientation);
1218
1224 void setOrientationOffset(const glm::quat& newOrientation);
1225
1231 void setOrientationOrigin(const glm::quat& newOrientation);
1232
1238 std::array<glm::vec3, 8> getVolumeRelativeBoxCorners() const;
1239
1246 std::array<glm::vec3, 8> getLocalOrientedBoxCorners() const;
1247
1253 std::array<glm::vec3, 8> getWorldOrientedBoxCorners() const;
1254
1264
1269 std::pair<TrueVolumeType, TrueVolume> getVolume() const {
1270 return { mType, mTrueVolume };
1271 }
1272
1277 inline void setVolume(TrueVolumeType type, const TrueVolume& volume) {
1278 mType = type;
1279 mTrueVolume = volume;
1281 }
1282
1287 inline void setVolumeBox(const glm::vec3& boxDimensions) {
1288 assert(
1289 isNonNegative(boxDimensions) && isFinite(boxDimensions)
1290 && "Invalid box parameters provided"
1291 );
1292 setVolume(TrueVolumeType::BOX,
1293 TrueVolume { .mBox { .mDimensions { boxDimensions } } }
1294 );
1295 }
1296
1301 inline void setVolumeCapsule(float radius, float height) {
1302 assert(
1303 isNonNegative(radius) && isNonNegative(height) && isFinite(radius) && isFinite(height)
1304 && "Invalid capsule parameters provided"
1305 );
1306 setVolume(TrueVolumeType::CAPSULE,
1307 TrueVolume {
1308 .mCapsule { .mHeight { height }, .mRadius { radius } }
1309 }
1310 );
1311 }
1312
1317 inline void setVolumeSphere(float radius) {
1318 assert(
1319 isNonNegative(radius) && isFinite(radius)
1320 && "Invalid sphere parameters provided"
1321 );
1322 setVolume(TrueVolumeType::SPHERE,
1323 TrueVolume {
1324 .mSphere { .mRadius { radius } }
1325 }
1326 );
1327 }
1328
1339 glm::vec3 getSupportAlong(const glm::vec3& axis) const;
1340
1347 std::pair<float, float> getProjectionAlong(const glm::vec3& axis) const;
1348
1354 bool isSensible() const;
1355
1361 bool isPositiveStrict() const;
1362
1369
1375 inline void setInteractionLayers(InteractionLayerMask newLayers) { mInteractionLayers = newLayers; }
1376
1383
1390 };
1391
1404 public:
1410 inline static std::string getComponentTypeName() { return "AxisAlignedBounds"; }
1411
1416 using Extents = std::pair<glm::vec3, glm::vec3>;
1417
1423
1429 AxisAlignedBounds(const ObjectBounds& objectBounds);
1430
1437 AxisAlignedBounds(const Extents& axisAlignedExtents, InteractionLayerMask interactionLayers=0x0);
1438
1445 AxisAlignedBounds(const glm::vec3& position, const glm::vec3& dimensions, InteractionLayerMask interactionLayers=0x0):
1446 AxisAlignedBounds { Extents{{position + .5f*dimensions}, {position - .5f*dimensions}}, interactionLayers }
1447 {}
1448
1455 AxisAlignedBounds operator+(const AxisAlignedBounds& other) const;
1456
1462 std::array<glm::vec3, 8> getAxisAlignedBoxCorners() const;
1463
1469 inline std::array<AreaTriangle, 12> getAxisAlignedBoxFaceTriangles() const { return computeBoxFaceTriangles(getAxisAlignedBoxCorners()); }
1470
1476 Extents getAxisAlignedBoxExtents() const;
1477
1483 inline glm::vec3 getDimensions() const { return mExtents.first - mExtents.second; }
1484
1490 inline glm::vec3 getPositionWorld() const { return mExtents.second + .5f * getDimensions(); }
1491
1498 inline bool isSensible() const {
1499 return (
1500 isFinite(mExtents.first) && isFinite(mExtents.second)
1501 && isNonNegative(mExtents.first - mExtents.second)
1502 );
1503 }
1504
1513 glm::vec3 getSupportAlong(const glm::vec3& axis) const;
1514
1521 inline bool isPositiveStrict() const {
1522 return (
1524 );
1525 }
1526
1533
1539 inline void setInteractionLayers(InteractionLayerMask newLayers) { mInteractionLayers = newLayers; }
1540
1546 inline void setPosition(const glm::vec3& position) {
1547 assert(isFinite(position) && "Invalid position specified. Position must be finite");
1548 const glm::vec3 deltaPosition { position - getPositionWorld() };
1549 mExtents.first += deltaPosition;
1550 mExtents.second += deltaPosition;
1551 }
1552
1558 inline void setDimensions(const glm::vec3& dimensions) {
1559 assert(isNonNegative(dimensions) && isFinite(dimensions) && "Invalid dimensions provided. Dimensions must be non negative and finite");
1560 const glm::vec3 position { getPositionWorld() };
1561 const glm::vec3 deltaDimensions { dimensions - getDimensions() };
1562 mExtents.first += .5f * deltaDimensions;
1563 mExtents.second -= .5f * deltaDimensions;
1564 }
1565 private:
1571 void setByExtents(const Extents& axisAlignedExtents);
1572
1577 Extents mExtents {glm::vec3{0.f}, glm::vec3{0.f}};
1578
1584 };
1585
1590 NLOHMANN_JSON_SERIALIZE_ENUM( ObjectBounds::TrueVolumeType, {
1591 {ObjectBounds::TrueVolumeType::BOX, "box"},
1592 {ObjectBounds::TrueVolumeType::SPHERE, "sphere"},
1593 {ObjectBounds::TrueVolumeType::CAPSULE, "capsule"},
1594 })
1595
1600 inline void to_json(nlohmann::json& json, const ObjectBounds& objectBounds) {
1601 json = {
1602 {"type", ObjectBounds::getComponentTypeName()},
1603 {"volume_type", objectBounds.mType},
1604 {"position_offset", { objectBounds.mPositionOffset.x, objectBounds.mPositionOffset.y, objectBounds.mPositionOffset.z}},
1605 {"orientation_offset", { objectBounds.mOrientationOffset.w, objectBounds.mOrientationOffset.x, objectBounds.mOrientationOffset.y, objectBounds.mOrientationOffset.z }},
1606 };
1607 switch(objectBounds.mType) {
1608 case ObjectBounds::TrueVolumeType::BOX:
1609 json["volume_properties"] = {
1610 {"width", objectBounds.mTrueVolume.mBox.mDimensions.x},
1611 {"height", objectBounds.mTrueVolume.mBox.mDimensions.y},
1612 {"depth", objectBounds.mTrueVolume.mBox.mDimensions.z},
1613 };
1614 break;
1615 case ObjectBounds::TrueVolumeType::SPHERE:
1616 json["volume_properties"] = {
1617 {"radius", objectBounds.mTrueVolume.mSphere.mRadius},
1618 };
1619 break;
1620 case ObjectBounds::TrueVolumeType::CAPSULE:
1621 json["volume_properties"] = {
1622 {"radius", objectBounds.mTrueVolume.mCapsule.mRadius},
1623 {"height", objectBounds.mTrueVolume.mCapsule.mHeight},
1624 };
1625 break;
1626 };
1627 }
1628
1630 inline void from_json(const nlohmann::json& json, ObjectBounds& objectBounds) {
1631 assert(json.at("type") == ObjectBounds::getComponentTypeName() && "Incorrect type property for an objectBounds component");
1632 const glm::vec3 positionOffset {
1633 json.at("position_offset")[0],
1634 json.at("position_offset")[1],
1635 json.at("position_offset")[2],
1636 };
1637 const glm::vec3 orientationOffset {
1638 glm::eulerAngles(glm::normalize(glm::quat {
1639 json.at("orientation_offset")[0],
1640 json.at("orientation_offset")[1],
1641 json.at("orientation_offset")[2],
1642 json.at("orientation_offset")[3]
1643 }))
1644 };
1645 const InteractionLayerMask interactionLayers { json.at("interaction_layers").get<InteractionLayerMask>() };
1646 const InteractionLayerMask interactionMask { json.at("interaction_mask").get<InteractionLayerMask>() };
1647
1648 switch (static_cast<ObjectBounds::TrueVolumeType>(json.at("volume_type"))) {
1649 case ObjectBounds::TrueVolumeType::BOX:
1650 objectBounds = ObjectBounds::create(
1651 VolumeBox{ .mDimensions {
1652 json.at("volume_properties").at("width").get<float>(),
1653 json.at("volume_properties").at("height").get<float>(),
1654 json.at("volume_properties").at("depth").get<float>(),
1655 } },
1656 positionOffset,
1657 orientationOffset,
1658 interactionLayers,
1659 interactionMask
1660 );
1661 break;
1662
1663 case ObjectBounds::TrueVolumeType::SPHERE:
1664 objectBounds = ObjectBounds::create(
1665 VolumeSphere { .mRadius { json.at("volume_properties").at("radius").get<float>() } },
1666 positionOffset,
1667 orientationOffset,
1668 interactionLayers,
1669 interactionMask
1670 );
1671 break;
1672
1673 case ObjectBounds::TrueVolumeType::CAPSULE:
1674 objectBounds = ObjectBounds::create(
1675 VolumeCapsule {
1676 .mHeight { json.at("volume_properties").at("height").get<float>() },
1677 .mRadius { json.at("volume_properties").at("radius").get<float>() },
1678 },
1679 positionOffset,
1680 orientationOffset,
1681 interactionLayers,
1682 interactionMask
1683 );
1684 break;
1685 }
1686 objectBounds.mVolumeSystemComputed = false;
1687 }
1688
1690 inline void to_json(nlohmann::json& json, const AxisAlignedBounds& axisAlignedBounds) { /* never used, so pass */
1691 (void)json; // prevent unused parameter warnings
1692 (void)axisAlignedBounds; // prevent unused parameter warnings
1693 }
1694
1696 inline void from_json(const nlohmann::json& json, AxisAlignedBounds& objectBounds) { /* never used, so pass */
1697 (void)json; // prevent unused parameter warnings
1698 (void)objectBounds; // prevent unused parameter warnings
1699 }
1700}
1701
1702#endif
1703
glm::vec3 getPositionWorld() const
Gets the coordinates of the center of this box.
Definition types.hpp:1490
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:1469
void setPosition(const glm::vec3 &position)
Sets the position of this box.
Definition types.hpp:1546
void setDimensions(const glm::vec3 &dimensions)
Sets the dimensions of this box.
Definition types.hpp:1558
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:1416
InteractionLayerMask mInteractionLayers
Determines which spatial queries and collisions this object participates in.
Definition types.hpp:1583
glm::vec3 getDimensions() const
Gets the dimensions of this box.
Definition types.hpp:1483
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:1577
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:1498
bool isPositiveStrict() const
Tests whether this box has strictly positive parameters and hence encloses some region in space.
Definition types.hpp:1521
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:1445
static std::string getComponentTypeName()
Gets the component type string for this object.
Definition types.hpp:1410
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:782
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:746
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:752
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:736
std::vector< glm::vec3 > mPoints
List of points representing this polytope.
Definition types.hpp:741
bool isPositiveStrict(float number)
Tests whether a number is strictly positive.
Definition types.hpp:81
void setInteractionMask(InteractionLayerMask newMask)
Changes which set of interaction layers this object can trigger events with.
Definition types.hpp:1389
InteractionLayerMask getInteractionLayers() const
Returns an integer representing which spatial queries and collisions this object will participate in.
Definition types.hpp:1532
InteractionLayerMask getInteractionLayers() const
Returns an integer representing which spatial queries and collisions this object will participate in.
Definition types.hpp:1368
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:1382
void setInteractionLayers(InteractionLayerMask newLayers)
Sets interaction layer mask for this object.
Definition types.hpp:1539
uint8_t BoxCorner
Type used to represent the name of the corner of a box.
Definition types.hpp:35
void setInteractionLayers(InteractionLayerMask newLayers)
Moves this object into a new group of interaction layers.
Definition types.hpp:1375
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
uint16_t InteractionLayerMask
Bit field where each bit represents an interaction layer – a physics/spatial layer that can trigger o...
Definition types.hpp:138
bool isNonNegative(float number)
Tests whether a number is non-negative.
Definition types.hpp:112
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
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:25
A set of numbers representing a single circle situated somewhere in the world.
Definition types.hpp:472
glm::vec3 mCenter
The real-world coordinates of the center of the circle.
Definition types.hpp:483
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:489
bool isSensible() const
Tests whether the circle described by these parameters is valid (as opposed to invalid or infinite).
Definition types.hpp:497
bool isPositiveStrict() const
Tests whether the circle's parameters are strictly positive, and hence whether the circle encloses so...
Definition types.hpp:516
float mRadius
The radius of the circle.
Definition types.hpp:477
A set of 3 points located in the world forming a (hopefully sensible) triangle.
Definition types.hpp:408
std::array< glm::vec3, 3 > mPoints
The points of the triangle, where each point has 3 components.
Definition types.hpp:413
bool isPositiveStrict() const
Tests whether the points of this triangle encapsulate some area in space.
Definition types.hpp:443
bool isSensible() const
Tests whether the points describing the triangle are sensible (as opposed to invalid or infinite).
Definition types.hpp:422
Data representing everything about a collision.
Definition types.hpp:897
Contact mContactA
Contact information relative to the first collision shape.
Definition types.hpp:908
Contact mContactB
Contact information relative to the second collision shape.
Definition types.hpp:914
bool mCollided
Whether a collision occurred.
Definition types.hpp:902
Object representing contact information between a pair of convex shapes from the perspective of one o...
Definition types.hpp:852
float mPenetrationDepth
The length by which to move this object in the direction of the contact normal to separate the collid...
Definition types.hpp:883
glm::vec3 mTangent1
Worldspace tangent orthogonal to the contact normal and the other contact tangent.
Definition types.hpp:870
glm::vec3 mNormal
Worldspace normal pointing inward from the surface of this shape such that moving in this direction b...
Definition types.hpp:864
glm::vec3 mPoint
The worldspace point on the surface of this shape that made contact with the other shape.
Definition types.hpp:857
glm::vec3 mTangent2
Worldspace tangent orthogonal to the contact normal and the other contact tangent.
Definition types.hpp:876
A component defining the true bounds of a spatially queryable object situated somewhere in the world.
Definition types.hpp:926
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:1287
TrueVolume mTrueVolume
The data defining the volume itself, independent of its position.
Definition types.hpp:1027
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:1277
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:932
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:1101
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:1057
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:1075
TrueVolumeType mType
Value indicating the type of the volume represented by this object.
Definition types.hpp:1021
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:1051
bool mTransformUpdateRequired
Flag set when object position or orientation has been set through this component, indicating that the...
Definition types.hpp:1088
glm::vec3 mPositionWorld
The world position of the bounds of this object in the current frame.
Definition types.hpp:1033
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:1069
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:1039
glm::mat4 getTranslationTransformOrigin() const
Gets the translation matrix associated with the underlying scene object's translation.
Definition types.hpp:1149
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:1263
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:1301
std::pair< TrueVolumeType, TrueVolume > getVolume() const
Returns the volume and its type associated with these bounds.
Definition types.hpp:1269
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:1045
bool mPhysicsRecomputeRequired
Flag set when this object's physics properties must be recomputed according to its new volume.
Definition types.hpp:1117
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:1140
glm::quat mOrientationOffset
The transformation mapping forward as known by the underlying scene node, to forward as known by the ...
Definition types.hpp:1063
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:1110
bool mUpdatedFromTransform
Whether an update on the object's transform is allowed to modify object bounds properties.
Definition types.hpp:1081
void setVolumeSphere(float radius)
Sets a sphere volume for this object.
Definition types.hpp:1317
glm::mat3 getRotationTransformLocal() const
Gets the rotation matrix associated with this object's orientation offset.
Definition types.hpp:1131
TrueVolumeType
The types of volumes supported by the engine.
Definition types.hpp:938
A set of numbers describing a plane situated somewhere in the world.
Definition types.hpp:581
bool isPositiveStrict() const
Same as Plane::isSensible().
Definition types.hpp:618
glm::vec3 mNormal
A vector normal to the plane.
Definition types.hpp:592
glm::vec3 mPointOnPlane
A known point on the plane.
Definition types.hpp:586
bool isSensible() const
Tests whether the plane described is sensible (as opposed to invalid, infinite, or degenerate).
Definition types.hpp:600
Stores the indices of a single face of this polytope.
Definition types.hpp:722
A set of numbers describing a ray with its source at some finite point in the world,...
Definition types.hpp:528
float mLength
The length of the ray, infinite by default.
Definition types.hpp:545
glm::vec3 mStart
A point representing the starting point of the ray.
Definition types.hpp:533
glm::vec3 mDirection
The direction the ray is pointing in.
Definition types.hpp:539
bool isPositiveStrict() const
Tests whether the ray actually travels any distance from its origin.
Definition types.hpp:571
bool isSensible() const
Tests whether the ray is sensible (as opposed to invalid).
Definition types.hpp:553
Primitive for GJK algorithm.
Definition types.hpp:630
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:642
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:648
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:662
uint8_t mNPoints
The number of points in this simplex.
Definition types.hpp:654
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:678
std::array< glm::vec3, 4 > mPoints
Points representing the simplex, derived by finding the Minksowski difference of support points on tw...
Definition types.hpp:636
The base class of all spatial query volumes.
Definition types.hpp:147
bool isSensible() const
Returns whether or not the derived volume has sensible parameters (i.e., isn't infinite or invalid).
Definition types.hpp:207
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:172
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:156
bool isPositiveStrict() const
Returns whether or not the derived volume has strictly positive parameters.
Definition types.hpp:220
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets corners of the object-relative bounding box that encapsulates the derived volume.
Definition types.hpp:192
Holds the parameters describing the spatial query volume of a simple three-dimensionsal box.
Definition types.hpp:264
bool isSensible() const
Tests whether the values representing the box are valid (as opposed to invalid or infinite).
Definition types.hpp:286
glm::vec3 mDimensions
The dimensions of the box, its width, height, and depth.
Definition types.hpp:269
bool isPositiveStrict() const
Tests whether the values representing the box are strictly positive.
Definition types.hpp:296
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Returns an array of coordinates corresponding to the corners of the box.
Definition types.hpp:276
Holds the parameters describing the spatial query volume of a simple three-dimensionsal capsule (or p...
Definition types.hpp:306
float mRadius
The radius of the hemispheres on either end of the capsule.
Definition types.hpp:317
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:324
float mHeight
The height of the cylindrical section of the capsule.
Definition types.hpp:311
bool isPositiveStrict() const
Tests whether the values representing the capsule are all strictly positive.
Definition types.hpp:351
bool isSensible() const
Tests whether the values representing the capsule make sense (as opposed to being invalid or infinite...
Definition types.hpp:337
Holds parameters describing a spherical spatial query volume.
Definition types.hpp:365
float mRadius
The radius of the sphere.
Definition types.hpp:370
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Gets an array of coordinates of corners of a box just encapsulating the sphere.
Definition types.hpp:377
bool isPositiveStrict() const
Tests whether this volume's parameters are strictly positive.
Definition types.hpp:398
bool isSensible() const
Tests whether this volume's parameters are sensible (as opposed to invalid or infinite).
Definition types.hpp:387
Definition types.hpp:227
bool isPositiveStrict() const
Poor man's vtable cont'd.
Definition types.hpp:254
bool isSensible() const
Poor man's vtable cont'd.
Definition types.hpp:244
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners() const
Poor man's vtable cont'd.
Definition types.hpp:234
A union of supported volume structs.
Definition types.hpp:948