GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Shape.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_PHYSICS_SHAPE_HPP
5#define GREM_PHYSICS_SHAPE_HPP
6
8
23#include <GREM/core/math.hpp>
26
27#include <utility> // std::move
28
29namespace grem::physics {
30
35public:
39 static const CollisionLayer MAX;
40
46 constexpr explicit CollisionLayer(size_t index) noexcept
47 : index(static_cast<uint8_t>(index)) {}
48
54 constexpr explicit operator size_t() const noexcept {
55 return static_cast<size_t>(index);
56 }
57
65 [[nodiscard]] constexpr bool operator==(const CollisionLayer& other) const noexcept = default;
66
67private:
68 uint8_t index;
69};
70
72
77public:
81 static const CollisionLayers ALL;
82
86 constexpr CollisionLayers() noexcept = default;
87
96 constexpr CollisionLayers(CollisionLayer layer) noexcept
97 : bits(uint32_t{1} << static_cast<size_t>(layer)) {}
98
106 [[nodiscard]] constexpr bool operator==(const CollisionLayers& other) const noexcept = default;
107
113 [[nodiscard]] constexpr bool empty() const noexcept {
114 return bits == 0;
115 }
116
124 [[nodiscard]] constexpr bool contains(CollisionLayer layer) const noexcept {
125 return (bits & CollisionLayers{layer}.bits) != 0;
126 }
127
136 [[nodiscard]] constexpr bool containsAnyOf(CollisionLayers layers) const noexcept {
137 return (bits & layers.bits) != 0;
138 }
139
148 [[nodiscard]] constexpr bool containsAllOf(CollisionLayers layers) const noexcept {
149 return (bits & layers.bits) == layers.bits;
150 }
151
160 [[nodiscard]] friend constexpr CollisionLayers operator~(CollisionLayers a) noexcept {
161 return CollisionLayers{~a.bits};
162 }
163
172 [[nodiscard]] friend constexpr CollisionLayers operator&(CollisionLayers a, CollisionLayers b) noexcept {
173 return CollisionLayers{a.bits & b.bits};
174 }
175
184 [[nodiscard]] friend constexpr CollisionLayers operator|(CollisionLayers a, CollisionLayers b) noexcept {
185 return CollisionLayers{a.bits | b.bits};
186 }
187
197 [[nodiscard]] friend constexpr CollisionLayers operator^(CollisionLayers a, CollisionLayers b) noexcept {
198 return CollisionLayers{a.bits ^ b.bits};
199 }
200
209 friend constexpr CollisionLayers& operator&=(CollisionLayers& a, CollisionLayers b) noexcept {
210 return a = a & b;
211 }
212
221 friend constexpr CollisionLayers& operator|=(CollisionLayers& a, CollisionLayers b) noexcept {
222 return a = a | b;
223 }
224
233 friend constexpr CollisionLayers& operator^=(CollisionLayers& a, CollisionLayers b) noexcept {
234 return a = a ^ b;
235 }
236
237private:
238 constexpr explicit CollisionLayers(uint32_t bits) noexcept
239 : bits(bits) {}
240
241 uint32_t bits = 0;
242};
243
244inline constexpr CollisionLayers CollisionLayers::ALL = ~CollisionLayers{};
245
254 return ~CollisionLayers{a};
255}
256
266 return CollisionLayers{a} | CollisionLayers{b};
267}
268
279
284 using TestFlags = uint8_t;
285 enum TestFlag : TestFlags { // NOLINT(cppcoreguidelines-use-enum-class)
288 };
289
291
298 [[nodiscard]] constexpr explicit operator bool() const noexcept {
299 return passed != 0;
300 }
301
309 [[nodiscard]] constexpr bool operator==(const CollisionFilterTestResult& other) const noexcept = default;
310
318 [[nodiscard]] constexpr bool detectsCollision() const noexcept {
319 return (passed & DETECTS_COLLISION) != 0;
320 }
321
329 [[nodiscard]] constexpr bool respondsToCollision() const noexcept {
330 return (passed & RESPONDS_TO_COLLISION) != 0;
331 }
332};
333
340
343
352 [[nodiscard]] constexpr CollisionFilterTestResult operator()(CollisionFilter a, CollisionFilter b) const noexcept {
353 const CollisionLayers detectionLayersA = detectionLayers & a.detectionLayers & b.layers;
354 const CollisionLayers detectionLayersB = detectionLayers & b.detectionLayers & a.layers;
355 const CollisionLayers noDetectionLayersA = detectionLayers & a.noDetectionLayers & b.layers;
356 const CollisionLayers noDetectionLayersB = detectionLayers & b.noDetectionLayers & a.layers;
357 const bool wantsDetectionA = detectionLayersA != CollisionLayers{} && noDetectionLayersA == CollisionLayers{};
358 const bool wantsDetectionB = detectionLayersB != CollisionLayers{} && noDetectionLayersB == CollisionLayers{};
359 const CollisionLayers responseLayersA = responseLayers & a.responseLayers & b.layers;
360 const CollisionLayers responseLayersB = responseLayers & b.responseLayers & a.layers;
361 const CollisionLayers noResponseLayersA = responseLayers & a.noResponseLayers & b.layers;
362 const CollisionLayers noResponseLayersB = responseLayers & b.noResponseLayers & a.layers;
363 const bool wantsResponseA = responseLayersA != CollisionLayers{} && noResponseLayersA == CollisionLayers{};
364 const bool wantsResponseB = responseLayersB != CollisionLayers{} && noResponseLayersB == CollisionLayers{};
365 const bool detectsCollision = wantsDetectionA && wantsDetectionB;
366 const bool respondsToCollision = wantsResponseA && wantsResponseB;
368 static_assert(CollisionFilterTestResult::DETECTS_COLLISION == 1 << 0);
369 passed |= static_cast<CollisionFilterTestResult::TestFlags>(detectsCollision);
371 passed |= static_cast<CollisionFilterTestResult::TestFlags>(static_cast<CollisionFilterTestResult::TestFlags>(respondsToCollision) << 1);
372 return {.passed = passed};
373 }
374};
375
376inline constexpr CollisionFilterTest CollisionFilterTest::DETECTION{
377 .detectionLayers = CollisionLayers::ALL,
378 .responseLayers{},
379};
380
382 .detectionLayers{},
383 .responseLayers = CollisionLayers::ALL,
384};
385
391template <size_t N>
392struct Ray {
393 using Unit = typename Position<N>::Unit;
394 using DimensionType = typename Unit::DimensionType;
395 using MagnitudeType = typename Unit::MagnitudeType;
396 static constexpr Unit UNIT{};
397 static constexpr DimensionType DIMENSION{};
398 static constexpr MagnitudeType MAGNITUDE{};
399
410 [[nodiscard]] static constexpr Optional<Ray> between(Position<N> origin, Position<N> destination) {
411 if (const Optional<grem::Ray<N, Scalar>> result = grem::Ray<N, Scalar>::between(origin.in(UNIT), destination.in(UNIT))) {
412 return Ray::reinterpret(*result);
413 }
414 return {};
415 }
416
424 template <typename T>
425 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr Ray reinterpret(const grem::Ray<N, T>& ray) noexcept {
426 return {
427 .origin = Position<N>::reinterpret(ray.origin),
428 .direction = Direction<N>::reinterpret(ray.direction),
429 .maxDistance = Distance::reinterpret(ray.maxDistance),
430 .directionInverse = ray.directionInverse,
431 };
432 }
433
438
445
451 Distance maxDistance = Distance::MAX;
452
459
467 template <typename OtherUnitT>
468 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::Ray<N, Scalar> in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
469 return {
470 .origin = origin.in(unit),
471 .direction = direction,
472 .maxDistance = maxDistance.in(unit),
473 .directionInverse = directionInverse,
474 };
475 }
476};
477using Ray2D = Ray<2>;
478using Ray3D = Ray<3>;
479
480template <size_t N, typename T>
481[[nodiscard]] GREM_ALWAYS_INLINE constexpr Ray<N> operator*(const grem::Ray<N, T>& ray, typename Ray<N>::Unit) {
482 return Ray<N>::reinterpret(ray);
483}
484
485template <size_t N, typename T>
486[[nodiscard]] GREM_ALWAYS_INLINE constexpr Ray<N> operator*(typename Ray<N>::Unit, const grem::Ray<N, T>& ray) {
487 return Ray<N>::reinterpret(ray);
488}
489
493struct RayMiss {
494 using Unit = typename Distance::Unit;
495 using DimensionType = typename Unit::DimensionType;
496 using MagnitudeType = typename Unit::MagnitudeType;
497 static constexpr Unit UNIT{};
498 static constexpr DimensionType DIMENSION{};
499 static constexpr MagnitudeType MAGNITUDE{};
500
508 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr RayMiss reinterpret(const grem::RayMiss& miss) noexcept {
509 (void)miss;
510 return {};
511 }
512
521 template <typename OtherUnitT>
522 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::RayMiss in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
523 (void)unit;
524 return {};
525 }
526};
527
528[[nodiscard]] GREM_ALWAYS_INLINE constexpr RayMiss operator*(const grem::RayMiss& miss, typename RayMiss::Unit) {
529 return RayMiss::reinterpret(miss);
530}
531
532[[nodiscard]] GREM_ALWAYS_INLINE constexpr RayMiss operator*(typename RayMiss::Unit, const grem::RayMiss& miss) {
533 return RayMiss::reinterpret(miss);
534}
535
541template <size_t N>
542struct RayHit {
543 using Unit = typename Position<N>::Unit;
544 using DimensionType = typename Unit::DimensionType;
545 using MagnitudeType = typename Unit::MagnitudeType;
546 static constexpr Unit UNIT{};
547 static constexpr DimensionType DIMENSION{};
548 static constexpr MagnitudeType MAGNITUDE{};
549
557 template <typename T>
558 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr RayHit reinterpret(const grem::RayHit<N, T>& hit) noexcept {
559 return {
560 .localOffset = Length<N>::reinterpret(hit.localOffset),
561 .distance = Distance::reinterpret(hit.distance),
562 .normal = Direction<N>::reinterpret(hit.normal),
563 };
564 }
565
569
577 template <typename OtherUnitT>
578 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::RayHit<N, Scalar> in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
579 return {.localOffset = localOffset.in(unit), .distance = distance.in(unit), .normal = normal};
580 }
581};
584
585template <size_t N, typename T>
586[[nodiscard]] GREM_ALWAYS_INLINE constexpr RayHit<N> operator*(const grem::RayHit<N, T>& hit, typename RayHit<N>::Unit) {
587 return RayHit<N>::reinterpret(hit);
588}
589
590template <size_t N, typename T>
591[[nodiscard]] GREM_ALWAYS_INLINE constexpr RayHit<N> operator*(typename RayHit<N>::Unit, const grem::RayHit<N, T>& hit) {
592 return RayHit<N>::reinterpret(hit);
593}
594
600template <size_t N>
602 using Unit = typename Distance::Unit;
603 using DimensionType = typename Unit::DimensionType;
604 using MagnitudeType = typename Unit::MagnitudeType;
605 static constexpr Unit UNIT{};
606 static constexpr DimensionType DIMENSION{};
607 static constexpr MagnitudeType MAGNITUDE{};
608
616 template <typename T>
617 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr RayHitInterior reinterpret(const grem::RayHitInterior<N, T>& hit) noexcept {
618 return {.localOffset = Length<N>::reinterpret(hit.localOffset)};
619 }
620
622
630 template <typename OtherUnitT>
631 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::RayHitInterior<N, Scalar> in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
632 return {.localOffset = localOffset.in(unit)};
633 }
634};
637
638template <size_t N, typename T>
642
643template <size_t N, typename T>
647
653template <size_t N>
654struct RaycastResult : Variant<RayMiss, RayHit<N>, RayHitInterior<N>> {
655 using Unit = typename Position<N>::Unit;
656 using DimensionType = typename Unit::DimensionType;
657 using MagnitudeType = typename Unit::MagnitudeType;
658 static constexpr Unit UNIT{};
659 static constexpr DimensionType DIMENSION{};
660 static constexpr MagnitudeType MAGNITUDE{};
661
670 template <typename T>
671 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr RaycastResult reinterpret(const grem::RaycastResult<N, T>& raycastResult) noexcept {
672 GREM_MATCH(raycastResult) {
673 GREM_CASE(const grem::RayMiss& miss) {
674 return RayMiss::reinterpret(miss);
675 }
676 GREM_CASE(const grem::RayHit<N, T>& hit) {
677 return RayHit<N>::reinterpret(hit);
678 }
679 GREM_CASE(const grem::RayHitInterior<N, T>& hitInterior) {
680 return RayHitInterior<N>::reinterpret(hitInterior);
681 }
682 }
683 unreachable();
684 }
685
687
696 template <typename OtherUnitT>
697 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::RaycastResult<N, Scalar> in(OtherUnitT unit) const requires(OtherUnitT::DIMENSION == LENGTH) {
698 (void)unit;
699 return match(*this)([](const auto& r) -> grem::RaycastResult<N, Scalar> { return r.in(OtherUnitT{}); });
700 }
701};
704
705template <size_t N, typename T>
707 return RaycastResult<N>::reinterpret(raycastResult);
708}
709
710template <size_t N, typename T>
712 return RaycastResult<N>::reinterpret(raycastResult);
713}
714
720template <size_t N>
721struct Plane {
722 using Unit = typename Position<N>::Unit;
723 using DimensionType = typename Unit::DimensionType;
724 using MagnitudeType = typename Unit::MagnitudeType;
725 static constexpr Unit UNIT{};
726 static constexpr DimensionType DIMENSION{};
727 static constexpr MagnitudeType MAGNITUDE{};
728
731
739 [[nodiscard]] bool operator==(const Plane& other) const = default;
740};
743
749template <size_t N>
751 using Unit = typename Position<N>::Unit;
752 using DimensionType = typename Unit::DimensionType;
753 using MagnitudeType = typename Unit::MagnitudeType;
754 static constexpr Unit UNIT{};
755 static constexpr DimensionType DIMENSION{};
756 static constexpr MagnitudeType MAGNITUDE{};
757
766 template <typename T>
767 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr LineSegment reinterpret(const grem::LineSegment<N, T>& line) noexcept {
768 return {.pointA = Position<N>::reinterpret(line.pointA), .pointB = Position<N>::reinterpret(line.pointB)};
769 }
770
773
782 template <typename OtherUnitT>
783 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::LineSegment<N, Scalar> in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
784 return {.pointA = pointA.in(unit), .pointB = pointB.in(unit)};
785 }
786
794 [[nodiscard]] bool operator==(const LineSegment& other) const = default;
795};
798
799template <size_t N, typename T>
801 return LineSegment<N>::reinterpret(line);
802}
803
804template <size_t N, typename T>
806 return LineSegment<N>::reinterpret(line);
807}
808
812template <size_t N>
813struct Box {
814 using Unit = typename Position<N>::Unit;
815 using DimensionType = typename Unit::DimensionType;
816 using MagnitudeType = typename Unit::MagnitudeType;
817 static constexpr Unit UNIT{};
818 static constexpr DimensionType DIMENSION{};
819 static constexpr MagnitudeType MAGNITUDE{};
820
828 template <typename T>
829 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr Box reinterpret(const grem::Box<N, T>& box) noexcept {
830 return {.min = Position<N>::reinterpret(box.min), .max = Position<N>::reinterpret(box.max)};
831 }
832
835
843 template <typename OtherUnitT>
844 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::Box<N, Scalar> in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
845 return {.min = min.in(unit), .max = max.in(unit)};
846 }
847
855 [[nodiscard]] bool operator==(const Box& other) const = default;
856
864 [[nodiscard]] GREM_ALWAYS_INLINE constexpr bool contains(const Position<N>& point) const noexcept {
865 return all(greaterThanEqual(point, min) & lessThan(point, max));
866 }
867
877 [[nodiscard]] GREM_ALWAYS_INLINE friend constexpr bool intersects(const Box& a, const Box& b) noexcept {
878 return all(lessThan(a.min, b.max) & greaterThan(a.max, b.min));
879 }
880
888 [[nodiscard]] GREM_ALWAYS_INLINE constexpr bool intersects(const Ray<N>& ray) const noexcept {
889 return in(UNIT).intersects(ray.in(UNIT));
890 }
891
899 [[nodiscard]] GREM_ALWAYS_INLINE constexpr RaycastResult<N> raycast(const Ray<N>& ray) const noexcept {
901 }
902
908 [[nodiscard]] GREM_ALWAYS_INLINE constexpr Box<N> getBoundingBox() const noexcept {
909 return *this;
910 }
911
921 [[nodiscard]] GREM_ALWAYS_INLINE constexpr Box<N> getExpanded(Length<N> expansion) const noexcept {
923 return {.min = min - expansion, .max = max + expansion};
924 }
925
935 [[nodiscard]] GREM_ALWAYS_INLINE constexpr Box<N> getExpanded(Distance expansion) const noexcept {
936 return getExpanded(Length<N>{expansion});
937 }
938};
939using Box2D = Box<2>;
940using Box3D = Box<3>;
941
942template <size_t N, typename T>
943[[nodiscard]] GREM_ALWAYS_INLINE constexpr Box<N> operator*(const grem::Box<N, T>& box, typename Box<N>::Unit) {
944 return Box<N>::reinterpret(box);
945}
946
947template <size_t N, typename T>
948[[nodiscard]] GREM_ALWAYS_INLINE constexpr Box<N> operator*(typename Box<N>::Unit, const grem::Box<N, T>& box) {
949 return Box<N>::reinterpret(box);
950}
951
955template <size_t N>
956struct Sphere {
957 using Unit = typename Position<N>::Unit;
958 using DimensionType = typename Unit::DimensionType;
959 using MagnitudeType = typename Unit::MagnitudeType;
960 static constexpr Unit UNIT{};
961 static constexpr DimensionType DIMENSION{};
962 static constexpr MagnitudeType MAGNITUDE{};
963
971 template <typename T>
972 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr Sphere reinterpret(const grem::Sphere<N, T>& sphere) noexcept {
973 return {.center = Position<N>::reinterpret(sphere.center), .radius = Distance::reinterpret(sphere.radius)};
974 }
975
978
986 template <typename OtherUnitT>
987 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::Sphere<N, Scalar> in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
988 return {.center = center.in(unit), .radius = radius.in(unit)};
989 }
990
998 [[nodiscard]] bool operator==(const Sphere& other) const = default;
999
1007 [[nodiscard]] GREM_ALWAYS_INLINE constexpr bool contains(const Position<N>& point) const noexcept {
1008 return distance2(center, point) < length2(radius);
1009 }
1010
1020 [[nodiscard]] GREM_ALWAYS_INLINE friend constexpr bool intersects(const Sphere& a, const Sphere& b) noexcept {
1021 return distance2(a.center, b.center) < length2(a.radius + b.radius);
1022 }
1023
1031 [[nodiscard]] GREM_ALWAYS_INLINE constexpr bool intersects(const Ray<N>& ray) const noexcept {
1032 return in(UNIT).intersects(ray.in(UNIT));
1033 }
1034
1042 [[nodiscard]] GREM_ALWAYS_INLINE constexpr RaycastResult<N> raycast(const Ray<N>& ray) const noexcept {
1044 }
1045
1051 [[nodiscard]] GREM_ALWAYS_INLINE constexpr Box<N> getBoundingBox() const noexcept {
1052 return {.min = center - Length<N>{radius}, .max = center + Length<N>{radius}};
1053 }
1054};
1058
1059template <size_t N, typename T>
1060[[nodiscard]] GREM_ALWAYS_INLINE constexpr Sphere<N> operator*(const grem::Sphere<N, T>& sphere, typename Sphere<N>::Unit) {
1061 return Sphere<N>::reinterpret(sphere);
1062}
1063
1064template <size_t N, typename T>
1065[[nodiscard]] GREM_ALWAYS_INLINE constexpr Sphere<N> operator*(typename Sphere<N>::Unit, const grem::Sphere<N, T>& sphere) {
1066 return Sphere<N>::reinterpret(sphere);
1067}
1068
1072template <size_t N>
1073struct Triangle {
1074 using Unit = typename Position<N>::Unit;
1075 using DimensionType = typename Unit::DimensionType;
1076 using MagnitudeType = typename Unit::MagnitudeType;
1077 static constexpr Unit UNIT{};
1078 static constexpr DimensionType DIMENSION{};
1079 static constexpr MagnitudeType MAGNITUDE{};
1080
1088 template <typename T>
1089 [[nodiscard]] GREM_ALWAYS_INLINE static constexpr Triangle reinterpret(const grem::Triangle<N, T>& triangle) noexcept {
1090 return {
1091 .pointA = Position<N>::reinterpret(triangle.pointA),
1092 .pointB = Position<N>::reinterpret(triangle.pointB),
1093 .pointC = Position<N>::reinterpret(triangle.pointC),
1094 };
1095 }
1096
1100
1109 template <typename OtherUnitT>
1110 [[nodiscard]] GREM_ALWAYS_INLINE constexpr grem::Triangle<N, Scalar> in(OtherUnitT unit) const noexcept requires(OtherUnitT::DIMENSION == LENGTH) {
1111 return {
1112 .pointA = pointA.in(unit),
1113 .pointB = pointB.in(unit),
1114 .pointC = pointC.in(unit),
1115 };
1116 }
1117
1125 [[nodiscard]] bool operator==(const Triangle& other) const = default;
1126
1134 [[nodiscard]] GREM_ALWAYS_INLINE constexpr bool contains(const Position<N>& point) const noexcept requires(N == 2) {
1135 return in(UNIT).contains(point.in(UNIT));
1136 }
1137
1145 [[nodiscard]] GREM_ALWAYS_INLINE constexpr bool intersects(const Ray<N>& ray) const noexcept {
1146 return in(UNIT).intersects(ray.in(UNIT));
1147 }
1148
1156 [[nodiscard]] GREM_ALWAYS_INLINE constexpr RaycastResult<N> raycast(const Ray<N>& ray) const noexcept {
1158 }
1159
1165 [[nodiscard]] GREM_ALWAYS_INLINE constexpr Box<N> getBoundingBox() const noexcept {
1166 return {.min = min(min(pointA, pointB), pointC), .max = max(max(pointA, pointB), pointC)};
1167 }
1168};
1171
1172template <size_t N, typename T>
1173[[nodiscard]] GREM_ALWAYS_INLINE constexpr Triangle<N> operator*(const grem::Triangle<N, T>& triangle, typename Triangle<N>::Unit) {
1174 return Triangle<N>::reinterpret(triangle);
1175}
1176
1177template <size_t N, typename T>
1178[[nodiscard]] GREM_ALWAYS_INLINE constexpr Triangle<N> operator*(typename Triangle<N>::Unit, const grem::Triangle<N, T>& triangle) {
1179 return Triangle<N>::reinterpret(triangle);
1180}
1181
1182namespace detail {
1183
1184template <size_t N>
1185[[nodiscard]] inline Box<N> getTransformedBoundingBox(const Transformation<N>& transformation, Length<N> halfExtents) {
1186 const Basis<N> basis = transformation.getBasis();
1187 Box<N> result{.min = transformation.getOrigin(), .max = transformation.getOrigin()};
1188 meta::forEachIndex<N>([&](auto y) -> void {
1189 meta::forEachIndex<N>([&](auto x) -> void {
1190 const Length1D a = basis[y][x] * -halfExtents[y];
1191 const Length1D b = basis[y][x] * halfExtents[y];
1192 result.min[x] += min(a, b);
1193 result.max[x] += max(a, b);
1194 });
1195 });
1196 return result;
1197}
1198
1199} // namespace detail
1200
1213template <size_t N>
1214[[nodiscard]] inline Box<N> getTransformedBoundingBox(const Transformation<N>& transformation, const Box<N>& box) {
1215 const Length<N> localCenterOffset = +midpoint(box.min, box.max);
1216 const Length<N> halfExtents = (box.max - box.min) * Scalar{0.5};
1217 return detail::getTransformedBoundingBox<N>(Transformation<N>{transformation(localCenterOffset), transformation.getBasis()}, halfExtents);
1218}
1219
1226template <typename T, size_t N>
1227concept shape = requires(const T t, const Mass mass, const Transformation<N> transformation, const Basis<N> basis, const Direction<N> direction, const Length<N> localRayOrigin,
1228 const Direction<N> localRayDirection, const Distance maxLocalRayDistance) {
1229 { t.calculateVolume() } -> convertible_to<Volume>;
1230 { t.calculatePrincipalMomentsOfInertia(mass) } -> convertible_to<PrincipalMomentsOfInertia<N>>;
1231 { t.getBoundingBox(transformation) } -> convertible_to<Optional<Box<N>>>;
1232 { t.getBoundingRadius(basis) } -> convertible_to<Optional<Distance>>;
1233 { t.getReferenceArea(basis, direction) } -> convertible_to<Optional<Area>>;
1234 { t.castLocalRay(localRayOrigin, localRayDirection, maxLocalRayDistance) } -> convertible_to<RaycastResult<N>>;
1235};
1236
1242template <typename T>
1244
1250template <typename T>
1252
1259template <typename T, size_t N>
1260concept convex_shape = shape<T, N> && requires(const T t, const Length<N> localPoint, const Direction<N> localDirection) {
1261 { t.containsLocalPoint(localPoint) } -> convertible_to<bool>;
1262 { t.getLocalSupportPointOffset(localDirection) } -> convertible_to<Length<N>>;
1263};
1264
1270template <typename T>
1272
1278template <typename T>
1280
1287template <typename T, size_t N>
1290 requires(const T t, const ConvexPolytopeVertexIndex vertexIndex, const ConvexPolytopeFaceIndex faceIndex, const Direction<N> localDirection, const Direction<N> direction) {
1291 { t.getLocalSupportPointVertexIndex(localDirection, vertexIndex) } -> convertible_to<ConvexPolytopeVertexIndex>;
1292 { t.getVertexCount() } -> convertible_to<ConvexPolytopeVertexIndex>;
1293 { t.getFaceCount() } -> convertible_to<ConvexPolytopeFaceIndex>;
1294 { t.getLocalVertexOffset(vertexIndex) } -> convertible_to<Length<N>>;
1295 { t.getLocalFaceOffset(faceIndex) } -> convertible_to<Length<N>>;
1296 { t.getLocalFaceNormal(faceIndex) } -> convertible_to<Direction<N>>;
1297 { t.getFaceIndexWithMostFittingLocalNormal(localDirection, faceIndex) } -> convertible_to<ConvexPolytopeFaceIndex>;
1298 } && (N != 3 || requires(const T t, const ConvexPolytopeVertexIndex vertexIndex, const ConvexPolytopeFaceIndex faceIndex, const ConvexPolytopeEdgeIndex edgeIndex) {
1299 { t.getEdgeCount() } -> convertible_to<ConvexPolytopeEdgeIndex>;
1300 { t.getFirstVertexIndexOfEdge(edgeIndex) } -> convertible_to<ConvexPolytopeVertexIndex>;
1301 { t.getFaceIndexOfEdge(edgeIndex) } -> convertible_to<ConvexPolytopeFaceIndex>;
1302 { t.getNextEdgeIndex(edgeIndex) } -> convertible_to<ConvexPolytopeEdgeIndex>;
1303 { t.getFirstEdgeIndexOfFace(faceIndex) } -> convertible_to<ConvexPolytopeEdgeIndex>;
1304 { t.getSomeEdgeIndexOfVertex(vertexIndex) } -> convertible_to<ConvexPolytopeEdgeIndex>;
1305 });
1306
1312template <typename T>
1314
1320template <typename T>
1322
1331inline void forEachVertexIndexInFace(const convex_polytope_shape_2d auto& shape, ConvexPolytopeFaceIndex faceIndex, auto callback) {
1332 callback(static_cast<ConvexPolytopeVertexIndex>(faceIndex));
1333 callback(static_cast<ConvexPolytopeVertexIndex>((faceIndex + 1) % shape.getFaceCount()));
1334}
1335
1344inline void forEachVertexIndexInFace(const convex_polytope_shape_3d auto& shape, ConvexPolytopeFaceIndex faceIndex, auto callback) {
1345 const ConvexPolytopeEdgeIndex firstEdgeIndex = shape.getFirstEdgeIndexOfFace(faceIndex);
1346 ConvexPolytopeEdgeIndex edgeIndex = firstEdgeIndex;
1347 do {
1348 callback(shape.getFirstVertexIndexOfEdge(edgeIndex));
1349 edgeIndex = shape.getNextEdgeIndex(edgeIndex);
1350 } while (edgeIndex != firstEdgeIndex);
1351}
1352
1362inline void forEachFaceIndexAroundVertex(const convex_polytope_shape_2d auto& shape, ConvexPolytopeVertexIndex vertexIndex, auto callback) {
1363 callback(static_cast<ConvexPolytopeFaceIndex>(vertexIndex));
1364 callback(static_cast<ConvexPolytopeFaceIndex>((vertexIndex == 0) ? shape.getFaceCount() - 1 : vertexIndex - 1));
1365}
1366
1376inline void forEachFaceIndexAroundVertex(const convex_polytope_shape_3d auto& shape, ConvexPolytopeVertexIndex vertexIndex, auto callback) {
1377 const ConvexPolytopeEdgeIndex firstEdgeIndex = shape.getSomeEdgeIndexOfVertex(vertexIndex);
1378 ConvexPolytopeEdgeIndex edgeIndex = firstEdgeIndex;
1379 do {
1380 callback(shape.getFaceIndexOfEdge(edgeIndex));
1381 edgeIndex = shape.getNextEdgeIndex(static_cast<ConvexPolytopeEdgeIndex>(edgeIndex ^ 1));
1382 } while (edgeIndex != firstEdgeIndex);
1383}
1384
1396 callback(static_cast<ConvexPolytopeFaceIndex>((vertexIndex == 0) ? shape.getFaceCount() - 1 : vertexIndex - 1));
1397 callback(static_cast<ConvexPolytopeFaceIndex>((vertexIndex + 1) % shape.getFaceCount()));
1398}
1399
1411 const ConvexPolytopeEdgeIndex firstEdgeIndex = shape.getSomeEdgeIndexOfVertex(vertexIndex);
1412 ConvexPolytopeEdgeIndex edgeIndex = firstEdgeIndex;
1413 do {
1414 const ConvexPolytopeEdgeIndex twinEdgeIndex = static_cast<ConvexPolytopeEdgeIndex>(edgeIndex ^ 1);
1415 const ConvexPolytopeVertexIndex twinVertexIndex = shape.getFirstVertexIndexOfEdge(twinEdgeIndex);
1416 callback(twinVertexIndex);
1417 edgeIndex = shape.getNextEdgeIndex(twinEdgeIndex);
1418 } while (edgeIndex != firstEdgeIndex);
1419}
1420
1426template <size_t N>
1430 return {};
1431 }
1432
1435 (void)mass;
1436 return {};
1437 }
1438
1440 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
1441 return Box<N>{.min = transformation.getOrigin(), .max = transformation.getOrigin()};
1442 }
1443
1446 (void)basis;
1447 return Distance{};
1448 }
1449
1451 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const {
1452 (void)basis;
1453 (void)direction;
1454 return Area{};
1455 }
1456
1458 [[nodiscard]] GREM_ALWAYS_INLINE RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const {
1459 (void)localRayOrigin;
1460 (void)localRayDirection;
1461 (void)maxLocalRayDistance;
1462 return RayMiss{};
1463 }
1464
1466 [[nodiscard]] GREM_ALWAYS_INLINE bool containsLocalPoint(Length<N> localPoint) const {
1467 (void)localPoint;
1468 return false;
1469 }
1470
1473 (void)localDirection;
1474 return {};
1475 }
1476};
1477extern template struct PointShape<2>;
1478extern template struct PointShape<3>;
1481static_assert(convex_shape_2d<PointShape2D>);
1482static_assert(convex_shape_3d<PointShape3D>);
1483
1489template <size_t N>
1492
1496 return {};
1497 }
1498
1502 (void)mass;
1503 return {};
1504 }
1505
1507 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
1509 const Length<N> halfVectorA = transformation.getRelative(Y_AXIS<N> * -halfLength);
1510 const Length<N> halfVectorB = transformation.getRelative(Y_AXIS<N> * halfLength);
1511 return Box<N>{.min = transformation.getOrigin() - min(halfVectorA, halfVectorB), .max = transformation.getOrigin() + max(halfVectorA, halfVectorB)};
1512 }
1513
1516 return length(basis[Y] * halfLength);
1517 }
1518
1520 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const {
1521 (void)basis;
1522 (void)direction;
1523 return Area{};
1524 }
1525
1527 [[nodiscard]] GREM_ALWAYS_INLINE RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const {
1528 (void)localRayOrigin;
1529 (void)localRayDirection;
1530 (void)maxLocalRayDistance;
1531 return RayMiss{};
1532 }
1533
1535 [[nodiscard]] GREM_ALWAYS_INLINE bool containsLocalPoint(Length<N> localPoint) const {
1536 (void)localPoint;
1537 return false;
1538 }
1539
1543 const Length<N> halfLineVector = Y_AXIS<N> * halfLength;
1544 return (localDirection.getY() >= 0) ? halfLineVector : -halfLineVector;
1545 }
1546};
1547extern template struct LineSegmentShape<2>;
1548extern template struct LineSegmentShape<3>;
1553
1559template <size_t N>
1563 return {};
1564 }
1565
1568 (void)mass;
1569 return {};
1570 }
1571
1573 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
1574 (void)transformation;
1575 return {};
1576 }
1577
1580 (void)basis;
1581 return {};
1582 }
1583
1585 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const {
1586 (void)basis;
1587 (void)direction;
1588 return {};
1589 }
1590
1592 [[nodiscard]] GREM_ALWAYS_INLINE RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const {
1593 (void)localRayOrigin;
1594 (void)localRayDirection;
1595 (void)maxLocalRayDistance;
1596 return RayMiss{};
1597 }
1598
1600 [[nodiscard]] GREM_ALWAYS_INLINE bool containsLocalPoint(Length<N> localPoint) const {
1601 (void)localPoint;
1602 return false;
1603 }
1604
1607 return Y_AXIS<N> * ((localDirection.getY() >= 0) ? Distance::MAX : Distance::MIN);
1608 }
1609};
1610extern template struct InfiniteLineShape<2>;
1611extern template struct InfiniteLineShape<3>;
1616
1622template <size_t N>
1626 return {};
1627 }
1628
1631 (void)mass;
1632 return {};
1633 }
1634
1636 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
1637 (void)transformation;
1638 return {};
1639 }
1640
1643 (void)basis;
1644 return {};
1645 }
1646
1648 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const {
1649 (void)basis;
1650 (void)direction;
1651 return {};
1652 }
1653
1655 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
1656};
1657extern template struct InfiniteHalfSpaceShape<2>;
1658extern template struct InfiniteHalfSpaceShape<3>;
1663
1671 return {};
1672 }
1673
1676 (void)mass;
1677 return {};
1678 }
1679
1681 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box3D> getBoundingBox(const Transformation3D& transformation) const {
1682 (void)transformation;
1683 return {};
1684 }
1685
1688 (void)basis;
1689 return {};
1690 }
1691
1693 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis3D& basis, Direction3D direction) const {
1694 (void)basis;
1695 (void)direction;
1696 return {};
1697 }
1698
1700 [[nodiscard]] GREM_API(physics) RaycastResult3D castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const;
1701};
1702static_assert(shape_3d<InfinitePlaneShape3D>);
1703
1709template <size_t N>
1710struct BoxShape {
1712
1714 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
1715
1718
1720 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
1722 return detail::getTransformedBoundingBox<N>(transformation, halfExtents);
1723 }
1724
1727 return length(basis * halfExtents);
1728 }
1729
1731 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
1732
1734 [[nodiscard]] GREM_ALWAYS_INLINE RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const {
1736 return Box<N>{.min = -halfExtents, .max = halfExtents}.raycast(Ray<N>{.origin = localRayOrigin, .direction = localRayDirection, .maxDistance = maxLocalRayDistance});
1737 }
1738
1740 [[nodiscard]] GREM_ALWAYS_INLINE bool containsLocalPoint(Length<N> localPoint) const {
1741 return Box<N>{.min = -halfExtents, .max = halfExtents}.contains(localPoint);
1742 }
1743
1747 return copysign(halfExtents, localDirection);
1748 }
1749
1751 [[nodiscard]] GREM_API(physics) ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction<N> localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const;
1752
1755 if constexpr (N == 2) {
1756 return 4;
1757 } else {
1758 return 8;
1759 }
1760 }
1761
1764 if constexpr (N == 2) {
1765 return 4;
1766 } else {
1767 return 6;
1768 }
1769 }
1770
1772 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount() const requires(N == 3) {
1773 return 24;
1774 }
1775
1777 [[nodiscard]] GREM_API(physics) Length<N> getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const;
1778
1780 [[nodiscard]] GREM_API(physics) Length<N> getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const;
1781
1783 [[nodiscard]] GREM_API(physics) Direction<N> getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const;
1784
1786 [[nodiscard]] GREM_API(physics) ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction<N> localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const;
1787
1789 [[nodiscard]] GREM_API(physics) ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
1790
1792 [[nodiscard]] GREM_API(physics) ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
1793
1795 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
1796
1798 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const requires(N == 3);
1799
1801 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const requires(N == 3);
1802};
1803extern template struct BoxShape<2>;
1804extern template struct BoxShape<3>;
1810
1816template <size_t N>
1819
1822 return BoxShape<N>{.halfExtents{halfExtent}}.calculateVolume();
1823 }
1824
1829
1831 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
1832 return BoxShape<N>{.halfExtents{halfExtent}}.getBoundingBox(transformation);
1833 }
1834
1837 return BoxShape<N>{.halfExtents{halfExtent}}.getBoundingRadius(basis);
1838 }
1839
1841 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const {
1842 return BoxShape<N>{.halfExtents{halfExtent}}.getReferenceArea(basis, direction);
1843 }
1844
1846 [[nodiscard]] GREM_ALWAYS_INLINE RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const {
1847 return BoxShape<N>{.halfExtents{halfExtent}}.castLocalRay(localRayOrigin, localRayDirection, maxLocalRayDistance);
1848 }
1849
1851 [[nodiscard]] GREM_ALWAYS_INLINE bool containsLocalPoint(Length<N> localPoint) const {
1852 return BoxShape<N>{.halfExtents{halfExtent}}.containsLocalPoint(localPoint);
1853 }
1854
1857 return BoxShape<N>{.halfExtents{halfExtent}}.getLocalSupportPointOffset(localDirection);
1858 }
1859
1862 ConvexPolytopeVertexIndex searchStartVertexIndex) const {
1863 return BoxShape<N>{.halfExtents{halfExtent}}.getLocalSupportPointVertexIndex(localDirection, searchStartVertexIndex);
1864 }
1865
1868 if constexpr (N == 2) {
1869 return 4;
1870 } else {
1871 return 8;
1872 }
1873 }
1874
1877 if constexpr (N == 2) {
1878 return 4;
1879 } else {
1880 return 6;
1881 }
1882 }
1883
1885 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount() const requires(N == 3) {
1886 return 24;
1887 }
1888
1891 return BoxShape<N>{.halfExtents{halfExtent}}.getLocalVertexOffset(vertexIndex);
1892 }
1893
1896 return BoxShape<N>{.halfExtents{halfExtent}}.getLocalFaceOffset(faceIndex);
1897 }
1898
1901 return BoxShape<N>{.halfExtents{halfExtent}}.getLocalFaceNormal(faceIndex);
1902 }
1903
1906 ConvexPolytopeFaceIndex searchStartFaceIndex) const {
1907 return BoxShape<N>{.halfExtents{halfExtent}}.getFaceIndexWithMostFittingLocalNormal(localDirection, searchStartFaceIndex);
1908 }
1909
1912 return BoxShape3D{.halfExtents{halfExtent}}.getFirstVertexIndexOfEdge(edgeIndex);
1913 }
1914
1917 return BoxShape3D{.halfExtents{halfExtent}}.getFaceIndexOfEdge(edgeIndex);
1918 }
1919
1922 return BoxShape3D{.halfExtents{halfExtent}}.getNextEdgeIndex(edgeIndex);
1923 }
1924
1927 return BoxShape3D{.halfExtents{halfExtent}}.getFirstEdgeIndexOfFace(faceIndex);
1928 }
1929
1932 return BoxShape3D{.halfExtents{halfExtent}}.getSomeEdgeIndexOfVertex(vertexIndex);
1933 }
1934};
1935extern template struct CubeShape<2>;
1936extern template struct CubeShape<3>;
1942
1948template <size_t N>
1951
1953 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
1954
1957
1959 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
1960 return BoxShape<N>{.halfExtents = radii}.getBoundingBox(transformation);
1961 }
1962
1965 return maxComponent(basis.getScale() * radii);
1966 }
1967
1969 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
1970
1972 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
1973
1975 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length<N> localPoint) const;
1976
1978 [[nodiscard]] GREM_API(physics) Length<N> getLocalSupportPointOffset(Direction<N> localDirection) const;
1979};
1980extern template struct EllipsoidShape<2>;
1981extern template struct EllipsoidShape<3>;
1987
1993template <size_t N>
1996
1999 return EllipsoidShape<N>{.radii{radius}}.calculateVolume();
2000 }
2001
2006
2008 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
2010 const Position<N> center = transformation.getOrigin();
2011 const Distance maxTransformedRadius = radius * sqrt(maxComponent(transformation.getBasis().getScale2()));
2012 return Box<N>{.min = center - Length<N>{maxTransformedRadius}, .max = center + Length<N>{maxTransformedRadius}};
2013 }
2014
2017 return EllipsoidShape<N>{.radii{radius}}.getBoundingRadius(basis);
2018 }
2019
2021 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const {
2022 return EllipsoidShape<N>{.radii{radius}}.getReferenceArea(basis, direction);
2023 }
2024
2026 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
2027
2029 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length<N> localPoint) const;
2030
2032 [[nodiscard]] GREM_API(physics) Length<N> getLocalSupportPointOffset(Direction<N> localDirection) const;
2033};
2034extern template struct SphereShape<2>;
2035extern template struct SphereShape<3>;
2038static_assert(convex_shape_2d<SphereShape2D>);
2039static_assert(convex_shape_3d<SphereShape3D>);
2041
2047template <size_t N>
2051
2053 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2054
2057
2059 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
2062 const Position<N> pointA = transformation(-Y_AXIS<N> * halfLength);
2063 const Position<N> pointB = transformation(Y_AXIS<N> * halfLength);
2064 const Distance maxTransformedRadius = radius * sqrt(maxComponent(transformation.getBasis().getScale2()));
2065 const Box<N> boxA{.min = pointA - Length<N>{maxTransformedRadius}, .max = pointA + Length<N>{maxTransformedRadius}};
2066 const Box<N> boxB{.min = pointB - Length<N>{maxTransformedRadius}, .max = pointB + Length<N>{maxTransformedRadius}};
2067 return Box<N>{.min = min(boxA.min, boxB.min), .max = max(boxA.max, boxB.max)};
2068 }
2069
2074 return BoxShape<N>{.halfExtents = Y_AXIS<N> * halfLength + Length<N>{radius}}.getBoundingRadius(basis);
2075 }
2076
2078 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
2079
2081 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
2082
2084 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length<N> localPoint) const;
2085
2087 [[nodiscard]] GREM_API(physics) Length<N> getLocalSupportPointOffset(Direction<N> localDirection) const;
2088};
2089extern template struct CapsuleShape<2>;
2090extern template struct CapsuleShape<3>;
2093static_assert(convex_shape_2d<CapsuleShape2D>);
2094static_assert(convex_shape_3d<CapsuleShape3D>);
2096
2102template <size_t N>
2107
2109 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2110
2113
2122
2131
2133 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
2134
2136 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
2137
2139 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length<N> localPoint) const;
2140
2142 [[nodiscard]] GREM_API(physics) Length<N> getLocalSupportPointOffset(Direction<N> localDirection) const;
2143};
2144extern template struct TaperedCapsuleShape<2>;
2145extern template struct TaperedCapsuleShape<3>;
2150
2158
2160 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2161
2164
2166 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box3D> getBoundingBox(const Transformation3D& transformation) const {
2169 return BoxShape3D{.halfExtents{radius, halfLength, radius}}.getBoundingBox(transformation);
2170 }
2171
2176 return BoxShape3D{.halfExtents{radius, halfLength, radius}}.getBoundingRadius(basis);
2177 }
2178
2180 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis3D& basis, Direction3D direction) const;
2181
2183 [[nodiscard]] GREM_API(physics) RaycastResult3D castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const;
2184
2186 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length3D localPoint) const;
2187
2189 [[nodiscard]] GREM_API(physics) Length3D getLocalSupportPointOffset(Direction3D localDirection) const;
2190};
2192
2200
2202 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2203
2206
2208 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box3D> getBoundingBox(const Transformation3D& transformation) const {
2213 const Distance maxRadius = max(bottomRadius, topRadius);
2214 return BoxShape3D{.halfExtents{maxRadius, halfLength, maxRadius}}.getBoundingBox(transformation);
2215 }
2216
2223 const Distance maxRadius = max(bottomRadius, topRadius);
2224 return BoxShape3D{.halfExtents{maxRadius, halfLength, maxRadius}}.getBoundingRadius(basis);
2225 }
2226
2228 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis3D& basis, Direction3D direction) const;
2229
2231 [[nodiscard]] GREM_API(physics) RaycastResult3D castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const;
2232
2234 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length3D localPoint) const;
2235
2237 [[nodiscard]] GREM_API(physics) Length3D getLocalSupportPointOffset(Direction3D localDirection) const;
2238};
2240
2246template <size_t N>
2248public:
2252
2259 : polytope(std::move(polytope)) {
2260 GREM_ASSERT(this->polytope);
2261 }
2262
2276
2283 return polytope;
2284 }
2285
2287 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2288
2291
2293 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
2294 return getTransformedBoundingBox<N>(transformation, polytope->getBoundingBox() * Box<N>::UNIT);
2295 }
2296
2299 return sqrt(maxComponent(basis.getScale2())) * polytope->getBoundingRadius() * Distance::UNIT;
2300 }
2301
2303 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
2304
2306 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
2307
2309 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length<N> localPoint) const;
2310
2312 [[nodiscard]] GREM_API(physics) Length<N> getLocalSupportPointOffset(Direction<N> localDirection) const;
2313
2315 [[nodiscard]] GREM_API(physics) ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction<N> localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const;
2316
2319 return static_cast<ConvexPolytopeVertexIndex>(polytope->getVertices().size());
2320 }
2321
2324 return static_cast<ConvexPolytopeFaceIndex>(polytope->getFaces().size());
2325 }
2326
2328 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount() const requires(N == 3) {
2329 if constexpr (N == 3) {
2330 return static_cast<ConvexPolytopeEdgeIndex>(polytope->getEdges().size());
2331 } else {
2332 unreachable();
2333 }
2334 }
2335
2337 [[nodiscard]] GREM_API(physics) Length<N> getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const;
2338
2340 [[nodiscard]] GREM_API(physics) Length<N> getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const;
2341
2343 [[nodiscard]] GREM_API(physics) Direction<N> getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const;
2344
2346 [[nodiscard]] GREM_API(physics) ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction<N> localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const;
2347
2349 [[nodiscard]] GREM_API(physics) ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
2350
2352 [[nodiscard]] GREM_API(physics) ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
2353
2355 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
2356
2358 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const requires(N == 3);
2359
2361 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const requires(N == 3);
2362
2363private:
2365};
2366extern template class ConvexPolytopeShape<2>;
2367extern template class ConvexPolytopeShape<3>;
2372
2378template <size_t N>
2380public:
2384
2391 : mesh(std::move(mesh)) {
2392 GREM_ASSERT(this->mesh);
2393 }
2394
2408
2423
2430 return mesh;
2431 }
2432
2434 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2435
2438
2440 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
2441 return getTransformedBoundingBox<N>(transformation, mesh->getBoundingBox() * Box<N>::UNIT);
2442 }
2443
2446 return sqrt(maxComponent(basis.getScale2())) * mesh->getBoundingRadius() * Distance::UNIT;
2447 }
2448
2450 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
2451
2453 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
2454
2455private:
2457};
2458extern template class TriangleMeshShape<2>;
2459extern template class TriangleMeshShape<3>;
2462static_assert(shape_2d<TriangleMeshShape2D>);
2463static_assert(shape_3d<TriangleMeshShape3D>);
2464
2470template <size_t N>
2471struct Shape;
2472
2478template <size_t N>
2484
2486 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2487
2490
2492 [[nodiscard]] GREM_API(physics) Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const;
2493
2495 [[nodiscard]] GREM_API(physics) Optional<Distance> getBoundingRadius(const Basis<N>& basis) const;
2496
2498 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
2499
2501 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
2502};
2503extern template struct LocallyTransformedShape<2>;
2504extern template struct LocallyTransformedShape<3>;
2509
2515template <size_t N>
2516struct SubCollider;
2519
2525template <size_t N>
2527public:
2534 : subColliders(std::move(subColliders))
2535 , boundingBox(calculateCompoundBoundingBox(getSubColliders()))
2536 , boundingRadius(calculateCompoundBoundingRadius(getSubColliders())) {
2537 GREM_ASSERT(this->subColliders);
2538 }
2539
2549 GREM_API(physics) explicit CompoundColliderShape(Span<const SubCollider<N>> subColliders);
2550
2557 return Span<const SubCollider<N>>{subColliders.get(), subColliders.size()};
2558 }
2559
2561 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
2562
2565
2567 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
2568 if (!boundingBox) {
2569 return {};
2570 }
2571 return getTransformedBoundingBox<N>(transformation, *boundingBox);
2572 }
2573
2576 if (!boundingRadius) {
2577 return {};
2578 }
2579 return sqrt(maxComponent(basis.getScale2())) * *boundingRadius;
2580 }
2581
2583 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
2584
2586 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
2587
2588private:
2589 [[nodiscard]] GREM_API(physics) static Optional<Box<N>> calculateCompoundBoundingBox(Span<const SubCollider<N>> subColliders) noexcept;
2590 [[nodiscard]] GREM_API(physics) static Optional<Distance> calculateCompoundBoundingRadius(Span<const SubCollider<N>> subColliders) noexcept;
2591
2592 SharedPointer<SubCollider<N>[]> subColliders;
2593 Optional<Box<N>> boundingBox;
2594 Optional<Distance> boundingRadius;
2595};
2596extern template class CompoundColliderShape<2>;
2597extern template class CompoundColliderShape<3>;
2602
2606template <>
2611
2612 using Variant::Variant;
2613
2620 [[nodiscard]] bool isConvexShapeType() const {
2621 return match(*this)([&](const convex_shape_2d auto&) -> bool { return true; }, [&](const auto&) -> bool { return false; });
2622 }
2623
2630 [[nodiscard]] bool isConvexPolytopeShapeType() const {
2631 return match(*this)([&](const convex_polytope_shape_2d auto&) -> bool { return true; }, [&](const auto&) -> bool { return false; });
2632 }
2633
2639 [[nodiscard]] Volume calculateVolume() const;
2640
2650
2662 [[nodiscard]] Optional<Box2D> getBoundingBox(const Transformation2D& transformation) const;
2663
2673 [[nodiscard]] Optional<Distance> getBoundingRadius(const Basis2D& basis) const;
2674
2686 [[nodiscard]] Optional<Area> getReferenceArea(const Basis2D& basis, Direction2D direction) const;
2687
2700 [[nodiscard]] RaycastResult2D castLocalRay(Length2D localRayOrigin, Direction2D localRayDirection, Distance maxLocalRayDistance) const;
2701};
2702
2706template <>
2707struct Shape<3>
2708 : Variant<PointShape3D, LineSegmentShape3D, InfiniteLineShape3D, InfiniteHalfSpaceShape3D, InfinitePlaneShape3D, BoxShape3D, CubeShape3D, EllipsoidShape3D, SphereShape3D,
2709 CapsuleShape3D, TaperedCapsuleShape3D, CylinderShape3D, TaperedCylinderShape3D, ConvexPolytopeShape3D, TriangleMeshShape3D, LocallyTransformedShape3D,
2710 CompoundColliderShape3D> {
2712
2713 using Variant::Variant;
2714
2721 [[nodiscard]] bool isConvexShapeType() const {
2722 return match(*this)([&](const convex_shape_3d auto&) -> bool { return true; }, [&](const auto&) -> bool { return false; });
2723 }
2724
2731 [[nodiscard]] bool isConvexPolytopeShapeType() const {
2732 return match(*this)([&](const convex_polytope_shape_3d auto&) -> bool { return true; }, [&](const auto&) -> bool { return false; });
2733 }
2734
2740 [[nodiscard]] Volume calculateVolume() const;
2741
2751
2763 [[nodiscard]] Optional<Box3D> getBoundingBox(const Transformation3D& transformation) const;
2764
2774 [[nodiscard]] Optional<Distance> getBoundingRadius(const Basis3D& basis) const;
2775
2787 [[nodiscard]] Optional<Area> getReferenceArea(const Basis3D& basis, Direction3D direction) const;
2788
2801 [[nodiscard]] RaycastResult3D castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const;
2802};
2805
2811template <size_t N>
2818
2819template <size_t N>
2826
2832template <size_t N>
2834public:
2837
2839 using index_type = value_type::index_type;
2840
2847 template <typename T>
2848 GREM_ALWAYS_INLINE constexpr ShapeView(const T& shape) noexcept requires(same_as<T, Shape<N>>)
2849 : shapeData(match(shape)([](const auto& s) -> const void* { return &s; }))
2850 , shapeTypeIndex(shape.index()) {}
2851
2858 template <typename T>
2860 : shapeData(&shape)
2861 , shapeTypeIndex(variant_index_v<T, value_type>) {}
2862
2869 [[nodiscard]] GREM_ALWAYS_INLINE constexpr const void* data() const noexcept {
2870 return shapeData;
2871 }
2872
2878 [[nodiscard]] GREM_ALWAYS_INLINE constexpr index_type index() const noexcept {
2879 return shapeTypeIndex;
2880 }
2881
2888 [[nodiscard]] constexpr bool valueless_by_exception() const noexcept {
2889 return shapeTypeIndex == Shape<N>::value_type::npos;
2890 }
2891
2902 template <typename T>
2903 [[nodiscard]] constexpr bool is() const noexcept requires(variant_has_alternative_v<T, value_type>) {
2904 return shapeTypeIndex == variant_index_v<T, value_type>;
2905 }
2906
2931 template <typename T>
2932 [[nodiscard]] constexpr const T& as() const& noexcept requires(variant_has_alternative_v<T, value_type>) {
2933 GREM_ASSERT(is<T>());
2934 return *static_cast<const T*>(shapeData);
2935 }
2936
2951 template <typename T>
2952 [[nodiscard]] constexpr const T& get() const& requires(variant_has_alternative_v<T, value_type>) {
2953 if (!is<T>()) {
2954 throw BadVariantAccess{};
2955 }
2956 return as<T>();
2957 }
2958
2973 template <typename T>
2974 [[nodiscard]] constexpr const T* get_if() const noexcept requires(variant_has_alternative_v<T, value_type>) {
2975 return (is<T>()) ? &as<T>() : nullptr;
2976 }
2977
2984 [[nodiscard]] bool isConvexShapeType() const noexcept;
2985
2992 [[nodiscard]] bool isConvexPolytopeShapeType() const noexcept;
2993
2999 [[nodiscard]] GREM_API(physics) Volume calculateVolume() const;
3000
3010
3022 [[nodiscard]] GREM_API(physics) Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const;
3023
3033 [[nodiscard]] GREM_API(physics) Optional<Distance> getBoundingRadius(const Basis<N>& basis) const;
3034
3046 [[nodiscard]] GREM_API(physics) Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const;
3047
3060 [[nodiscard]] GREM_API(physics) RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const;
3061
3062private:
3063 const void* shapeData;
3064 index_type shapeTypeIndex;
3065};
3066extern template class ShapeView<2>;
3067extern template class ShapeView<3>;
3070static_assert(shape_2d<ShapeView2D>);
3071static_assert(shape_3d<ShapeView3D>);
3072
3088template <typename Visitor, size_t N>
3089constexpr decltype(auto) visit(Visitor&& visitor, ShapeView<N> shape) { // NOLINT(cppcoreguidelines-missing-std-forward)
3090 return Shape<N>::value_type::visitIndex(shape.index(), [&]<typename T>(std::in_place_type_t<T>) -> decltype(auto) { return visitor(*static_cast<const T*>(shape.data())); });
3091}
3092
3094 return ShapeView2D{*this}.calculateVolume();
3095}
3096
3098 return ShapeView2D{*this}.calculatePrincipalMomentsOfInertia(mass);
3099}
3100
3101inline Optional<Box2D> Shape<2>::getBoundingBox(const Transformation2D& transformation) const {
3102 return ShapeView2D{*this}.getBoundingBox(transformation);
3103}
3104
3106 return ShapeView2D{*this}.getBoundingRadius(basis);
3107}
3108
3109inline Optional<Area> Shape<2>::getReferenceArea(const Basis2D& basis, Direction2D direction) const {
3110 return ShapeView2D{*this}.getReferenceArea(basis, direction);
3111}
3112
3113inline RaycastResult2D Shape<2>::castLocalRay(Length2D localRayOrigin, Direction2D localRayDirection, Distance maxLocalRayDistance) const {
3114 return ShapeView2D{*this}.castLocalRay(localRayOrigin, localRayDirection, maxLocalRayDistance);
3115}
3116
3118 return ShapeView3D{*this}.calculateVolume();
3119}
3120
3122 return ShapeView3D{*this}.calculatePrincipalMomentsOfInertia(mass);
3123}
3124
3125inline Optional<Box3D> Shape<3>::getBoundingBox(const Transformation3D& transformation) const {
3126 return ShapeView3D{*this}.getBoundingBox(transformation);
3127}
3128
3130 return ShapeView3D{*this}.getBoundingRadius(basis);
3131}
3132
3133inline Optional<Area> Shape<3>::getReferenceArea(const Basis3D& basis, Direction3D direction) const {
3134 return ShapeView3D{*this}.getReferenceArea(basis, direction);
3135}
3136
3137inline RaycastResult3D Shape<3>::castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const {
3138 return ShapeView3D{*this}.castLocalRay(localRayOrigin, localRayDirection, maxLocalRayDistance);
3139}
3140
3146template <size_t N>
3147class ConvexShapeView : public ShapeView<N> {
3148public:
3149 using typename ShapeView<N>::value_type;
3150 using typename ShapeView<N>::index_type;
3151
3158 template <typename T>
3159 GREM_ALWAYS_INLINE constexpr explicit ConvexShapeView(const T& shape) noexcept requires(same_as<T, Shape<N>>)
3160 : ShapeView<N>(shape) {}
3161
3168 template <typename T>
3171
3180
3191 [[nodiscard]] GREM_API(physics) bool containsLocalPoint(Length<N> localPoint) const;
3192
3205 [[nodiscard]] GREM_API(physics) Length<N> getLocalSupportPointOffset(Direction<N> localDirection) const;
3206};
3207extern template class ConvexShapeView<2>;
3208extern template class ConvexShapeView<3>;
3213
3219template <size_t N>
3221public:
3222 using typename ShapeView<N>::value_type;
3223 using typename ShapeView<N>::index_type;
3224
3231 template <typename T>
3232 GREM_ALWAYS_INLINE constexpr explicit ConvexPolytopeShapeView(const T& shape) noexcept requires(same_as<T, Shape<N>>)
3233 : ConvexShapeView<N>(shape) {}
3234
3241 template <typename T>
3245
3254
3270 [[nodiscard]] GREM_API(physics) ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction<N> localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const;
3271
3281 [[nodiscard]] GREM_API(physics) ConvexPolytopeVertexIndex getVertexCount() const;
3282
3292 [[nodiscard]] GREM_API(physics) ConvexPolytopeFaceIndex getFaceCount() const;
3293
3303 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getEdgeCount() const requires(N == 3);
3304
3317 [[nodiscard]] GREM_API(physics) Length<N> getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const;
3318
3330 [[nodiscard]] GREM_API(physics) Length<N> getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const;
3331
3345 [[nodiscard]] GREM_API(physics) Direction<N> getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const;
3346
3362 [[nodiscard]] GREM_API(physics) ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction<N> localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const;
3363
3375 [[nodiscard]] GREM_API(physics) ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
3376
3388 [[nodiscard]] GREM_API(physics) ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
3389
3405 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3);
3406
3418 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const requires(N == 3);
3419
3431 [[nodiscard]] GREM_API(physics) ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const requires(N == 3);
3432};
3433extern template class ConvexPolytopeShapeView<2>;
3434extern template class ConvexPolytopeShapeView<3>;
3439
3445template <size_t N>
3449
3456 GREM_ALWAYS_INLINE constexpr ColliderView(const Collider<N>& collider) noexcept
3457 : shape(collider.shape)
3458 , filter(collider.filter) {}
3459
3470};
3471extern template struct ColliderView<2>;
3472extern template struct ColliderView<3>;
3475
3476namespace detail {
3477
3478template <size_t N>
3479struct TriangleShape {
3480 Length<N> pointA;
3481 Length<N> pointB;
3482 Length<N> pointC;
3483
3484 [[nodiscard]] GREM_ALWAYS_INLINE Volume calculateVolume() const {
3485 return {};
3486 }
3487
3489 (void)mass;
3490 return {};
3491 }
3492
3493 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Box<N>> getBoundingBox(const Transformation<N>& transformation) const {
3494 const Position<N> transformedPointA = transformation(pointA);
3495 const Position<N> transformedPointB = transformation(pointB);
3496 const Position<N> transformedPointC = transformation(pointC);
3497 return {.min = min(min(transformedPointA, transformedPointB), transformedPointC), .max = max(max(transformedPointA, transformedPointB), transformedPointC)};
3498 }
3499
3500 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Distance> getBoundingRadius(const Basis<N>& basis) const {
3501 const Length<N> offsetA = basis * pointA;
3502 const Length<N> offsetB = basis * pointB;
3503 const Length<N> offsetC = basis * pointC;
3504 return sqrt(max(max(length2(offsetA), length2(offsetB)), length2(offsetC)));
3505 }
3506
3507 [[nodiscard]] GREM_ALWAYS_INLINE Optional<Area> getReferenceArea(const Basis<N>& basis, Direction<N> direction) const {
3508 const Length<N> offsetA = basis * pointA;
3509 const Length<N> offsetB = basis * pointB;
3510 const Length<N> offsetC = basis * pointC;
3511 return Scalar{0.5} * abs(dot(cross(offsetB - offsetA, offsetC - offsetA), direction));
3512 }
3513
3514 [[nodiscard]] GREM_ALWAYS_INLINE RaycastResult<N> castLocalRay(Length<N> localRayOrigin, Direction<N> localRayDirection, Distance maxLocalRayDistance) const {
3515 return Triangle<N>{.pointA = pointA, .pointB = pointB, .pointC = pointC}.raycast(
3516 Ray<N>{.origin = localRayOrigin, .direction = localRayDirection, .maxDistance = maxLocalRayDistance});
3517 }
3518
3519 [[nodiscard]] GREM_ALWAYS_INLINE bool containsLocalPoint(Length<N> localPoint) const {
3520 (void)localPoint;
3521 return false;
3522 }
3523
3524 [[nodiscard]] GREM_ALWAYS_INLINE Length<N> getLocalSupportPointOffset(Direction<N> localDirection) const {
3525 return getLocalVertexOffset(getLocalSupportPointVertexIndex(localDirection, 0));
3526 }
3527
3528 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction<N> localDirection,
3529 ConvexPolytopeVertexIndex searchStartVertexIndex) const {
3530 (void)searchStartVertexIndex;
3531 ConvexPolytopeVertexIndex farthestVertexIndex = 0;
3532 Length1D farthestSignedDistance = dot(pointA, localDirection);
3533 const Length1D signedDistanceB = dot(pointB, localDirection);
3534 if (signedDistanceB > farthestSignedDistance) {
3535 farthestVertexIndex = 1;
3536 farthestSignedDistance = signedDistanceB;
3537 }
3538 const Length1D signedDistanceC = dot(pointC, localDirection);
3539 if (signedDistanceC > farthestSignedDistance) {
3540 farthestVertexIndex = 2;
3541 farthestSignedDistance = signedDistanceC;
3542 }
3543 return farthestVertexIndex;
3544 }
3545
3546 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getVertexCount() const {
3547 return 3;
3548 }
3549
3550 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceCount() const {
3551 if constexpr (N == 2) {
3552 return 3;
3553 } else {
3554 return 2;
3555 }
3556 }
3557
3558 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount() const requires(N == 3) {
3559 return 6;
3560 }
3561
3562 [[nodiscard]] GREM_ALWAYS_INLINE Length<N> getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const {
3563 GREM_ASSERT(vertexIndex < getVertexCount());
3564 switch (vertexIndex) {
3565 case 0: return pointA;
3566 case 1: return pointB;
3567 case 2: return pointC;
3568 default: break;
3569 }
3570 unreachable();
3571 }
3572
3573 [[nodiscard]] GREM_ALWAYS_INLINE Length<N> getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const {
3574 GREM_ASSERT(faceIndex < getFaceCount());
3575 if constexpr (N == 2) {
3576 return getLocalVertexOffset(static_cast<ConvexPolytopeVertexIndex>(faceIndex));
3577 } else {
3578 return (faceIndex == 0) ? pointA : pointB;
3579 }
3580 }
3581
3582 [[nodiscard]] GREM_ALWAYS_INLINE Direction<N> getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const {
3583 if constexpr (N == 2) {
3584 const Length2D a = getLocalVertexOffset(static_cast<ConvexPolytopeVertexIndex>(faceIndex));
3585 const Length2D b = getLocalVertexOffset(static_cast<ConvexPolytopeVertexIndex>(faceIndex + 1) % getVertexCount());
3586 const Length2D difference = b - a;
3587 return normalize(rotate90DegreesClockwise(difference));
3588 } else {
3589 const Direction3D normal = normalize(cross(pointB - pointA, pointC - pointA));
3590 return flipSignIf(normal, faceIndex != 0);
3591 }
3592 }
3593
3594 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction<N> localDirection,
3595 ConvexPolytopeFaceIndex searchStartFaceIndex) const {
3596 (void)searchStartFaceIndex;
3597 if constexpr (N == 2) {
3598 ConvexPolytopeFaceIndex mostFittingFaceIndex = 0;
3599 Scale1D largestDotProduct = dot(localDirection, getLocalFaceNormal(0));
3600 const Scale1D dotProductB = dot(localDirection, getLocalFaceNormal(1));
3601 if (dotProductB > largestDotProduct) {
3602 mostFittingFaceIndex = 1;
3603 largestDotProduct = dotProductB;
3604 }
3605 const Scale1D dotProductC = dot(localDirection, getLocalFaceNormal(2));
3606 if (dotProductC > largestDotProduct) {
3607 mostFittingFaceIndex = 2;
3608 largestDotProduct = dotProductC;
3609 }
3610 return mostFittingFaceIndex;
3611 } else {
3612 const auto vector = cross(pointB - pointA, pointC - pointA);
3613 return static_cast<ConvexPolytopeFaceIndex>(signbit(dot(vector, localDirection)));
3614 }
3615 }
3616
3617 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3) {
3618 GREM_ASSERT(edgeIndex < getEdgeCount());
3619 switch (edgeIndex) {
3620 case 0: return 0;
3621 case 1: return 1;
3622 case 2: return 1;
3623 case 3: return 2;
3624 case 4: return 2;
3625 case 5: return 0;
3626 default: break;
3627 }
3628 unreachable();
3629 }
3630
3631 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3) {
3632 GREM_ASSERT(edgeIndex < getEdgeCount());
3633 switch (edgeIndex) {
3634 case 0: return 0;
3635 case 1: return 1;
3636 case 2: return 0;
3637 case 3: return 1;
3638 case 4: return 0;
3639 case 5: return 1;
3640 default: break;
3641 }
3642 unreachable();
3643 }
3644
3645 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const requires(N == 3) {
3646 GREM_ASSERT(edgeIndex < getEdgeCount());
3647 switch (edgeIndex) {
3648 case 0: return 2;
3649 case 1: return 5;
3650 case 2: return 4;
3651 case 3: return 1;
3652 case 4: return 0;
3653 case 5: return 3;
3654 default: break;
3655 }
3656 unreachable();
3657 }
3658
3659 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const requires(N == 3) {
3660 GREM_ASSERT(faceIndex < getFaceCount());
3661 return static_cast<ConvexPolytopeEdgeIndex>(faceIndex);
3662 }
3663
3664 [[nodiscard]] GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const requires(N == 3) {
3665 GREM_ASSERT(vertexIndex < getVertexCount());
3666 return static_cast<ConvexPolytopeEdgeIndex>(vertexIndex << 1);
3667 }
3668};
3669using TriangleShape2D = TriangleShape<2>;
3670using TriangleShape3D = TriangleShape<3>;
3673
3674} // namespace detail
3675
3676} // namespace grem::physics
3677
3678#endif
#define GREM_MATCH(...)
Definition Variant.hpp:1997
#define GREM_CASE(...)
Definition Variant.hpp:1998
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
#define GREM_ALWAYS_INLINE
Definition attributes.hpp:10
Definition Allocation.hpp:25
Convex polytope.
Definition ConvexPolytope.hpp:171
ConvexPolytopeFace< N, Scalar > Face
Face type of the convex polytope.
Definition ConvexPolytope.hpp:175
ConvexPolytopeEdge< N, Scalar > Edge
Edge type of the convex polytope.
Definition ConvexPolytope.hpp:174
ConvexPolytopeVertex< N, Scalar > Vertex
Vertex type of the convex polytope.
Definition ConvexPolytope.hpp:173
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition SharedPointer.hpp:65
Definition Span.hpp:146
Triangle mesh.
Definition TriangleMesh.hpp:40
TriangleMeshVertexIndex VertexIndex
Vertex index type of the triangle mesh.
Definition TriangleMesh.hpp:43
TriangleMeshVertex< N, Scalar > Vertex
Vertex type of the triangle mesh.
Definition TriangleMesh.hpp:42
TriangleMeshFaceIndex FaceIndex
Face index type of the triangle mesh.
Definition TriangleMesh.hpp:44
Tagged union value type that holds a value of one of the given types.
Definition Variant.hpp:293
friend class Variant
Definition Variant.hpp:1402
Identifier for a collision layer that a collider may belong to.
Definition Shape.hpp:34
constexpr CollisionLayer(size_t index) noexcept
Construct a layer identifier with a specific index.
Definition Shape.hpp:46
constexpr bool operator==(const CollisionLayer &other) const noexcept=default
Compare this layer identifier to another for equality.
static const CollisionLayer MAX
Maximum collision layer value.
Definition Shape.hpp:39
Set of collision layers that a collider may belong to.
Definition Shape.hpp:76
constexpr bool operator==(const CollisionLayers &other) const noexcept=default
Compare this layer set to another for equality.
friend constexpr CollisionLayers operator&(CollisionLayers a, CollisionLayers b) noexcept
Get the intersection of two layer sets.
Definition Shape.hpp:172
friend constexpr CollisionLayers & operator^=(CollisionLayers &a, CollisionLayers b) noexcept
Assign the symmetric difference of two layer sets to the first set.
Definition Shape.hpp:233
friend constexpr CollisionLayers operator~(CollisionLayers a) noexcept
Get the complement of a layer set.
Definition Shape.hpp:160
friend constexpr CollisionLayers & operator|=(CollisionLayers &a, CollisionLayers b) noexcept
Assign the union of two layer sets to the first set.
Definition Shape.hpp:221
friend constexpr CollisionLayers operator|(CollisionLayers a, CollisionLayers b) noexcept
Get the union of two layer sets.
Definition Shape.hpp:184
constexpr bool contains(CollisionLayer layer) const noexcept
Check if the layer set contains the given layer.
Definition Shape.hpp:124
friend constexpr CollisionLayers & operator&=(CollisionLayers &a, CollisionLayers b) noexcept
Assign the intersection of two layer sets to the first set.
Definition Shape.hpp:209
constexpr CollisionLayers() noexcept=default
Construct an empty layer set.
constexpr bool containsAllOf(CollisionLayers layers) const noexcept
Check if the layer set contains all of the given layers.
Definition Shape.hpp:148
constexpr bool empty() const noexcept
Check if the layer set is empty.
Definition Shape.hpp:113
friend constexpr CollisionLayers operator^(CollisionLayers a, CollisionLayers b) noexcept
Get the symmetric difference of two layer sets.
Definition Shape.hpp:197
static const CollisionLayers ALL
Set containing all possible layers.
Definition Shape.hpp:81
constexpr bool containsAnyOf(CollisionLayers layers) const noexcept
Check if the layer set contains at least one of the given layers.
Definition Shape.hpp:136
Shape that combines multiple colliders.
Definition Shape.hpp:2526
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2575
GREM_ALWAYS_INLINE CompoundColliderShape(SharedPointer< SubCollider< N >[]> subColliders) noexcept
Construct a compound collider shape from a set of colliders.
Definition Shape.hpp:2533
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2567
CompoundColliderShape(Span< const SubCollider< N > > subColliders)
Construct a compound shape from a set of colliders.
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
GREM_ALWAYS_INLINE Span< const SubCollider< N > > getSubColliders() const noexcept
Definition Shape.hpp:2556
View of a generic convex polytope shape.
Definition Shape.hpp:3220
ConvexPolytopeEdgeIndex getEdgeCount() const
Get the total number of edges, including twin edges, on the convex polyhedron defined by this 3-dimen...
ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const
Direction< N > getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const
ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const
ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction< N > localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const
Get the vertex index of the farthest point on the shape in a certain local direction.
GREM_ALWAYS_INLINE constexpr ConvexPolytopeShapeView(const T &shape) noexcept
Construct a convex polytope shape view.
Definition Shape.hpp:3242
ConvexPolytopeVertexIndex getVertexCount() const
Get the total number of vertices in the convex polytope defined by this shape.
ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
GREM_ALWAYS_INLINE constexpr ConvexPolytopeShapeView(ShapeView< N > shape)
Construct a shape view.
Definition Shape.hpp:3252
ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const
GREM_ALWAYS_INLINE constexpr ConvexPolytopeShapeView(const T &shape) noexcept
Construct a convex polytope shape view.
Definition Shape.hpp:3232
ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction< N > localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const
ConvexPolytopeFaceIndex getFaceCount() const
Get the total number of faces on the convex polytope defined by this shape.
Length< N > getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const
Length< N > getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const
Convex polytope shape.
Definition Shape.hpp:2247
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount() const
Get the total number of edges, including twin edges, on the convex polyhedron defined by this 3-dimen...
Definition Shape.hpp:2328
GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getVertexCount() const
Get the total number of vertices in the convex polytope defined by this shape.
Definition Shape.hpp:2318
ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const
Get the index of the next edge after another edge on the same face on the convex polyhedron defined b...
GREM_ALWAYS_INLINE const SharedPointer< ConvexPolytope< N, float > > & getConvexPolytope() const noexcept
Get the underlying convex polytope of the shape.
Definition Shape.hpp:2282
typename ConvexPolytope< N, float >::Vertex Vertex
Vertex type of the convex polytope shape.
Definition Shape.hpp:2249
typename ConvexPolytope< N, float >::Edge Edge
Edge type of the convex polytope shape.
Definition Shape.hpp:2251
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2293
bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Length< N > getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const
Get the local offset of a specific face on the convex polytope defined by this shape.
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceCount() const
Get the total number of faces on the convex polytope defined by this shape.
Definition Shape.hpp:2323
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
Get the index of the face that a specific edge is part of on the convex polyhedron defined by this 3-...
ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const
Get the index of some edge that has a specific vertex as its origin on the convex polyhedron defined ...
ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
Get the vertex index of the first point of a specific edge on the convex polyhedron defined by this 3...
ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction< N > localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const
Get the vertex index of the farthest point on the shape in a certain local direction.
Length< N > getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const
Get the local offset of a specific vertex in the convex polytope defined by this shape.
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Direction< N > getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const
Get the local normal of a specific face on the convex polytope defined by this shape.
Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
GREM_ALWAYS_INLINE ConvexPolytopeShape(SharedPointer< ConvexPolytope< N, float > > polytope) noexcept
Construct a convex polytope shape from an existing convex polytope.
Definition Shape.hpp:2258
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2298
typename ConvexPolytope< N, float >::Face Face
Face type of the convex polytope shape.
Definition Shape.hpp:2250
ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const
Get the index of the first edge that a specific face is made up of on the convex polyhedron defined b...
ConvexPolytopeShape(Span< const Vertex > vertices, ConvexPolytopeVertexIndex maxVertexCount=Limits< ConvexPolytopeVertexIndex >::MAX)
Construct a convex polytope shape from a set of vertices.
ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction< N > localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const
Get the index of the face on the convex polytope defined by this shape whose local normal is the most...
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
View of a generic convex shape.
Definition Shape.hpp:3147
GREM_ALWAYS_INLINE constexpr ConvexShapeView(const T &shape) noexcept
Construct a convex shape view.
Definition Shape.hpp:3159
GREM_ALWAYS_INLINE constexpr ConvexShapeView(const T &shape) noexcept
Construct a convex shape view.
Definition Shape.hpp:3169
GREM_ALWAYS_INLINE constexpr ConvexShapeView(ShapeView< N > shape)
Construct a shape view.
Definition Shape.hpp:3178
Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
View of a generic shape.
Definition Shape.hpp:2833
constexpr const T * get_if() const noexcept
Access the underlying shape with the given type if it is the currently active alternative.
Definition Shape.hpp:2974
GREM_ALWAYS_INLINE constexpr const void * data() const noexcept
Get an untyped pointer to the data of the underlying shape.
Definition Shape.hpp:2869
constexpr bool is() const noexcept
Check if the shape view currently references the alternative with the given type.
Definition Shape.hpp:2903
Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
bool isConvexPolytopeShapeType() const noexcept
GREM_ALWAYS_INLINE constexpr ShapeView(const T &shape) noexcept
Construct a shape view.
Definition Shape.hpp:2848
constexpr const T & as() const &noexcept
Access the underlying value with the given type without a safety check.
Definition Shape.hpp:2932
typename Shape< N >::value_type value_type
Underling shape variant type.
Definition Shape.hpp:2836
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
constexpr const T & get() const &
Access the underlying value with the given type.
Definition Shape.hpp:2952
bool isConvexShapeType() const noexcept
Check if the shape held by this wrapper is a convex shape type.
GREM_ALWAYS_INLINE constexpr ShapeView(const T &shape) noexcept
Construct a shape view.
Definition Shape.hpp:2859
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
value_type::index_type index_type
Index type used to encode the active shape type.
Definition Shape.hpp:2839
constexpr bool valueless_by_exception() const noexcept
Check if the shape view is in the valueless by exception state.
Definition Shape.hpp:2888
GREM_ALWAYS_INLINE constexpr index_type index() const noexcept
Get the type index of the underlying shape.
Definition Shape.hpp:2878
Affine transformation in world space.
Definition quantities.hpp:5104
GREM_ALWAYS_INLINE Basis< N > GREM_VECTORCALL getBasis() const
Definition quantities.hpp:5158
GREM_ALWAYS_INLINE Position< N > GREM_VECTORCALL getOrigin() const
Definition quantities.hpp:5154
GREM_ALWAYS_INLINE Quantity< N, UnitT > GREM_VECTORCALL getRelative(Quantity< N, UnitT > localQuantity) const
Definition quantities.hpp:5171
Triangle mesh shape.
Definition Shape.hpp:2379
TriangleMeshShape(Allocation< Vertex > vertices, Allocation< VertexIndex > indices)
Construct a triangle mesh shape from a set of vertices.
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
typename TriangleMesh< N, float >::Vertex Vertex
Vertex type of the triangle mesh shape.
Definition Shape.hpp:2381
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
GREM_ALWAYS_INLINE const SharedPointer< TriangleMesh< N, float > > & getTriangleMesh() const noexcept
Get the underlying triangle mesh of the shape.
Definition Shape.hpp:2429
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2445
typename TriangleMesh< N, float >::VertexIndex VertexIndex
Vertex index type of the triangle mesh shape.
Definition Shape.hpp:2382
GREM_ALWAYS_INLINE TriangleMeshShape(SharedPointer< TriangleMesh< N, float > > mesh) noexcept
Construct a triangle mesh shape from an existing triangle mesh.
Definition Shape.hpp:2390
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2440
TriangleMeshShape(Span< const Vertex > vertices, Span< const VertexIndex > indices)
Construct a triangle mesh shape from a set of vertices and indices.
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
typename TriangleMesh< N, float >::FaceIndex FaceIndex
Face index type of the triangle mesh shape.
Definition Shape.hpp:2383
Definition concepts.hpp:47
Concept that checks if a type is a valid 2-dimensional convex polytope shape type.
Definition Shape.hpp:1313
Concept that checks if a type is a valid 3-dimensional convex polytope shape type.
Definition Shape.hpp:1321
Concept that checks if a type is a valid convex polytope shape type.
Definition Shape.hpp:1288
Concept that checks if a type is a valid 2-dimensional convex shape type.
Definition Shape.hpp:1271
Concept that checks if a type is a valid 3-dimensional convex shape type.
Definition Shape.hpp:1279
Concept that checks if a type is a valid convex shape type.
Definition Shape.hpp:1260
Concept that checks if a type is a valid 2-dimensional shape type.
Definition Shape.hpp:1243
Concept that checks if a type is a valid 3-dimensional shape type.
Definition Shape.hpp:1251
Concept that checks if a type is a valid shape type.
Definition Shape.hpp:1227
Concept that checks if a type is a valid physical unit type.
Definition quantities.hpp:515
Definition concepts.hpp:35
constexpr void forEachIndex(auto fn)
Execute a function for each index in the sequence from 0 up to, but not including,...
Definition metaprogramming.hpp:229
Definition Broadphase.hpp:24
Length1D Distance
Scalar length quantity.
Definition quantities.hpp:4962
Collider< 2 > Collider2D
Generic collider in 2-dimensional space.
Definition Shape.hpp:2816
GREM_ALWAYS_INLINE constexpr auto rotate90DegreesClockwise(A a)
Definition quantities.hpp:4232
PointShape< 3 > PointShape3D
Point shape in 3-dimensional space.
Definition Shape.hpp:1480
consteval auto operator*(const UnitT1 &a, const UnitlessT2 &b)
Get the unit resulting from multiplying a unit by a dimensionless unit with a magnitude of 1.
Definition quantities.hpp:759
GREM_ALWAYS_INLINE auto GREM_VECTORCALL abs(A a)
Definition quantities.hpp:3217
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL distance2(A a, B b)
Definition quantities.hpp:3316
BoxShape2D RectangleShape2D
Rectangle shape in 2-dimensional space.
Definition Shape.hpp:1809
Direction< 2 > Direction2D
Normalized unit vector in 2-dimensional space. Unitless.
Definition quantities.hpp:4151
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL lessThan(A a, B b)
Definition quantities.hpp:3595
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL length(A a)
Definition quantities.hpp:3302
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL cross(A a, B b)
Definition quantities.hpp:3239
constexpr decltype(auto) visit(Visitor &&visitor, ShapeView< N > shape)
Call a visitor functor with a reference to the currently active underlying shape of a ShapeView.
Definition Shape.hpp:3089
SphereShape< 2 > SphereShape2D
Sphere shape in 2-dimensional space.
Definition Shape.hpp:2036
ConvexPolytopeShape< 2 > ConvexPolytopeShape2D
Convex polytope shape in 2-dimensional space.
Definition Shape.hpp:2368
Box< 3 > Box3D
Description of an axis-aligned box in 3-dimensional space.
Definition Shape.hpp:940
Quantity< 1, SquareMeters > Area
Scalar area quantity.
Definition quantities.hpp:5525
GREM_ALWAYS_INLINE auto GREM_VECTORCALL signbit(A a)
Definition quantities.hpp:3150
constexpr CollisionLayers operator|(CollisionLayer a, CollisionLayer b) noexcept
Get the union of two collision layers.
Definition Shape.hpp:265
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL midpoint(A a, B b)
Definition quantities.hpp:3497
Sphere< 2 > Sphere2D
Description of a sphere in 2-dimensional space.
Definition Shape.hpp:1055
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL min(Quantity< N1, UnitT1 > a, Quantity< N2, UnitT2 > b)
Definition quantities.hpp:2982
Ray< 3 > Ray3D
Description of a ray in 3-dimensional space.
Definition Shape.hpp:478
Triangle< 2 > Triangle2D
Description of a triangle in 2-dimensional space.
Definition Shape.hpp:1169
CubeShape2D SquareShape2D
Square shape in 2-dimensional space.
Definition Shape.hpp:1941
float Scalar
Underlying scalar type of physics quantity components.
Definition quantities.hpp:1480
RayHitInterior< 3 > RayHitInterior3D
Result of a raycast interior hit in 3-dimensional space.
Definition Shape.hpp:636
ShapeView< 3 > ShapeView3D
View of a generic shape in 3-dimensional space.
Definition Shape.hpp:3069
ShapeView< 2 > ShapeView2D
View of a generic shape in 2-dimensional space.
Definition Shape.hpp:3068
PointShape< 2 > PointShape2D
Point shape in 2-dimensional space.
Definition Shape.hpp:1479
ConvexPolytopeShapeView< 2 > ConvexPolytopeShapeView2D
View of a generic convex polytope shape in 2-dimensional space.
Definition Shape.hpp:3435
void forEachNeighboringVertexIndex(const convex_polytope_shape_2d auto &shape, ConvexPolytopeVertexIndex vertexIndex, auto callback)
Execute a function for each vertex that is directly connected to a specific vertex of a convex polyto...
Definition Shape.hpp:1395
constexpr Dimension< 0, 1, 0 > LENGTH
L.
Definition quantities.hpp:187
Direction< 3 > Direction3D
Normalized unit vector in 3-dimensional space. Unitless.
Definition quantities.hpp:4152
TaperedCapsuleShape< 3 > TaperedCapsuleShape3D
Tapered capsule shape aligned with the local Y axis in 3-dimensional space.
Definition Shape.hpp:2147
LocallyTransformedShape< 2 > LocallyTransformedShape2D
Wrapper of another shape with a local transformation applied to it in 2-dimensional space.
Definition Shape.hpp:2505
SubCollider< 3 > SubCollider3D
Sub-collider of a compound collider shape in 3-dimensional space.
Definition Shape.hpp:2518
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL flipSignIf(A a, bool b)
Definition quantities.hpp:4155
Basis< 3 > Basis3D
Basis matrix in 3-dimensional space. Unitless.
Definition quantities.hpp:4000
LineSegment< 2 > LineSegment2D
Description of a line segment in 2-dimensional space.
Definition Shape.hpp:796
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL greaterThanEqual(A a, B b)
Definition quantities.hpp:3697
Sphere< 3 > Sphere3D
Description of a sphere in 3-dimensional space.
Definition Shape.hpp:1056
Triangle< 3 > Triangle3D
Description of a triangle in 3-dimensional space.
Definition Shape.hpp:1170
Quantity< 1, CubicMeters > Volume
Scalar volume quantity.
Definition quantities.hpp:5539
CubeShape< 3 > CubeShape3D
Cube shape in 3-dimensional space.
Definition Shape.hpp:1938
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(const Shape< N > &shape, Mass mass)
Calculate the principal moments of inertia of an object given its shape and mass.
Definition objects.hpp:573
EllipsoidShape< 3 > EllipsoidShape3D
Ellipsoid shape in 3-dimensional space.
Definition Shape.hpp:1983
InfiniteLineShape< 2 > InfiniteLineShape2D
Infinite line shape parallel to the local Y axis in 2-dimensional space.
Definition Shape.hpp:1612
LineSegment< 3 > LineSegment3D
Description of a line segment in 3-dimensional space.
Definition Shape.hpp:797
ConvexShapeView< 2 > ConvexShapeView2D
View of a generic convex shape in 2-dimensional space.
Definition Shape.hpp:3209
ConvexPolytopeShape< 3 > ConvexPolytopeShape3D
Convex polytope shape in 3-dimensional space.
Definition Shape.hpp:2369
Basis< 2 > Basis2D
Basis matrix in 2-dimensional space. Unitless.
Definition quantities.hpp:3999
TensorQuantity< N, Unitless > Basis
Basis matrix.
Definition quantities.hpp:3998
Length< 1 > Length1D
Relative distance/length offset in 1-dimensional space. Unit: Meters.
Definition quantities.hpp:4925
CubeShape< 2 > CubeShape2D
Cube shape in 2-dimensional space.
Definition Shape.hpp:1937
Ray< 2 > Ray2D
Description of a ray in 2-dimensional space.
Definition Shape.hpp:477
Plane< 3 > Plane3D
Description of an infinite plane in 3-dimensional space.
Definition Shape.hpp:742
Plane< 2 > Plane2D
Description of an infinite plane in 2-dimensional space.
Definition Shape.hpp:741
RayHitInterior< 2 > RayHitInterior2D
Result of a raycast interior hit in 2-dimensional space.
Definition Shape.hpp:635
CompoundColliderShape< 2 > CompoundColliderShape2D
Shape that combines multiple colliders in 2-dimensional space.
Definition Shape.hpp:2598
EllipsoidShape< 2 > EllipsoidShape2D
Ellipsoid shape in 2-dimensional space.
Definition Shape.hpp:1982
constexpr Direction< N > Y_AXIS
The Y axis in the space with the given number of dimensions.
Definition quantities.hpp:4897
ConvexPolytopeShapeView< 3 > ConvexPolytopeShapeView3D
View of a generic convex polytope shape in 3-dimensional space.
Definition Shape.hpp:3436
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL greaterThan(A a, B b)
Definition quantities.hpp:3663
EllipsoidShape2D EllipseShape2D
Ellipse shape in 2-dimensional space.
Definition Shape.hpp:1986
Shape< 2 > Shape2D
Generic shape in 2-dimensional space.
Definition Shape.hpp:2803
LineSegmentShape< 3 > LineSegmentShape3D
Line segment shape parallel to the local Y axis in 3-dimensional space.
Definition Shape.hpp:1550
TriangleMeshShape< 3 > TriangleMeshShape3D
Triangle mesh shape in 3-dimensional space.
Definition Shape.hpp:2461
Quantity< 1, Kilograms > Mass
Scalar mass quantity.
Definition quantities.hpp:5504
InfiniteLineShape< 3 > InfiniteLineShape3D
Infinite line shape parallel to the local Y axis in 3-dimensional space.
Definition Shape.hpp:1613
CompoundColliderShape< 3 > CompoundColliderShape3D
Shape that combines multiple colliders in 3-dimensional space.
Definition Shape.hpp:2599
ColliderView< 2 > ColliderView2D
View of a generic collider in 2-dimensional space.
Definition Shape.hpp:3473
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL normalize(A a)
Definition quantities.hpp:4187
RaycastResult< 3 > RaycastResult3D
Result of a raycast in 3-dimensional space.
Definition Shape.hpp:703
GREM_ALWAYS_INLINE auto GREM_VECTORCALL copysign(A a, B b)
Definition quantities.hpp:4175
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL length2(A a)
Definition quantities.hpp:3295
LineSegmentShape< 2 > LineSegmentShape2D
Line segment shape parallel to the local Y axis in 2-dimensional space.
Definition Shape.hpp:1549
ColliderView< 3 > ColliderView3D
View of a generic collider in 3-dimensional space.
Definition Shape.hpp:3474
Length< 3 > Length3D
Relative distance/length offset in 3-dimensional space. Unit: Meters.
Definition quantities.hpp:4927
CapsuleShape< 3 > CapsuleShape3D
Capsule shape aligned with the local Y axis in 3-dimensional space.
Definition Shape.hpp:2092
Transformation< 2 > Transformation2D
Affine transformation in 2-dimensional space.
Definition quantities.hpp:5183
BoxShape< 2 > BoxShape2D
Box shape in 2-dimensional space.
Definition Shape.hpp:1805
RaycastResult< 2 > RaycastResult2D
Result of a raycast in 2-dimensional space.
Definition Shape.hpp:702
void forEachVertexIndexInFace(const convex_polytope_shape_2d auto &shape, ConvexPolytopeFaceIndex faceIndex, auto callback)
Execute a function for each vertex of a face of a convex polytope shape.
Definition Shape.hpp:1331
Quantity< N, Meters > Length
Relative distance/length offset quantity.
Definition quantities.hpp:4924
TriangleMeshShape< 2 > TriangleMeshShape2D
Triangle mesh shape in 2-dimensional space.
Definition Shape.hpp:2460
Sphere2D Circle
Description of a circle in 2-dimensional space.
Definition Shape.hpp:1057
SphereShape2D CircleShape2D
Circle shape in 2-dimensional space.
Definition Shape.hpp:2040
TaperedCapsuleShape< 2 > TaperedCapsuleShape2D
Tapered capsule shape aligned with the local Y axis in 2-dimensional space.
Definition Shape.hpp:2146
consteval auto sqrt(UnitT a)
Get the canonical unit resulting from taking the square root of a quantity of a given unit.
Definition quantities.hpp:1051
InfiniteHalfSpaceShape< 3 > InfiniteHalfSpaceShape3D
Infinite half-space shape perpendicular to the local Y axis in 3-dimensional space.
Definition Shape.hpp:1660
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL dot(A a, B b)
Definition quantities.hpp:3234
RayHit< 3 > RayHit3D
Result of a raycast hit in 3-dimensional space.
Definition Shape.hpp:583
BoxShape< 3 > BoxShape3D
Box shape in 3-dimensional space.
Definition Shape.hpp:1806
PrincipalMomentsOfInertia< 3 > PrincipalMomentsOfInertia3D
Principal moments of inertia in 3-dimensional inertia major axis space. Unit: kilogram square meters.
Definition quantities.hpp:5862
Quantity< N, Absolute< Meters > > Position
Absolute position in world space.
Definition quantities.hpp:4949
Quantity< N, Unitless > Scale
Dimensionless scale.
Definition quantities.hpp:3984
RayHit< 2 > RayHit2D
Result of a raycast hit in 2-dimensional space.
Definition Shape.hpp:582
void forEachFaceIndexAroundVertex(const convex_polytope_shape_2d auto &shape, ConvexPolytopeVertexIndex vertexIndex, auto callback)
Execute a function for each face that is adjacent to a vertex of a convex polytope shape.
Definition Shape.hpp:1362
constexpr ComponentSwizzle< 1 > Y
Tag specifying the Y component at index 1 of a vector.
Definition quantities.hpp:1493
Box< N > getTransformedBoundingBox(const Transformation< N > &transformation, const Box< N > &box)
Get the axis-aligned bounding box of an axis-aligned box with a transformation applied to it.
Definition Shape.hpp:1214
Shape< 3 > Shape3D
Generic shape in 3-dimensional space.
Definition Shape.hpp:2804
SubCollider< 2 > SubCollider2D
Sub-collider of a compound collider shape in 2-dimensional space.
Definition Shape.hpp:2517
PrincipalMomentsOfInertia< 2 > PrincipalMomentsOfInertia2D
Principal moments of inertia in 2-dimensional inertia major axis space. Unit: kilogram square meters.
Definition quantities.hpp:5861
CapsuleShape2D StadiumShape2D
Stadium shape in 2-dimensional space.
Definition Shape.hpp:2095
Collider< 3 > Collider3D
Generic collider in 3-dimensional space.
Definition Shape.hpp:2817
Box< 2 > Box2D
Description of an axis-aligned box in 2-dimensional space.
Definition Shape.hpp:939
CapsuleShape< 2 > CapsuleShape2D
Capsule shape aligned with the local Y axis in 2-dimensional space.
Definition Shape.hpp:2091
LocallyTransformedShape< 3 > LocallyTransformedShape3D
Wrapper of another shape with a local transformation applied to it in 3-dimensional space.
Definition Shape.hpp:2506
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL max(Quantity< N1, UnitT1 > a, Quantity< N2, UnitT2 > b)
Definition quantities.hpp:3001
SphereShape< 3 > SphereShape3D
Sphere shape in 3-dimensional space.
Definition Shape.hpp:2037
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL maxComponent(A a)
Definition quantities.hpp:3103
Scale< 1 > Scale1D
Dimensionless scale in 1-dimensional space. Unitless.
Definition quantities.hpp:3985
ConvexShapeView< 3 > ConvexShapeView3D
View of a generic convex shape in 3-dimensional space.
Definition Shape.hpp:3210
InfiniteHalfSpaceShape< 2 > InfiniteHalfSpaceShape2D
Infinite half-space shape perpendicular to the local Y axis in 2-dimensional space.
Definition Shape.hpp:1659
AngularQuantity< N, KilogramSquareMeters > PrincipalMomentsOfInertia
Principal moments of inertia in inertia major axis space.
Definition quantities.hpp:5860
constexpr CollisionLayers operator~(CollisionLayer a) noexcept
Get the complement of a collision layer.
Definition Shape.hpp:253
Length< 2 > Length2D
Relative distance/length offset in 2-dimensional space. Unit: Meters.
Definition quantities.hpp:4926
Transformation< 3 > Transformation3D
Affine transformation in 3-dimensional space.
Definition quantities.hpp:5184
uint8_t ConvexPolytopeEdgeIndex
Index of an edge in a convex polytope.
Definition ConvexPolytope.hpp:29
constexpr bool variant_has_alternative_v
Check if a variant type has a given type as one of its possible alternatives.
Definition Variant.hpp:179
constexpr Box< N, T > getTransformedBoundingBox(const mat< N+1, N+1, T > &transformation, const Box< N, T > &aabb) noexcept
Get the axis-aligned bounding box of an axis-aligned box with an affine transformation applied to it.
Definition geometry.hpp:1637
uint8_t ConvexPolytopeVertexIndex
Index of a vertex in a convex polytope.
Definition ConvexPolytope.hpp:24
vec< N, T > Length
Generic length in N-dimensional space.
Definition geometry.hpp:38
void unreachable()
Definition assertions.hpp:125
uint8_t ConvexPolytopeFaceIndex
Index of a face in a convex polytope.
Definition ConvexPolytope.hpp:34
constexpr detail::Matcher< V > match(V &&variant)
Choose a function overload to execute based on the active alternative of a variant.
Definition Variant.hpp:1922
GREM_ALWAYS_INLINE constexpr bool GREM_VECTORCALL all(bool a)
Definition math.hpp:1285
constexpr std::size_t variant_index_v
Get the index of the variant alternative with a given type in a variant type.
Definition Variant.hpp:196
Exception type that is thrown on an attempt to erroneously access an inactive alternative of a Varian...
Definition Variant.hpp:284
Generic axis-aligned box shape with minimum and maximum extents in N-dimensional space.
Definition geometry.hpp:149
Point< N, T > max
Position with the maximum coordinates of the box extents on each coordinate axis.
Definition geometry.hpp:154
constexpr bool intersects(const Ray< N, T > &ray) const noexcept
Check if this box intersects a given ray.
Definition geometry.hpp:193
Point< N, T > min
Position with the minimum coordinates of the box extents on each coordinate axis.
Definition geometry.hpp:153
static constexpr T MAX
Definition fundamentals.hpp:29
Generic line segment between two points in N-dimensional space.
Definition geometry.hpp:772
Result of an interor raycast hit.
Definition geometry.hpp:123
Result of a raycast hit.
Definition geometry.hpp:110
Result of a raycast miss.
Definition geometry.hpp:101
Generic ray with an origin and direction in N-dimensional space.
Definition geometry.hpp:47
static constexpr Optional< Ray > between(Point< N, T > origin, Point< N, T > destination)
Create a ray between two points.
Definition geometry.hpp:61
Result of a raycast.
Definition geometry.hpp:134
Generic sphere shape with a center and radius in N-dimensional space.
Definition geometry.hpp:1018
Generic triangle shape in N-dimensional space.
Definition geometry.hpp:586
Box shape.
Definition Shape.hpp:1710
GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceCount() const
Get the total number of faces on the convex polytope defined by this shape.
Definition Shape.hpp:1763
GREM_ALWAYS_INLINE RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Definition Shape.hpp:1734
GREM_ALWAYS_INLINE bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Definition Shape.hpp:1740
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount() const
Get the total number of edges, including twin edges, on the convex polyhedron defined by this 3-dimen...
Definition Shape.hpp:1772
ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
Get the vertex index of the first point of a specific edge on the convex polyhedron defined by this 3...
ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const
Get the index of some edge that has a specific vertex as its origin on the convex polyhedron defined ...
Direction< N > getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const
Get the local normal of a specific face on the convex polytope defined by this shape.
Length< N > getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const
Get the local offset of a specific vertex in the convex polytope defined by this shape.
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
GREM_ALWAYS_INLINE Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
Definition Shape.hpp:1745
GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getVertexCount() const
Get the total number of vertices in the convex polytope defined by this shape.
Definition Shape.hpp:1754
ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const
Get the index of the next edge after another edge on the same face on the convex polyhedron defined b...
Length< N > getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const
Get the local offset of a specific face on the convex polytope defined by this shape.
ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
Get the index of the face that a specific edge is part of on the convex polyhedron defined by this 3-...
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction< N > localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const
Get the vertex index of the farthest point on the shape in a certain local direction.
ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const
Get the index of the first edge that a specific face is made up of on the convex polyhedron defined b...
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1726
Length< N > halfExtents
Definition Shape.hpp:1711
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1720
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction< N > localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const
Get the index of the face on the convex polytope defined by this shape whose local normal is the most...
Description of an axis-aligned box in world space.
Definition Shape.hpp:813
GREM_ALWAYS_INLINE constexpr bool intersects(const Ray< N > &ray) const noexcept
Check if this box intersects a given ray.
Definition Shape.hpp:888
GREM_ALWAYS_INLINE constexpr RaycastResult< N > raycast(const Ray< N > &ray) const noexcept
Find the closest intersection of this box with a given ray.
Definition Shape.hpp:899
Position< N > min
Definition Shape.hpp:833
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:814
GREM_ALWAYS_INLINE constexpr Box< N > getExpanded(Length< N > expansion) const noexcept
Get a version of the box that is symmetrically expanded by a certain amount.
Definition Shape.hpp:921
bool operator==(const Box &other) const =default
Compare this box to another for equality.
GREM_ALWAYS_INLINE friend constexpr bool intersects(const Box &a, const Box &b) noexcept
Check if two axis-aligned boxes intersect.
Definition Shape.hpp:877
Position< N > max
Definition Shape.hpp:834
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:815
static constexpr DimensionType DIMENSION
Definition Shape.hpp:818
GREM_ALWAYS_INLINE constexpr Box< N > getExpanded(Distance expansion) const noexcept
Get a version of the box that is symmetrically expanded by a certain amount.
Definition Shape.hpp:935
static constexpr Unit UNIT
Definition Shape.hpp:817
GREM_ALWAYS_INLINE constexpr Box< N > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the box.
Definition Shape.hpp:908
GREM_ALWAYS_INLINE constexpr grem::Box< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical box to a unitless box given a desired unit.
Definition Shape.hpp:844
GREM_ALWAYS_INLINE constexpr bool contains(const Position< N > &point) const noexcept
Check if a given point is contained within the extents of this box.
Definition Shape.hpp:864
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:819
static GREM_ALWAYS_INLINE constexpr Box reinterpret(const grem::Box< N, T > &box) noexcept
Reinterpret a unitless box as a physical box in default units.
Definition Shape.hpp:829
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:816
Capsule shape aligned with the local Y axis.
Definition Shape.hpp:2048
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2071
Distance radius
Definition Shape.hpp:2049
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2059
bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Distance halfLength
Definition Shape.hpp:2050
Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
View of a generic collider.
Definition Shape.hpp:3446
CollisionFilter filter
Definition Shape.hpp:3448
GREM_ALWAYS_INLINE constexpr ColliderView(ShapeView< N > shape, CollisionFilter filter) noexcept
Construct a collider view from a shape and collision filter.
Definition Shape.hpp:3467
GREM_ALWAYS_INLINE constexpr ColliderView(const Collider< N > &collider) noexcept
Construct a collider view.
Definition Shape.hpp:3456
Generic collider.
Definition Shape.hpp:2812
CollisionFilter filter
Definition Shape.hpp:2814
Result of a CollisionFilterTest.
Definition Shape.hpp:283
uint8_t TestFlags
Definition Shape.hpp:284
@ RESPONDS_TO_COLLISION
Both colliders wanted to respond to collisions with each other on at least one of the tested layers.
Definition Shape.hpp:287
@ DETECTS_COLLISION
Both colliders wanted to detect collisions with each other on at least one of the tested layers.
Definition Shape.hpp:286
constexpr bool respondsToCollision() const noexcept
Check if both colliders want to respond to collisions with each other on at least some tested layer.
Definition Shape.hpp:329
TestFlags passed
Set of filter tests that passed.
Definition Shape.hpp:290
constexpr bool operator==(const CollisionFilterTestResult &other) const noexcept=default
Compare this filter test result to another for equality.
constexpr bool detectsCollision() const noexcept
Check if both colliders want to detect collisions with each other on at least some tested layer.
Definition Shape.hpp:318
Test that checks if a pair of colliders should collide.
Definition Shape.hpp:337
CollisionLayers responseLayers
Layers to test for collision response.
Definition Shape.hpp:342
static const CollisionFilterTest RESPONSE
Test that checks if a pair of colliders may respond to collisions with each other on any layer.
Definition Shape.hpp:339
static const CollisionFilterTest DETECTION
Test that checks if a pair of colliders may detect collisions with each other on any layer.
Definition Shape.hpp:338
CollisionLayers detectionLayers
Layers to test for collision detection.
Definition Shape.hpp:341
constexpr CollisionFilterTestResult operator()(CollisionFilter a, CollisionFilter b) const noexcept
Check if a given pair of collider's filters meet the requirements.
Definition Shape.hpp:352
Collision filtering options for a collider.
Definition Shape.hpp:272
CollisionLayers detectionLayers
Other colliders' layers that this collider wants to detect collisions with.
Definition Shape.hpp:274
CollisionLayers noResponseLayers
Other colliders' layers that this collider skips collision response with.
Definition Shape.hpp:277
CollisionLayers layers
Layers that the collider belongs to.
Definition Shape.hpp:273
CollisionLayers noDetectionLayers
Other colliders' layers that this collider skips collision detection with.
Definition Shape.hpp:275
CollisionLayers responseLayers
Other colliders' layers that this collider wants to respond to collisions with.
Definition Shape.hpp:276
Cube shape.
Definition Shape.hpp:1817
GREM_ALWAYS_INLINE RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Definition Shape.hpp:1846
GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
Get the index of the face that a specific edge is part of on the convex polyhedron defined by this 3-...
Definition Shape.hpp:1916
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1831
Distance halfExtent
Definition Shape.hpp:1818
GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getFirstVertexIndexOfEdge(ConvexPolytopeEdgeIndex edgeIndex) const
Get the vertex index of the first point of a specific edge on the convex polyhedron defined by this 3...
Definition Shape.hpp:1911
GREM_ALWAYS_INLINE Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
Definition Shape.hpp:1856
GREM_ALWAYS_INLINE Length< N > getLocalVertexOffset(ConvexPolytopeVertexIndex vertexIndex) const
Get the local offset of a specific vertex in the convex polytope defined by this shape.
Definition Shape.hpp:1890
GREM_ALWAYS_INLINE bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Definition Shape.hpp:1851
GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceIndexWithMostFittingLocalNormal(Direction< N > localDirection, ConvexPolytopeFaceIndex searchStartFaceIndex) const
Get the index of the face on the convex polytope defined by this shape whose local normal is the most...
Definition Shape.hpp:1905
GREM_ALWAYS_INLINE Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Definition Shape.hpp:1821
GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getVertexCount() const
Get the total number of vertices in the convex polytope defined by this shape.
Definition Shape.hpp:1867
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1836
GREM_ALWAYS_INLINE ConvexPolytopeFaceIndex getFaceCount() const
Get the total number of faces on the convex polytope defined by this shape.
Definition Shape.hpp:1876
GREM_ALWAYS_INLINE Length< N > getLocalFaceOffset(ConvexPolytopeFaceIndex faceIndex) const
Get the local offset of a specific face on the convex polytope defined by this shape.
Definition Shape.hpp:1895
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getNextEdgeIndex(ConvexPolytopeEdgeIndex edgeIndex) const
Get the index of the next edge after another edge on the same face on the convex polyhedron defined b...
Definition Shape.hpp:1921
GREM_ALWAYS_INLINE PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Definition Shape.hpp:1826
GREM_ALWAYS_INLINE ConvexPolytopeVertexIndex getLocalSupportPointVertexIndex(Direction< N > localDirection, ConvexPolytopeVertexIndex searchStartVertexIndex) const
Get the vertex index of the farthest point on the shape in a certain local direction.
Definition Shape.hpp:1861
GREM_ALWAYS_INLINE Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Definition Shape.hpp:1841
GREM_ALWAYS_INLINE Direction< N > getLocalFaceNormal(ConvexPolytopeFaceIndex faceIndex) const
Get the local normal of a specific face on the convex polytope defined by this shape.
Definition Shape.hpp:1900
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getSomeEdgeIndexOfVertex(ConvexPolytopeVertexIndex vertexIndex) const
Get the index of some edge that has a specific vertex as its origin on the convex polyhedron defined ...
Definition Shape.hpp:1931
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getFirstEdgeIndexOfFace(ConvexPolytopeFaceIndex faceIndex) const
Get the index of the first edge that a specific face is made up of on the convex polyhedron defined b...
Definition Shape.hpp:1926
GREM_ALWAYS_INLINE ConvexPolytopeEdgeIndex getEdgeCount() const
Get the total number of edges, including twin edges, on the convex polyhedron defined by this 3-dimen...
Definition Shape.hpp:1885
Cylinder shape aligned with the local Y axis in 3-dimensional world space.
Definition Shape.hpp:2155
bool containsLocalPoint(Length3D localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Distance radius
Radius of the cylinder. Must be positive.
Definition Shape.hpp:2156
PrincipalMomentsOfInertia3D calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Optional< Area > getReferenceArea(const Basis3D &basis, Direction3D direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis3D &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2173
GREM_ALWAYS_INLINE Optional< Box3D > getBoundingBox(const Transformation3D &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2166
Length3D getLocalSupportPointOffset(Direction3D localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
RaycastResult3D castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Distance halfLength
Half of the length of the cylinder's center line along its local Y axis. Must be positive.
Definition Shape.hpp:2157
Normalized unit vector.
Definition quantities.hpp:4105
static GREM_ALWAYS_INLINE constexpr Direction reinterpret(auto other)
Definition quantities.hpp:4117
Ellipsoid shape.
Definition Shape.hpp:1949
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Length< N > radii
Definition Shape.hpp:1950
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1959
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1964
Infinite half-space shape perpendicular to the local Y axis.
Definition Shape.hpp:1623
GREM_ALWAYS_INLINE Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Definition Shape.hpp:1625
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
GREM_ALWAYS_INLINE PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Definition Shape.hpp:1630
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1642
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1636
GREM_ALWAYS_INLINE Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Definition Shape.hpp:1648
Infinite line shape parallel to the local Y axis.
Definition Shape.hpp:1560
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1579
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1573
GREM_ALWAYS_INLINE PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Definition Shape.hpp:1567
GREM_ALWAYS_INLINE bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Definition Shape.hpp:1600
GREM_ALWAYS_INLINE Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Definition Shape.hpp:1562
GREM_ALWAYS_INLINE RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Definition Shape.hpp:1592
GREM_ALWAYS_INLINE Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Definition Shape.hpp:1585
GREM_ALWAYS_INLINE Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
Definition Shape.hpp:1606
Infinite plane shape perpendicular to the local Y axis in 3-dimensional space.
Definition Shape.hpp:1668
RaycastResult3D castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
GREM_ALWAYS_INLINE PrincipalMomentsOfInertia3D calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Definition Shape.hpp:1675
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis3D &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1687
GREM_ALWAYS_INLINE Optional< Area > getReferenceArea(const Basis3D &basis, Direction3D direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Definition Shape.hpp:1693
GREM_ALWAYS_INLINE Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Definition Shape.hpp:1670
GREM_ALWAYS_INLINE Optional< Box3D > getBoundingBox(const Transformation3D &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1681
Line segment shape parallel to the local Y axis.
Definition Shape.hpp:1490
GREM_ALWAYS_INLINE Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Definition Shape.hpp:1494
GREM_ALWAYS_INLINE RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Definition Shape.hpp:1527
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1507
Distance halfLength
Definition Shape.hpp:1491
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1515
GREM_ALWAYS_INLINE Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Definition Shape.hpp:1520
GREM_ALWAYS_INLINE bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Definition Shape.hpp:1535
GREM_ALWAYS_INLINE Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
Definition Shape.hpp:1541
GREM_ALWAYS_INLINE PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Definition Shape.hpp:1500
Description of a line segment in world space.
Definition Shape.hpp:750
static GREM_ALWAYS_INLINE constexpr LineSegment reinterpret(const grem::LineSegment< N, T > &line) noexcept
Reinterpret a unitless line segment as a physical line segment in default units.
Definition Shape.hpp:767
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:756
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:752
GREM_ALWAYS_INLINE constexpr grem::LineSegment< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical line segment to a unitless line segment given a desired unit.
Definition Shape.hpp:783
static constexpr DimensionType DIMENSION
Definition Shape.hpp:755
bool operator==(const LineSegment &other) const =default
Compare this line segment to another for equality.
static constexpr Unit UNIT
Definition Shape.hpp:754
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:753
Position< N > pointA
Definition Shape.hpp:771
Position< N > pointB
Definition Shape.hpp:772
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:751
Wrapper of another shape with a local transformation applied to it.
Definition Shape.hpp:2479
Orientation< N > localOrientation
Definition Shape.hpp:2482
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Length< N > localOffset
Definition Shape.hpp:2481
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Scale< N > localScale
Definition Shape.hpp:2483
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Absolute orientation in world space.
Definition quantities.hpp:4431
Description of an infinite plane in world space.
Definition Shape.hpp:721
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:723
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:727
static constexpr Unit UNIT
Definition Shape.hpp:725
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:724
Direction< N > normal
Definition Shape.hpp:730
static constexpr DimensionType DIMENSION
Definition Shape.hpp:726
bool operator==(const Plane &other) const =default
Compare this plane to another for equality.
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:722
Position< N > point
Definition Shape.hpp:729
Point shape.
Definition Shape.hpp:1427
GREM_ALWAYS_INLINE PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Definition Shape.hpp:1434
GREM_ALWAYS_INLINE bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
Definition Shape.hpp:1466
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:1440
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:1445
GREM_ALWAYS_INLINE Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Definition Shape.hpp:1451
GREM_ALWAYS_INLINE RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Definition Shape.hpp:1458
GREM_ALWAYS_INLINE Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Definition Shape.hpp:1429
GREM_ALWAYS_INLINE Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
Definition Shape.hpp:1472
Result of a raycast interior hit.
Definition Shape.hpp:601
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:604
typename Distance::Unit Unit
Unit type.
Definition Shape.hpp:602
Length< N > localOffset
Definition Shape.hpp:621
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:603
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:607
static GREM_ALWAYS_INLINE constexpr RayHitInterior reinterpret(const grem::RayHitInterior< N, T > &hit) noexcept
Reinterpret a unitless ray hit as a physical ray hit in default units.
Definition Shape.hpp:617
static constexpr DimensionType DIMENSION
Definition Shape.hpp:606
static constexpr Unit UNIT
Definition Shape.hpp:605
GREM_ALWAYS_INLINE constexpr grem::RayHitInterior< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical ray hit to a unitless ray hit given a desired unit.
Definition Shape.hpp:631
Result of a raycast hit.
Definition Shape.hpp:542
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:545
static GREM_ALWAYS_INLINE constexpr RayHit reinterpret(const grem::RayHit< N, T > &hit) noexcept
Reinterpret a unitless ray hit as a physical ray hit in default units.
Definition Shape.hpp:558
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:543
static constexpr Unit UNIT
Definition Shape.hpp:546
Length< N > localOffset
Definition Shape.hpp:566
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:548
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:544
static constexpr DimensionType DIMENSION
Definition Shape.hpp:547
Direction< N > normal
Definition Shape.hpp:568
GREM_ALWAYS_INLINE constexpr grem::RayHit< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical ray hit to a unitless ray hit given a desired unit.
Definition Shape.hpp:578
Distance distance
Definition Shape.hpp:567
Result of a raycast miss.
Definition Shape.hpp:493
static GREM_ALWAYS_INLINE constexpr RayMiss reinterpret(const grem::RayMiss &miss) noexcept
Reinterpret a unitless ray miss as a physical ray miss in default units.
Definition Shape.hpp:508
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:495
GREM_ALWAYS_INLINE constexpr grem::RayMiss in(OtherUnitT unit) const noexcept
Convert this physical ray miss to a unitless ray miss given a desired unit.
Definition Shape.hpp:522
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:496
static constexpr MagnitudeType MAGNITUDE
Unit magnitude.
Definition Shape.hpp:499
static constexpr DimensionType DIMENSION
Unit dimension.
Definition Shape.hpp:498
typename Distance::Unit Unit
Unit type.
Definition Shape.hpp:494
static constexpr Unit UNIT
Unit.
Definition Shape.hpp:497
Description of a ray.
Definition Shape.hpp:392
Position< N > origin
Definition Shape.hpp:437
static constexpr DimensionType DIMENSION
Definition Shape.hpp:397
static GREM_ALWAYS_INLINE constexpr Ray reinterpret(const grem::Ray< N, T > &ray) noexcept
Reinterpret a unitless ray as a physical ray in default units.
Definition Shape.hpp:425
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:393
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:394
GREM_ALWAYS_INLINE constexpr grem::Ray< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical ray to a unitless ray given a desired unit.
Definition Shape.hpp:468
static constexpr Optional< Ray > between(Position< N > origin, Position< N > destination)
Create a ray between two points.
Definition Shape.hpp:410
Scale< N > directionInverse
Definition Shape.hpp:458
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:395
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:398
static constexpr Unit UNIT
Definition Shape.hpp:396
Direction< N > direction
Definition Shape.hpp:444
Distance maxDistance
Definition Shape.hpp:451
Result of a raycast.
Definition Shape.hpp:654
static GREM_ALWAYS_INLINE constexpr RaycastResult reinterpret(const grem::RaycastResult< N, T > &raycastResult) noexcept
Reinterpret a unitless raycast result as a physical raycast result in default units.
Definition Shape.hpp:671
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:660
GREM_ALWAYS_INLINE constexpr grem::RaycastResult< N, Scalar > in(OtherUnitT unit) const
Convert this physical raycast result to a unitless raycast result given a desired unit.
Definition Shape.hpp:697
static constexpr Unit UNIT
Definition Shape.hpp:658
static constexpr DimensionType DIMENSION
Definition Shape.hpp:659
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:657
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:656
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:655
constexpr Variant() noexcept(std::is_nothrow_default_constructible_v< variant_alternative_t< 0, Variant > >)
Default-construct a variant with the first variant alternative, if it is default-constructible.
Definition Variant.hpp:351
bool isConvexShapeType() const
Check if the shape held by this wrapper is a convex shape type.
Definition Shape.hpp:2620
Variant value_type
Definition Shape.hpp:2610
bool isConvexPolytopeShapeType() const
Check if the shape held by this wrapper is a convex polytope shape type.
Definition Shape.hpp:2630
bool isConvexPolytopeShapeType() const
Check if the shape held by this wrapper is a convex polytope shape type.
Definition Shape.hpp:2731
constexpr Variant() noexcept(std::is_nothrow_default_constructible_v< variant_alternative_t< 0, Variant > >)
Default-construct a variant with the first variant alternative, if it is default-constructible.
Definition Variant.hpp:351
Variant value_type
Definition Shape.hpp:2711
bool isConvexShapeType() const
Check if the shape held by this wrapper is a convex shape type.
Definition Shape.hpp:2721
Generic shape.
Definition Shape.hpp:2471
Sphere shape.
Definition Shape.hpp:1994
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2016
bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
GREM_ALWAYS_INLINE Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Definition Shape.hpp:2021
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
GREM_ALWAYS_INLINE PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Definition Shape.hpp:2003
Distance radius
Definition Shape.hpp:1995
Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2008
GREM_ALWAYS_INLINE Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Definition Shape.hpp:1998
Description of a sphere in world space.
Definition Shape.hpp:956
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:962
GREM_ALWAYS_INLINE constexpr bool intersects(const Ray< N > &ray) const noexcept
Check if this sphere intersects a given ray.
Definition Shape.hpp:1031
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:957
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:959
GREM_ALWAYS_INLINE constexpr RaycastResult< N > raycast(const Ray< N > &ray) const noexcept
Find the closest intersection of this sphere with a given ray.
Definition Shape.hpp:1042
Distance radius
Definition Shape.hpp:977
GREM_ALWAYS_INLINE constexpr Box< N > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the sphere.
Definition Shape.hpp:1051
static constexpr DimensionType DIMENSION
Definition Shape.hpp:961
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:958
Position< N > center
Definition Shape.hpp:976
GREM_ALWAYS_INLINE constexpr bool contains(const Position< N > &point) const noexcept
Check if a given point is contained within the extents of this sphere.
Definition Shape.hpp:1007
static GREM_ALWAYS_INLINE constexpr Sphere reinterpret(const grem::Sphere< N, T > &sphere) noexcept
Reinterpret a unitless sphere as a physical sphere in default units.
Definition Shape.hpp:972
static constexpr Unit UNIT
Definition Shape.hpp:960
GREM_ALWAYS_INLINE constexpr grem::Sphere< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical sphere to a unitless sphere given a desired unit.
Definition Shape.hpp:987
bool operator==(const Sphere &other) const =default
Compare this sphere to another for equality.
GREM_ALWAYS_INLINE friend constexpr bool intersects(const Sphere &a, const Sphere &b) noexcept
Check if two spheres intersect.
Definition Shape.hpp:1020
Sub-collider of a compound collider shape.
Definition Shape.hpp:2820
Collider< N > collider
Definition Shape.hpp:2821
Length< N > localOffset
Definition Shape.hpp:2822
Orientation< N > localOrientation
Definition Shape.hpp:2823
Scale< N > localScale
Definition Shape.hpp:2824
Tapered capsule shape aligned with the local Y axis.
Definition Shape.hpp:2103
Distance halfLength
Definition Shape.hpp:2106
Distance bottomRadius
Definition Shape.hpp:2104
GREM_ALWAYS_INLINE Optional< Box< N > > getBoundingBox(const Transformation< N > &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2115
Optional< Area > getReferenceArea(const Basis< N > &basis, Direction< N > direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
Distance topRadius
Definition Shape.hpp:2105
Length< N > getLocalSupportPointOffset(Direction< N > localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
bool containsLocalPoint(Length< N > localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis< N > &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2124
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
RaycastResult< N > castLocalRay(Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Conical frustum shape aligned with the local Y axis in 3-dimensional space.
Definition Shape.hpp:2196
Distance topRadius
Radius of the top (+Y) disc of the conical frustum. Must be non-negative. Must be positive if bottomR...
Definition Shape.hpp:2198
Distance halfLength
Half of the length of the conical frustum's center line along its local Y axis. Must be positive.
Definition Shape.hpp:2199
GREM_ALWAYS_INLINE Optional< Distance > getBoundingRadius(const Basis3D &basis) const
Get the radius of the bounding sphere of the shape.
Definition Shape.hpp:2218
RaycastResult3D castLocalRay(Length3D localRayOrigin, Direction3D localRayDirection, Distance maxLocalRayDistance) const
Find the closest intersection of this shape with a given ray in local space.
Optional< Area > getReferenceArea(const Basis3D &basis, Direction3D direction) const
Get an estimate of the reference area of the shape for a certain direction, typically calculated as t...
GREM_ALWAYS_INLINE Optional< Box3D > getBoundingBox(const Transformation3D &transformation) const
Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Definition Shape.hpp:2208
Volume calculateVolume() const
Calculate an estimate of the volume of the shape.
Distance bottomRadius
Radius of the bottom (-Y) disc of the conical frustum. Must be non-negative. Must be positive if topR...
Definition Shape.hpp:2197
Length3D getLocalSupportPointOffset(Direction3D localDirection) const
Get the local offset from the origin of the shape to the farthest point on the shape in a certain loc...
PrincipalMomentsOfInertia3D calculatePrincipalMomentsOfInertia(Mass mass) const
Calculate an estimate of the local moment of inertia of the shape given a certain mass.
bool containsLocalPoint(Length3D localPoint) const
Check if a local point relative to the origin of the shape is contained within the shape.
GREM_ALWAYS_INLINE Quantity< N, Square< Relative< UnitT > > > getScale2() const noexcept
Definition quantities.hpp:3798
GREM_ALWAYS_INLINE Quantity< N, Relative< UnitT > > getScale() const noexcept
Definition quantities.hpp:3790
Description of a triangle in world space.
Definition Shape.hpp:1073
GREM_ALWAYS_INLINE constexpr bool contains(const Position< N > &point) const noexcept
Check if a given point is contained within the extents of this triangle.
Definition Shape.hpp:1134
bool operator==(const Triangle &other) const =default
Compare this triangle to another for equality.
typename Unit::DimensionType DimensionType
Unit dimension type.
Definition Shape.hpp:1075
Position< N > pointC
Definition Shape.hpp:1099
GREM_ALWAYS_INLINE constexpr RaycastResult< N > raycast(const Ray< N > &ray) const noexcept
Find the closest intersection of this triangle with a given ray.
Definition Shape.hpp:1156
Position< N > pointA
Definition Shape.hpp:1097
static constexpr Unit UNIT
Definition Shape.hpp:1077
static constexpr MagnitudeType MAGNITUDE
Definition Shape.hpp:1079
typename Unit::MagnitudeType MagnitudeType
Unit magnitude type.
Definition Shape.hpp:1076
static GREM_ALWAYS_INLINE constexpr Triangle reinterpret(const grem::Triangle< N, T > &triangle) noexcept
Reinterpret a unitless triangle as a physical triangle in default units.
Definition Shape.hpp:1089
GREM_ALWAYS_INLINE constexpr Box< N > getBoundingBox() const noexcept
Get the axis-aligned bounding box of the triangle.
Definition Shape.hpp:1165
GREM_ALWAYS_INLINE constexpr bool intersects(const Ray< N > &ray) const noexcept
Check if this triangle intersects a given ray.
Definition Shape.hpp:1145
Position< N > pointB
Definition Shape.hpp:1098
GREM_ALWAYS_INLINE constexpr grem::Triangle< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical triangle to a unitless triangle given a desired unit.
Definition Shape.hpp:1110
typename Position< N >::Unit Unit
Unit type.
Definition Shape.hpp:1074
static constexpr DimensionType DIMENSION
Definition Shape.hpp:1078