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
31 Sphere(const Transform<N>& _transform = Transform<N>{},
32 bool _isNormalFlipped = false);
33
36 const Transform<N>& _transform = Transform<N>{},
37 bool _isNormalFlipped = false);
38
40 ~Sphere() override = default;
41
43 Sphere(const Sphere& other);
44
46 Sphere(Sphere&& other) noexcept;
47
49 Sphere& operator=(const Sphere& other);
50
52 Sphere& operator=(Sphere&& other) noexcept;
53
56
59
61 double radius = 1.0;
62
63 private:
64 [[nodiscard]] Vector<double, N> ClosestPointLocal(
65 const Vector<double, N>& otherPoint) const override;
66
67 [[nodiscard]] double ClosestDistanceLocal(
68 const Vector<double, N>& otherPoint) const override;
69
70 [[nodiscard]] bool IntersectsLocal(
71 const Ray<double, N>& ray) const override;
72
73 [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
74
75 [[nodiscard]] Vector<double, N> ClosestNormalLocal(
76 const Vector<double, N>& otherPoint) const override;
77
78 [[nodiscard]] SurfaceRayIntersection<N> ClosestIntersectionLocal(
79 const Ray<double, N>& ray) const override;
80};
81
84
87
89using Sphere2Ptr = std::shared_ptr<Sphere2>;
90
92using Sphere3Ptr = std::shared_ptr<Sphere3>;
93
97template <size_t N>
98class Sphere<N>::Builder final
99 : public SurfaceBuilderBase<N, typename Sphere<N>::Builder>
100{
101 public:
104
106 Builder& WithRadius(double _radius);
107
110
112 std::shared_ptr<Sphere<N>> MakeShared() const;
113
114 private:
116 using Base::m_isNormalFlipped;
117 using Base::m_transform;
118
119 Vector<double, N> m_center;
120 double m_radius = 0.0;
121};
122} // namespace CubbyFlow
123
124#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:100
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 Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
Constructs a sphere with center at the origin and radius of 1.
Sphere(const Sphere &other)
Copy constructor.
double radius
Radius of the sphere.
Definition Sphere.hpp:61
Vector< double, N > center
Center of the sphere.
Definition Sphere.hpp:58
Sphere & operator=(const Sphere &other)
Copy assignment operator.
Sphere & operator=(Sphere &&other) noexcept
Move assignment operator.
static Builder GetBuilder()
Returns builder fox Sphere.
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() 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:21
std::shared_ptr< Sphere3 > Sphere3Ptr
Shared pointer for the Sphere3 type.
Definition Sphere.hpp:92
std::shared_ptr< Sphere2 > Sphere2Ptr
Shared pointer for the Sphere2 type.
Definition Sphere.hpp:89
Struct that represents ray-surface intersection point.
Definition Surface.hpp:26