sandbox
Loading...
Searching...
No Matches
sphere.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_MATH_SPHERE_HPP_
3#define LIBSBX_MATH_SPHERE_HPP_
4
6#include <libsbx/math/vector3.hpp>
7
8namespace sbx::math {
9
10template<scalar Type>
12
13public:
14
15 using value_type = Type;
17
18 basic_sphere() noexcept = default;
19
20 basic_sphere(const vector_type& center, const value_type radius) noexcept
21 : _center{center},
22 _radius{radius} { }
23
24 static auto transformed(const basic_sphere& sphere, const math::matrix4x4& matrix) -> basic_sphere {
25 // [NOTE] KAJ 2025-04-28 : We may need to add a scale factor to the radius here.
26 const auto transformed_center = math::vector3{matrix * math::vector4{sphere._center, 1.0f}};
27 return basic_sphere{transformed_center, sphere._radius};
28 }
29
30 auto center() const noexcept -> const vector_type& {
31 return _center;
32 }
33
34 auto radius() const noexcept -> value_type {
35 return _radius;
36 }
37
38private:
39
40 vector_type _center;
41 value_type _radius;
42
43}; // class basic_sphere
44
46
47using sphere = spheref;
48
49} // namespace sbx::math
50
51#endif // LIBSBX_MATH_SPHERE_HPP_
Definition: matrix4x4.hpp:26
Definition: sphere.hpp:11
Definition: vector4.hpp:24
Core numeric concepts and type traits.