blob: 567f98aa6112e5ed4922e35501dcf3b734e9384b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include "geometricPlane.h"
#include "ray.h"
#include <glm/geometric.hpp>
#include <glm/gtx/intersect.hpp>
GeometricPlane::PlaneRelation
GeometricPlane::getRelation(Position3D p) const
{
const auto d = glm::dot(normal, p - origin);
return d < 0.F ? PlaneRelation::Below : d > 0.F ? PlaneRelation::Above : PlaneRelation::On;
}
bool
GeometricPlane::isIntersect(PlaneRelation a, PlaneRelation b)
{
return ((a == PlaneRelation::Above && b == PlaneRelation::Below)
|| (a == PlaneRelation::Below && b == PlaneRelation::Above));
}
std::optional<GeometricPlane::DistAndPosition>
GeometricPlane::getRayIntersectPosition(const Ray & ray) const
{
float dist {};
if (!glm::intersectRayPlane(ray.start, ray.direction, origin, normal, dist)) {
return {};
}
return DistAndPosition {dist, ray.start + (ray.direction * dist)};
}
|