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