RigidBodyCollider.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_RIGID_BODY_COLLIDER_HPP
12 #define CUBBYFLOW_RIGID_BODY_COLLIDER_HPP
13 
15 
16 #include <utility>
17 
18 namespace CubbyFlow
19 {
20 template <size_t N>
22 {
23  // Do nothing
24 };
25 
26 template <>
28 {
29  public:
30  AngularVelocity() = default;
31 
32  AngularVelocity(double _value) : value(_value)
33  {
34  // Do nothing
35  }
36 
37  [[nodiscard]] Vector2D Cross(const Vector2D& r) const
38  {
39  return value * Vector2D{ -r.y, r.x };
40  }
41 
42  double value = 0.0;
43 };
44 
45 template <>
47 {
48  public:
49  AngularVelocity() = default;
50 
51  AngularVelocity(std::initializer_list<double> lst) : value(lst)
52  {
53  // Do nothing
54  }
55 
56  AngularVelocity(Vector3D _value) : value(std::move(_value))
57  {
58  // Do nothing
59  }
60 
61  [[nodiscard]] Vector3D Cross(const Vector3D& r) const
62  {
63  return value.Cross(r);
64  }
65 
67 };
68 
70 
72 
79 template <size_t N>
80 class RigidBodyCollider final : public Collider<N>
81 {
82  public:
83  class Builder;
84 
87 
89  explicit RigidBodyCollider(const std::shared_ptr<Surface<N>>& surface);
90 
92  RigidBodyCollider(const std::shared_ptr<Surface<N>>& surface,
93  const Vector<double, N>& _linearVelocity,
94  const AngularVelocity<N>& _angularVelocity);
95 
97  [[nodiscard]] Vector<double, N> VelocityAt(
98  const Vector<double, N>& point) const override;
99 
101  static Builder GetBuilder();
102 
105 
108 };
109 
112 
115 
117 using RigidBodyCollider2Ptr = std::shared_ptr<RigidBodyCollider2>;
118 
120 using RigidBodyCollider3Ptr = std::shared_ptr<RigidBodyCollider3>;
121 
125 template <size_t N>
126 class RigidBodyCollider<N>::Builder final
127 {
128  public:
130  Builder& WithSurface(const std::shared_ptr<Surface<N>>& surface);
131 
133  Builder& WithLinearVelocity(const Vector<double, N>& _linearVelocity);
134 
136  Builder& WithAngularVelocity(const AngularVelocity<N>& _angularVelocity);
137 
139  RigidBodyCollider Build() const;
140 
142  std::shared_ptr<RigidBodyCollider<N>> MakeShared() const;
143 
144  private:
145  std::shared_ptr<Surface<N>> m_surface;
146  Vector<double, N> m_linearVelocity;
147  AngularVelocity<N> m_angularVelocity;
148 };
149 } // namespace CubbyFlow
150 
151 #endif
AngularVelocity(std::initializer_list< double > lst)
Definition: RigidBodyCollider.hpp:51
std::shared_ptr< RigidBodyCollider2 > RigidBodyCollider2Ptr
Shared pointer for the RigidBodyCollider2 type.
Definition: RigidBodyCollider.hpp:117
N-D rigid body collider class.
Definition: RigidBodyCollider.hpp:80
AngularVelocity(Vector3D _value)
Definition: RigidBodyCollider.hpp:56
Vector3D Cross(const Vector3D &r) const
Definition: RigidBodyCollider.hpp:61
AngularVelocity< N > angularVelocity
Angular velocity of the rigid body.
Definition: RigidBodyCollider.hpp:107
Definition: RigidBodyCollider.hpp:21
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
AngularVelocity(double _value)
Definition: RigidBodyCollider.hpp:32
Abstract base class for N-D surface.
Definition: Surface.hpp:38
std::enable_if_t<(IsMatrixSizeDynamic< Rows, Cols >)||(Rows==2 &&Cols==1)) &&(IsMatrixSizeDynamic< R, C >)||(R==2 &&C==1)), U > Cross(const MatrixExpression< T, R, C, E > &expression) const
Definition: MatrixExpression-Impl.hpp:412
Vector3D value
Definition: RigidBodyCollider.hpp:66
Front-end to create RigidBodyCollider objects step by step.
Definition: RigidBodyCollider.hpp:126
Vector2D Cross(const Vector2D &r) const
Definition: RigidBodyCollider.hpp:37
std::shared_ptr< RigidBodyCollider3 > RigidBodyCollider3Ptr
Shared pointer for the RigidBodyCollider3 type.
Definition: RigidBodyCollider.hpp:120
Abstract base class for generic collider object.
Definition: Collider.hpp:30
Definition: RigidBodyCollider.hpp:27
Vector< double, N > linearVelocity
Linear velocity of the rigid body.
Definition: RigidBodyCollider.hpp:104
Definition: RigidBodyCollider.hpp:46