Loading...
Searching...
No Matches
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
18namespace CubbyFlow
19{
20template <size_t N>
22{
23 // Do nothing
24};
25
26template <>
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
45template <>
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
79template <size_t N>
80class RigidBodyCollider final : public Collider<N>
81{
82 public:
83 class Builder;
84
85 using Collider<N>::GetSurface;
86 using Collider<N>::SetSurface;
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
98 const Vector<double, N>& point) const override;
99
102
105
108};
109
112
115
117using RigidBodyCollider2Ptr = std::shared_ptr<RigidBodyCollider2>;
118
120using RigidBodyCollider3Ptr = std::shared_ptr<RigidBodyCollider3>;
121
125template <size_t N>
127{
128 public:
130 Builder& WithSurface(const std::shared_ptr<Surface<N>>& surface);
131
134
137
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
Definition RigidBodyCollider.hpp:28
Vector2D Cross(const Vector2D &r) const
Definition RigidBodyCollider.hpp:37
AngularVelocity(double _value)
Definition RigidBodyCollider.hpp:32
Definition RigidBodyCollider.hpp:47
Vector3D value
Definition RigidBodyCollider.hpp:66
AngularVelocity(std::initializer_list< double > lst)
Definition RigidBodyCollider.hpp:51
AngularVelocity(Vector3D _value)
Definition RigidBodyCollider.hpp:56
Vector3D Cross(const Vector3D &r) const
Definition RigidBodyCollider.hpp:61
Definition RigidBodyCollider.hpp:22
Abstract base class for generic collider object.
Definition Collider.hpp:31
const std::shared_ptr< Surface< N > > & GetSurface() const
Returns the surface instance.
void SetSurface(const std::shared_ptr< Surface< N > > &newSurface)
Assigns the surface instance from the subclass.
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
Definition Matrix.hpp:30
Front-end to create RigidBodyCollider objects step by step.
Definition RigidBodyCollider.hpp:127
Builder & WithLinearVelocity(const Vector< double, N > &_linearVelocity)
Returns builder with linear velocity.
Builder & WithSurface(const std::shared_ptr< Surface< N > > &surface)
Returns builder with surface.
Builder & WithAngularVelocity(const AngularVelocity< N > &_angularVelocity)
Returns builder with angular velocity.
std::shared_ptr< RigidBodyCollider< N > > MakeShared() const
Builds shared pointer of RigidBodyCollider instance.
RigidBodyCollider Build() const
Builds RigidBodyCollider.
N-D rigid body collider class.
Definition RigidBodyCollider.hpp:81
RigidBodyCollider(const std::shared_ptr< Surface< N > > &surface)
Constructs a collider with a surface.
static Builder GetBuilder()
Returns builder fox RigidBodyCollider.
RigidBodyCollider(const std::shared_ptr< Surface< N > > &surface, const Vector< double, N > &_linearVelocity, const AngularVelocity< N > &_angularVelocity)
Constructs a collider with a surface and other parameters.
Vector< double, N > linearVelocity
Linear velocity of the rigid body.
Definition RigidBodyCollider.hpp:104
AngularVelocity< N > angularVelocity
Angular velocity of the rigid body.
Definition RigidBodyCollider.hpp:107
Vector< double, N > VelocityAt(const Vector< double, N > &point) const override
Returns the velocity of the collider at given point.
Abstract base class for N-D surface.
Definition Surface.hpp:39
Definition pybind11Utils.hpp:21
std::shared_ptr< RigidBodyCollider3 > RigidBodyCollider3Ptr
Shared pointer for the RigidBodyCollider3 type.
Definition RigidBodyCollider.hpp:120
std::shared_ptr< RigidBodyCollider2 > RigidBodyCollider2Ptr
Shared pointer for the RigidBodyCollider2 type.
Definition RigidBodyCollider.hpp:117