// Copyright (C) 2021 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_SPHERE_HPP #define NAZARA_MATH_SPHERE_HPP #include #include namespace Nz { struct SerializationContext; template class Box; template class Sphere { public: Sphere() = default; Sphere(T X, T Y, T Z, T Radius); //Sphere(const Circle& circle); Sphere(const Vector3& center, T Radius); Sphere(const T sphere[4]); template explicit Sphere(const Sphere& sphere); Sphere(const Sphere& sphere) = default; ~Sphere() = default; bool Contains(T X, T Y, T Z) const; bool Contains(const Box& box) const; bool Contains(const Vector3& point) const; T Distance(T X, T Y, T Z) const; T Distance(const Vector3& point) const; Sphere& ExtendTo(T X, T Y, T Z); Sphere& ExtendTo(const Vector3& point); Vector3 GetNegativeVertex(const Vector3& normal) const; Vector3 GetPosition() const; Vector3 GetPositiveVertex(const Vector3& normal) const; bool Intersect(const Box& box) const; bool Intersect(const Sphere& sphere) const; bool IsValid() const; Sphere& MakeUnit(); Sphere& MakeZero(); Sphere& Set(T X, T Y, T Z, T Radius); //Sphere& Set(const Circle& rect); Sphere& Set(const Vector3& center, T Radius); Sphere& Set(const T sphere[4]); template Sphere& Set(const Sphere& sphere); std::string ToString() const; T& operator[](std::size_t i); T operator[](std::size_t i) const; Sphere operator*(T scalar) const; Sphere& operator=(const Sphere& other) = default; Sphere& operator*=(T scalar); bool operator==(const Sphere& sphere) const; bool operator!=(const Sphere& sphere) const; static Sphere Lerp(const Sphere& from, const Sphere& to, T interpolation); static Sphere Unit(); static Sphere Zero(); T x, y, z, radius; }; using Sphered = Sphere; using Spheref = Sphere; template bool Serialize(SerializationContext& context, const Sphere& sphere, TypeTag>); template bool Unserialize(SerializationContext& context, Sphere* sphere, TypeTag>); } template std::ostream& operator<<(std::ostream& out, const Nz::Sphere& sphere); #include #endif // NAZARA_MATH_SPHERE_HPP