// Copyright (C) 2023 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_PLANE_HPP #define NAZARA_MATH_PLANE_HPP #include #include namespace Nz { struct SerializationContext; template class Plane { // Note: this class follows the ax + by + cz + d = 0 equation, which means d is the distance from origin public: constexpr Plane() = default; constexpr Plane(T normalX, T normalY, T normalZ, T Distance); constexpr Plane(const T plane[4]); constexpr Plane(const Vector3& Normal, T Distance); constexpr Plane(const Vector3& Normal, const Vector3& point); Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3); template constexpr explicit Plane(const Plane& plane); constexpr Plane(const Plane& plane) = default; ~Plane() = default; constexpr bool ApproxEqual(const Plane& plane, T maxDifference = std::numeric_limits::epsilon()) const; Plane& Normalize(T* length = nullptr); constexpr T SignedDistance(const Vector3& point) const; std::string ToString() const; constexpr Plane& operator=(const Plane& other) = default; constexpr bool operator==(const Plane& plane) const; constexpr bool operator!=(const Plane& plane) const; static constexpr bool ApproxEqual(const Plane& lhs, const Plane& rhs, T maxDifference = std::numeric_limits::epsilon()); static constexpr Vector3 Intersect(const Plane& p0, const Plane& p1, const Plane& p2); static constexpr Plane Lerp(const Plane& from, const Plane& to, T interpolation); static Plane Normalize(const Plane& plane, T* length = nullptr); static constexpr Plane XY(); static constexpr Plane XZ(); static constexpr Plane YZ(); Vector3 normal; T distance; }; using Planed = Plane; using Planef = Plane; template bool Serialize(SerializationContext& context, const Plane& plane, TypeTag>); template bool Unserialize(SerializationContext& context, Plane* plane, TypeTag>); template std::ostream& operator<<(std::ostream& out, const Nz::Plane& plane); } #include #endif // NAZARA_MATH_PLANE_HPP