summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-02-13 01:36:42 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-02-13 01:36:42 +0000
commit849f4aa735352704995ffb51bf23dadf795bb119 (patch)
tree6f610f55791d7dc7ade6ebf5be42227f63979f75 /game
parentAdd helpers for testing for triangle overlap/containedness (diff)
downloadilt-849f4aa735352704995ffb51bf23dadf795bb119.tar.bz2
ilt-849f4aa735352704995ffb51bf23dadf795bb119.tar.xz
ilt-849f4aa735352704995ffb51bf23dadf795bb119.zip
Include face handle in intersectRay result
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp8
-rw-r--r--game/geoData.h6
2 files changed, 8 insertions, 6 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index ae43f3f..0dbc0ac 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -213,16 +213,16 @@ GeoData::positionAt(const PointFace & p) const
return positionOnTriangle(p.point, triangle<3>(p.face(this)));
}
-[[nodiscard]] std::optional<GlobalPosition3D>
+[[nodiscard]] GeoData::IntersectionResult
GeoData::intersectRay(const Ray<GlobalPosition3D> & ray) const
{
return intersectRay(ray, findPoint(ray.start));
}
-[[nodiscard]] std::optional<GlobalPosition3D>
+[[nodiscard]] GeoData::IntersectionResult
GeoData::intersectRay(const Ray<GlobalPosition3D> & ray, FaceHandle face) const
{
- std::optional<GlobalPosition3D> out;
+ GeoData::IntersectionResult out;
walkUntil(PointFace {ray.start, face},
ray.start.xy()
+ GlobalPosition2D(ray.direction.xy() * RelativePosition2D(upperExtent.xy() - lowerExtent.xy())),
@@ -231,7 +231,7 @@ GeoData::intersectRay(const Ray<GlobalPosition3D> & ray, FaceHandle face) const
RelativeDistance dist {};
const auto t = triangle<3>(face);
if (ray.intersectTriangle(t.x, t.y, t.z, bari, dist)) {
- out = t * bari;
+ out.emplace(t * bari, face);
return true;
}
return false;
diff --git a/game/geoData.h b/game/geoData.h
index 2fd3aa5..f599552 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -74,8 +74,10 @@ public:
[[nodiscard]] FaceHandle findPoint(GlobalPosition2D, FaceHandle start) const;
[[nodiscard]] GlobalPosition3D positionAt(const PointFace &) const;
- [[nodiscard]] std::optional<GlobalPosition3D> intersectRay(const Ray<GlobalPosition3D> &) const;
- [[nodiscard]] std::optional<GlobalPosition3D> intersectRay(const Ray<GlobalPosition3D> &, FaceHandle start) const;
+ using IntersectionLocation = std::pair<GlobalPosition3D, FaceHandle>;
+ using IntersectionResult = std::optional<IntersectionLocation>;
+ [[nodiscard]] IntersectionResult intersectRay(const Ray<GlobalPosition3D> &) const;
+ [[nodiscard]] IntersectionResult intersectRay(const Ray<GlobalPosition3D> &, FaceHandle start) const;
void walk(const PointFace & from, const GlobalPosition2D to, const std::function<void(FaceHandle)> & op) const;
void walkUntil(const PointFace & from, const GlobalPosition2D to, const std::function<bool(FaceHandle)> & op) const;