// Copyright (C) 2022 Gawaboumga (https://github.com/Gawaboumga) - Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Math module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_MATH_RAY_HPP #define NAZARA_MATH_RAY_HPP #include #include #include #include #include #include #include #include namespace Nz { struct SerializationContext; template class Ray { public: Ray() = default; Ray(T X, T Y, T Z, T directionX, T directionY, T directionZ); Ray(const Vector3& origin, const Vector3& direction); Ray(const T origin[3], const T direction[3]); Ray(const Plane& planeOne, const Plane& planeTwo); template explicit Ray(const Ray& ray); template explicit Ray(const Vector3& origin, const Vector3& direction); Ray(const Ray& ray) = default; ~Ray() = default; T ClosestPoint(const Vector3& point) const; Vector3 GetPoint(T lambda) const; bool Intersect(const BoundingVolume& volume, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Box& box, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Box& box, const Matrix4& transform, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const OrientedBox& orientedBox, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Plane& plane, T* hit = nullptr) const; bool Intersect(const Sphere& sphere, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Vector3& firstPoint, const Vector3& secondPoint, const Vector3& thirdPoint, T* hit = nullptr) const; Ray& MakeAxisX(); Ray& MakeAxisY(); Ray& MakeAxisZ(); Ray& Set(T X, T Y, T Z, T directionX, T directionY, T directionZ); Ray& Set(const Vector3& origin, const Vector3& direction); Ray& Set(const T origin[3], const T direction[3]); Ray& Set(const Plane& planeOne, const Plane& planeTwo); template Ray& Set(const Ray& ray); template Ray& Set(const Vector3& origin, const Vector3& direction); std::string ToString() const; Vector3 operator*(T lambda) const; Ray& operator=(const Ray& other) = default; bool operator==(const Ray& ray) const; bool operator!=(const Ray& ray) const; static Ray AxisX(); static Ray AxisY(); static Ray AxisZ(); static Ray Lerp(const Ray& from, const Ray& to, T interpolation); Vector3 direction, origin; }; using Rayd = Ray; using Rayf = Ray; template bool Serialize(SerializationContext& context, const Ray& ray, TypeTag>); template bool Unserialize(SerializationContext& context, Ray* ray, TypeTag>); } template std::ostream& operator<<(std::ostream& out, const Nz::Ray& vec); #include #endif // NAZARA_MATH_RAY_HPP