// Copyright (C) 2024 Gawaboumga (https://github.com/Gawaboumga) - Jérôme "SirLynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Math module" // For conditions of distribution and use, see copyright notice in Export.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: constexpr Ray() = default; constexpr Ray(T X, T Y, T Z, T directionX, T directionY, T directionZ); constexpr Ray(const Vector3& origin, const Vector3& direction); constexpr Ray(const T origin[3], const T direction[3]); Ray(const Plane& planeOne, const Plane& planeTwo); template constexpr explicit Ray(const Ray& ray); template constexpr explicit Ray(const Vector3& origin, const Vector3& direction); constexpr Ray(const Ray&) = default; constexpr Ray(Ray&&) = default; ~Ray() = default; constexpr bool ApproxEqual(const Ray& ray, T maxDifference = std::numeric_limits::epsilon()) const; constexpr T ClosestPoint(const Vector3& point) const; constexpr Vector3 GetPoint(T lambda) const; constexpr bool Intersect(const BoundingVolume& volume, T* closestHit = nullptr, T* furthestHit = nullptr) const; constexpr bool Intersect(const Box& box, T* closestHit = nullptr, T* furthestHit = nullptr) const; constexpr bool Intersect(const Box& box, const Matrix4& transform, T* closestHit = nullptr, T* furthestHit = nullptr) const; constexpr bool Intersect(const Plane& plane, T* hit = nullptr) const; constexpr bool Intersect(const Sphere& sphere, T* closestHit = nullptr, T* furthestHit = nullptr) const; constexpr bool Intersect(const Vector3& firstPoint, const Vector3& secondPoint, const Vector3& thirdPoint, T* hit = nullptr) const; std::string ToString() const; constexpr Ray& operator=(const Ray&) = default; constexpr Ray& operator=(Ray&&) = default; constexpr Vector3 operator*(T lambda) const; constexpr bool operator==(const Ray& ray) const; constexpr bool operator!=(const Ray& ray) const; constexpr bool operator<(const Ray& ray) const; constexpr bool operator<=(const Ray& ray) const; constexpr bool operator>(const Ray& ray) const; constexpr bool operator>=(const Ray& ray) const; static constexpr bool ApproxEqual(const Ray& lhs, const Ray& rhs, T maxDifference = std::numeric_limits::epsilon()); static constexpr Ray AxisX(); static constexpr Ray AxisY(); static constexpr Ray AxisZ(); static constexpr 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