Loading...
Searching...
No Matches
Sphere.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_SPHERE_HPP
12#define CUBBYFLOW_SPHERE_HPP
13
15
16namespace CubbyFlow
17{
24template <size_t N>
25class Sphere final : public Surface<N>
26{
27 public:
28 class Builder;
29
32 {
33 // Do nothing
34 }
35
37 explicit Sphere(const Transform<N>& _transform,
38 bool _isNormalFlipped = false);
39
42 const Transform<N>& _transform = Transform<N>{},
43 bool _isNormalFlipped = false);
44
46 ~Sphere() override = default;
47
49 Sphere(const Sphere& other);
50
52 Sphere(Sphere&& other) noexcept;
53
55 Sphere& operator=(const Sphere& other);
56
58 Sphere& operator=(Sphere&& other) noexcept;
59
62
65
67 double radius = 1.0;
68
69 private:
70 [[nodiscard]] Vector<double, N> ClosestPointLocal(
71 const Vector<double, N>& otherPoint) const override;
72
73 [[nodiscard]] double ClosestDistanceLocal(
74 const Vector<double, N>& otherPoint) const override;
75
76 [[nodiscard]] bool IntersectsLocal(
77 const Ray<double, N>& ray) const override;
78
79 [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
80
81 [[nodiscard]] Vector<double, N> ClosestNormalLocal(
82 const Vector<double, N>& otherPoint) const override;
83
84 [[nodiscard]] SurfaceRayIntersection<N> ClosestIntersectionLocal(
85 const Ray<double, N>& ray) const override;
86};
87
90
93
95using Sphere2Ptr = std::shared_ptr<Sphere2>;
96
98using Sphere3Ptr = std::shared_ptr<Sphere3>;
99
103template <size_t N>
104class Sphere<N>::Builder final
105 : public SurfaceBuilderBase<N, typename Sphere<N>::Builder>
106{
107 public:
110
112 Builder& WithRadius(double _radius);
113
116
118 std::shared_ptr<Sphere<N>> MakeShared() const;
119
120 private:
122 using Base::m_isNormalFlipped;
123 using Base::m_transform;
124
125 Vector<double, N> m_center;
126 double m_radius = 0.0;
127};
128} // namespace CubbyFlow
129
130#endif
N-D axis-aligned bounding box class.
Definition BoundingBox.hpp:47
Definition Matrix.hpp:30
Class for N-D ray.
Definition Ray.hpp:26
Front-end to create Sphere objects step by step.
Definition Sphere.hpp:106
Builder & WithRadius(double _radius)
Returns builder with sphere radius.
std::shared_ptr< Sphere< N > > MakeShared() const
Builds shared pointer of Sphere instance.
Builder & WithCenter(const Vector< double, N > &_center)
Returns builder with sphere center.
Sphere< N > Build() const
Builds Sphere.
N-D sphere geometry.
Definition Sphere.hpp:26
Sphere(const Sphere &other)
Copy constructor.
double radius
Radius of the sphere.
Definition Sphere.hpp:67
Vector< double, N > center
Center of the sphere.
Definition Sphere.hpp:64
Sphere & operator=(const Sphere &other)
Copy assignment operator.
Sphere & operator=(Sphere &&other) noexcept
Move assignment operator.
static Builder GetBuilder()
Returns builder fox Sphere.
Sphere()
Constructs a sphere with center at the origin and radius of 1.
Definition Sphere.hpp:31
Sphere(const Vector< double, N > &center, double radius, const Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
Constructs a sphere with center and radius.
Sphere(const Transform< N > &_transform, bool _isNormalFlipped=false)
Constructs a default sphere with a transform.
~Sphere() override=default
Default virtual destructor.
Sphere(Sphere &&other) noexcept
Move constructor.
Base class for N-D surface builder.
Definition Surface.hpp:154
Abstract base class for N-D surface.
Definition Surface.hpp:39
Represents N-D rigid body transform.
Definition Transform.hpp:83
Definition pybind11Utils.hpp:22
std::shared_ptr< Sphere3 > Sphere3Ptr
Shared pointer for the Sphere3 type.
Definition Sphere.hpp:98
std::shared_ptr< Sphere2 > Sphere2Ptr
Shared pointer for the Sphere2 type.
Definition Sphere.hpp:95
Struct that represents ray-surface intersection point.
Definition Surface.hpp:26