Loading...
Searching...
No Matches
Collider.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_COLLIDER_HPP
12#define CUBBYFLOW_COLLIDER_HPP
13
15
16#include <functional>
17
18namespace CubbyFlow
19{
29template <size_t N>
31{
32 public:
40 std::function<void(Collider*, double, double)>;
41
43 Collider() = default;
44
46 virtual ~Collider() = default;
47
49 Collider(const Collider& other) = default;
50
52 Collider(Collider&& other) noexcept = default;
53
55 Collider& operator=(const Collider& other) = default;
56
58 Collider& operator=(Collider&& other) noexcept = default;
59
61 [[nodiscard]] virtual Vector<double, N> VelocityAt(
62 const Vector<double, N>& point) const = 0;
63
72 void ResolveCollision(double radius, double restitutionCoefficient,
73 Vector<double, N>* position,
74 Vector<double, N>* velocity);
75
77 [[nodiscard]] double GetFrictionCoefficient() const;
78
85 void SetFrictionCoefficient(double newFrictionCoefficient);
86
88 [[nodiscard]] const std::shared_ptr<Surface<N>>& GetSurface() const;
89
91 void Update(double currentTimeInSeconds, double timeIntervalInSeconds);
92
104
105 protected:
114
116 void SetSurface(const std::shared_ptr<Surface<N>>& newSurface);
117
119 void GetClosestPoint(const std::shared_ptr<Surface<N>>& surface,
120 const Vector<double, N>& queryPoint,
121 ColliderQueryResult* result) const;
122
124 [[nodiscard]] bool IsPenetrating(const ColliderQueryResult& colliderPoint,
125 const Vector<double, N>& position,
126 double radius);
127
128 private:
129 std::shared_ptr<Surface<N>> m_surface;
130 double m_frictionCoefficient = 0.0;
131 OnBeginUpdateCallback m_onUpdateCallback;
132};
133
136
139
141using Collider2Ptr = std::shared_ptr<Collider2>;
142
144using Collider3Ptr = std::shared_ptr<Collider3>;
145} // namespace CubbyFlow
146
147#endif
Abstract base class for generic collider object.
Definition Collider.hpp:31
void Update(double currentTimeInSeconds, double timeIntervalInSeconds)
Updates the collider state.
double GetFrictionCoefficient() const
Returns friction coefficient.
Collider(const Collider &other)=default
Default copy constructor.
void SetOnBeginUpdateCallback(const OnBeginUpdateCallback &callback)
Sets the callback function to be called when Collider::update function is invoked.
Collider(Collider &&other) noexcept=default
Default move constructor.
Collider & operator=(const Collider &other)=default
Default copy assignment operator.
bool IsPenetrating(const ColliderQueryResult &colliderPoint, const Vector< double, N > &position, double radius)
Returns true if given point is in the opposite side of the surface.
void GetClosestPoint(const std::shared_ptr< Surface< N > > &surface, const Vector< double, N > &queryPoint, ColliderQueryResult *result) const
Outputs closest point's information.
std::function< void(Collider *, double, double)> OnBeginUpdateCallback
Callback function type for update calls.
Definition Collider.hpp:40
Collider()=default
Default constructor.
virtual ~Collider()=default
Default virtual destructor.
Collider & operator=(Collider &&other) noexcept=default
Default move assignment operator.
void SetFrictionCoefficient(double newFrictionCoefficient)
Sets the friction coefficient.
const std::shared_ptr< Surface< N > > & GetSurface() const
Returns the surface instance.
virtual Vector< double, N > VelocityAt(const Vector< double, N > &point) const =0
Returns the velocity of the collider at given point.
void SetSurface(const std::shared_ptr< Surface< N > > &newSurface)
Assigns the surface instance from the subclass.
void ResolveCollision(double radius, double restitutionCoefficient, Vector< double, N > *position, Vector< double, N > *velocity)
Definition Matrix.hpp:30
Abstract base class for N-D surface.
Definition Surface.hpp:39
Definition pybind11Utils.hpp:21
std::shared_ptr< Collider2 > Collider2Ptr
Shared pointer type for the Collider2.
Definition Collider.hpp:141
std::shared_ptr< Collider3 > Collider3Ptr
Shared pointer type for the Collider3.
Definition Collider.hpp:144
Internal query result structure.
Definition Collider.hpp:108
Vector< double, N > point
Definition Collider.hpp:110
double distance
Definition Collider.hpp:109
Vector< double, N > velocity
Definition Collider.hpp:112
Vector< double, N > normal
Definition Collider.hpp:111