Jet  v1.3.3
sphere3.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_SPHERE3_H_
8 #define INCLUDE_JET_SPHERE3_H_
9 
10 #include <jet/surface3.h>
11 #include <jet/bounding_box3.h>
12 
13 namespace jet {
14 
21 class Sphere3 final : public Surface3 {
22  public:
23  class Builder;
24 
27 
29  double radius = 1.0;
30 
33  const Transform3& transform = Transform3(),
34  bool isNormalFlipped = false);
35 
38  const Vector3D& center,
39  double radius,
40  const Transform3& transform = Transform3(),
41  bool isNormalFlipped = false);
42 
44  Sphere3(const Sphere3& other);
45 
47  static Builder builder();
48 
49  private:
50  Vector3D closestPointLocal(const Vector3D& otherPoint) const override;
51 
52  double closestDistanceLocal(const Vector3D& otherPoint) const override;
53 
54  bool intersectsLocal(const Ray3D& ray) const override;
55 
56  BoundingBox3D boundingBoxLocal() const override;
57 
58  Vector3D closestNormalLocal(const Vector3D& otherPoint) const override;
59 
60  SurfaceRayIntersection3 closestIntersectionLocal(
61  const Ray3D& ray) const override;
62 };
63 
65 typedef std::shared_ptr<Sphere3> Sphere3Ptr;
66 
70 class Sphere3::Builder final : public SurfaceBuilderBase3<Sphere3::Builder>{
71  public:
74 
77 
79  Sphere3 build() const;
80 
83 
84  private:
85  Vector3D _center{0, 0, 0};
86  double _radius = 0.0;
87 };
88 
89 } // namespace jet
90 
91 
92 #endif // INCLUDE_JET_SPHERE3_H_
surface3.h
jet::BoundingBox< T, 3 >
3-D axis-aligned bounding box class.
Definition: bounding_box3.h:41
jet::Sphere3::radius
double radius
Radius of the sphere.
Definition: sphere3.h:29
jet::Sphere3::Sphere3
Sphere3(const Vector3D &center, double radius, const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs a sphere with center and radius.
jet::SurfaceBuilderBase3
Base class for 3-D surface builder.
Definition: surface3.h:115
jet::Surface3::isNormalFlipped
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: surface3.h:33
jet::Sphere3
3-D sphere geometry.
Definition: sphere3.h:21
jet::Sphere3::Builder::withRadius
Builder & withRadius(double radius)
Returns builder with sphere radius.
jet
Definition: advection_solver2.h:18
jet::Sphere3::Sphere3
Sphere3(const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs a sphere with center at (0, 0, 0) and radius of 1.
jet::Sphere3::Sphere3
Sphere3(const Sphere3 &other)
Copy constructor.
jet::Sphere3::Builder::build
Sphere3 build() const
Builds Sphere3.
jet::Surface3::transform
Transform3 transform
Local-to-world transform.
Definition: surface3.h:30
jet::Ray< T, 3 >
Class for 2-D ray.
Definition: ray3.h:21
jet::Sphere3::builder
static Builder builder()
Returns builder fox Sphere3.
jet::SurfaceRayIntersection3
Struct that represents ray-surface intersection point.
Definition: surface3.h:19
jet::Sphere3::Builder
Front-end to create Sphere3 objects step by step.
Definition: sphere3.h:70
jet::Sphere3::Builder::withCenter
Builder & withCenter(const Vector3D &center)
Returns builder with sphere center.
jet::Vector< T, 3 >
3-D vector class.
Definition: vector3.h:25
bounding_box3.h
jet::Transform3
Represents 3-D rigid body transform.
Definition: transform3.h:20
jet::Sphere3::Builder::makeShared
Sphere3Ptr makeShared() const
Builds shared pointer of Sphere3 instance.
jet::Surface3
Abstract base class for 3-D surface.
Definition: surface3.h:27
jet::Sphere3Ptr
std::shared_ptr< Sphere3 > Sphere3Ptr
Shared pointer for the Sphere3 type.
Definition: sphere3.h:65
jet::Sphere3::center
Vector3D center
Center of the sphere.
Definition: sphere3.h:23