Sphere3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Sphere3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D sphere geometry.
6 > Created Time: 2017/04/04
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SPHERE3_H
10 #define CUBBYFLOW_SPHERE3_H
11 
12 #include <Core/Surface/Surface3.h>
13 
14 namespace CubbyFlow
15 {
22  class Sphere3 final : public Surface3
23  {
24  public:
25  class Builder;
26 
29 
31  double radius = 1.0;
32 
34  Sphere3(
35  const Transform3& transform = Transform3(),
36  bool isNormalFlipped = false);
37 
39  Sphere3(
40  const Vector3D& center,
41  double radius,
42  const Transform3& transform = Transform3(),
43  bool isNormalFlipped = false);
44 
46  Sphere3(const Sphere3& other);
47 
49  static Builder GetBuilder();
50 
51  private:
52  Vector3D ClosestPointLocal(const Vector3D& otherPoint) const override;
53 
54  double ClosestDistanceLocal(const Vector3D& otherPoint) const override;
55 
56  bool IntersectsLocal(const Ray3D& ray) const override;
57 
58  BoundingBox3D BoundingBoxLocal() const override;
59 
60  Vector3D ClosestNormalLocal(const Vector3D& otherPoint) const override;
61 
62  SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D& ray) const override;
63  };
64 
66  using Sphere3Ptr = std::shared_ptr<Sphere3>;
67 
71  class Sphere3::Builder final : public SurfaceBuilderBase3<Sphere3::Builder>
72  {
73  public:
76 
78  Builder& WithRadius(double radius);
79 
81  Sphere3 Build() const;
82 
84  Sphere3Ptr MakeShared() const;
85 
86  private:
87  Vector3D m_center = { 0, 0, 0 };
88  double m_radius = 0.0;
89  };
90 }
91 
92 #endif
static Builder GetBuilder()
Returns builder fox Sphere3.
3-D vector class.
Definition: Vector3.h:26
std::shared_ptr< Sphere3 > Sphere3Ptr
Shared pointer for the Sphere3 type.
Definition: Sphere3.h:66
Sphere3(const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs a sphere with center at (0, 0, 0) and radius of 1.
Structure that represents ray-surface intersection point.
Definition: Surface3.h:23
Base class for 3-D surface builder.
Definition: Surface3.h:106
Vector3D center
Center of the sphere.
Definition: Sphere3.h:25
3-D sphere geometry.
Definition: Sphere3.h:22
Definition: pybind11Utils.h:24
Sphere3 Build() const
Builds Sphere3.
Abstract base class for 3-D surface.
Definition: Surface3.h:32
Transform3 transform
Local-to-world transform.
Definition: Surface3.h:36
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
Represents 3-D rigid body transform.
Definition: Transform3.h:22
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: Surface3.h:39
Builder & WithCenter(const Vector3D &center)
Returns builder with sphere center.
Builder & WithRadius(double radius)
Returns builder with sphere radius.
double radius
Radius of the sphere.
Definition: Sphere3.h:31
Class for 3-D ray.
Definition: Ray3.h:23
Sphere3Ptr MakeShared() const
Builds shared pointer of Sphere3 instance.
Front-end to create Sphere3 objects step by step.
Definition: Sphere3.h:71