Leviathan  0.8.0.0
Leviathan game engine
Plane.cpp
Go to the documentation of this file.
1 // ------------------------------------ //
2 #include "Plane.h"
3 
4 #include "Ray.h"
5 
6 using namespace Leviathan;
7 // ------------------------------------ //
8 DLLEXPORT std::tuple<bool, float> Plane::CalculateIntersection(const Ray& ray) const
9 {
10  // This code is copied from bs::framework with modifications, see License.txt for details
11  const float denom = Normal.Dot(ray.GetDirection());
12 
13  if(std::abs(denom) < EPSILON) {
14  // Parallel
15  return std::make_tuple(false, 0.0f);
16  } else {
17  const float nom = Normal.Dot(ray.GetOrigin()) - Distance;
18  const float t = -(nom / denom);
19  return std::make_tuple(t >= 0.f, t);
20  }
21 }
const auto GetDirection() const
Definition: Ray.h:37
Ray starting from an origin with a direction.
Definition: Ray.h:14
DLLEXPORT std::tuple< bool, float > CalculateIntersection(const Ray &ray) const
Definition: Plane.cpp:8
constexpr float EPSILON
Definition: Define.h:70
const auto GetOrigin() const
Definition: Ray.h:32
DLLEXPORT constexpr float Dot(const Float3 &val) const noexcept
Definition: Types.h:1227
#define DLLEXPORT
Definition: Include.h:84
Float3 Normal
Definition: Plane.h:21
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
float Distance
Definition: Plane.h:22