Improved Ray class

Former-commit-id: 97a9a50440476e962cc850a09859b0784976c242
This commit is contained in:
Lynix
2014-07-10 10:11:17 +02:00
parent 2479588811
commit 3dac383486
2 changed files with 301 additions and 198 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014 Rémi Bèges - Jérôme Leclercq
// Copyright (C) 2014 Gawaboumga (https://github.com/Gawaboumga) - Jérôme Leclercq
// This file is part of the "Nazara Engine - Mathematics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -10,51 +10,57 @@
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/OrientedBox.hpp>
#include <Nazara/Math/Plane.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T> class NzRay
template<typename T>
class NzRay
{
public:
NzRay() = default;
NzRay(T X, T Y, T Z, T directionX, T directionY, T directionZ);
NzRay(const T origin[3], const T direction[3]);
NzRay(const NzVector3<T>& origin, const NzVector3<T>& direction);
NzRay(const NzPlane<T>& planeOne, const NzPlane<T>& planeTwo);
template<typename U> explicit NzRay(const NzVector3<U>& origin, const NzVector3<U>& direction);
NzRay(const NzVector3<T>& origin, const NzVector3<T>& direction);
template<typename U> explicit NzRay(const NzRay<U>& ray);
template<typename U> explicit NzRay(const NzVector3<U>& origin, const NzVector3<U>& direction);
NzRay(const NzRay<T>& ray) = default;
~NzRay() = default;
NzVector3<T> GetClosestPoint(const NzVector3<T>& point) const;
T ClosestPoint(const NzVector3<T>& point) const;
NzVector3<T> GetPoint(T lambda) const;
bool Intersect(const NzBox<T>& box, NzVector3<T> * hitPoint = nullptr, NzVector3<T> * hitSecondPoint = nullptr) const;
bool Intersect(const NzOrientedBox<T>& orientedBox, NzVector3<T> * hitPoint = nullptr, NzVector3<T> * hitSecondPoint = nullptr) const;
bool Intersect(const NzPlane<T>& plane, NzVector3<T> * hitPoint = nullptr) const;
bool Intersect(const NzSphere<T>& sphere, NzVector3<T> * hitPoint = nullptr, NzVector3<T> * hitSecondPoint = nullptr) const;
//bool Intersect(const NzBoundingVolume<T>& volume, T* closestHit = nullptr, T* farthestHit = nullptr) const;
bool Intersect(const NzBox<T>& box, T* closestHit = nullptr, T* farthestHit = nullptr) const;
bool Intersect(const NzBox<T>& box, const NzMatrix4<T>& transform, T* closestHit = nullptr, T* farthestHit = nullptr) const;
//bool Intersect(const NzOrientedBox<T>& orientedBox, T* closestHit = nullptr, T* farthestHit = nullptr) const;
bool Intersect(const NzPlane<T>& plane, T* hit = nullptr) const;
bool Intersect(const NzSphere<T>& sphere, T* closestHit = nullptr, T* farthestHit = nullptr) const;
NzVector3<T> operator*(T lambda) const;
NzRay& MakeAxisX();
NzRay& MakeAxisY();
NzRay& MakeAxisZ();
NzRay& Set(T X, T Y, T Z, T directionX, T directionY, T directionZ);
NzRay& Set(const T origin[3], const T direction[3]);
NzRay& Set(const NzVector3<T>& origin, const NzVector3<T>& direction);
NzRay& Set(const NzPlane<T>& planeOne, const NzPlane<T>& planeTwo);
template<typename U> NzRay& Set(const NzVector3<U>& origin, const NzVector3<U>& direction);
NzRay& Set(const NzRay& ray);
NzRay& Set(const NzVector3<T>& origin, const NzVector3<T>& direction);
template<typename U> NzRay& Set(const NzRay<U>& ray);
NzRay& Set(const NzRay& ray);
NzRay& SetDirection(const NzVector3<T>& direction);
NzRay& SetOrigin(const NzVector3<T>& origin);
template<typename U> NzRay& Set(const NzVector3<U>& origin, const NzVector3<U>& direction);
NzString ToString() const;
NzVector3<T> operator*(T lambda) const;
static NzRay AxisX();
static NzRay AxisY();
static NzRay AxisZ();
static NzRay Lerp(const NzRay& from, const NzRay& to, T interpolation);
static NzRay UnitX();
static NzRay UnitY();
static NzRay UnitZ();
NzVector3<T> direction, origin;
};