Collider3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Collider3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Abstract base class for generic collider object.
6 > Created Time: 2017/05/09
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_COLLIDER3_H
10 #define CUBBYFLOW_COLLIDER3_H
11 
12 #include <Core/Surface/Surface3.h>
13 
14 #include <functional>
15 
16 namespace CubbyFlow
17 {
27  class Collider3
28  {
29  public:
36  using OnBeginUpdateCallback = std::function<void(Collider3*, double, double)>;
37 
39  Collider3();
40 
42  virtual ~Collider3();
43 
45  virtual Vector3D VelocityAt(const Vector3D& point) const = 0;
46 
55  void ResolveCollision(double radius, double restitutionCoefficient, Vector3D* position, Vector3D* velocity);
56 
58  double GetFrictionCoefficient() const;
59 
66  void SetFrictionCoefficient(double newFrictionCoeffient);
67 
69  const Surface3Ptr& GetSurface() const;
70 
72  void Update(double currentTimeInSeconds, double timeIntervalInSeconds);
73 
84  void SetOnBeginUpdateCallback(const OnBeginUpdateCallback& callback);
85 
86  protected:
88  struct ColliderQueryResult final
89  {
90  double distance;
94  };
95 
97  void SetSurface(const Surface3Ptr& newSurface);
98 
100  void GetClosestPoint(const Surface3Ptr& surface, const Vector3D& queryPoint, ColliderQueryResult* result) const;
101 
103  bool IsPenetrating(const ColliderQueryResult& colliderPoint, const Vector3D& position, double radius);
104 
105  private:
106  Surface3Ptr m_surface;
107  double m_frictionCoeffient = 0.0;
108  OnBeginUpdateCallback m_onUpdateCallback;
109  };
110 
112  using Collider3Ptr = std::shared_ptr<Collider3>;
113 }
114 
115 #endif
3-D vector class.
Definition: Vector3.h:26
virtual ~Collider3()
Default destructor.
std::shared_ptr< Collider3 > Collider3Ptr
Shared pointer type for the Collider3.
Definition: Collider3.h:112
void Update(double currentTimeInSeconds, double timeIntervalInSeconds)
Updates the collider state.
std::function< void(Collider3 *, double, double)> OnBeginUpdateCallback
Callback function type for update calls.
Definition: Collider3.h:36
const Surface3Ptr & GetSurface() const
Returns the surface instance.
void ResolveCollision(double radius, double restitutionCoefficient, Vector3D *position, Vector3D *velocity)
virtual Vector3D VelocityAt(const Vector3D &point) const =0
Returns the velocity of the collider at given point.
Collider3()
Default constructor.
Internal query result structure.
Definition: Collider3.h:88
double distance
Definition: Collider3.h:90
Vector3D point
Definition: Collider3.h:91
Vector3D normal
Definition: Collider3.h:92
void SetFrictionCoefficient(double newFrictionCoeffient)
Sets the friction coefficient.
Definition: pybind11Utils.h:24
std::shared_ptr< Surface3 > Surface3Ptr
Shared pointer for the Surface3 type.
Definition: Surface3.h:100
void GetClosestPoint(const Surface3Ptr &surface, const Vector3D &queryPoint, ColliderQueryResult *result) const
Outputs closest point&#39;s information.
bool IsPenetrating(const ColliderQueryResult &colliderPoint, const Vector3D &position, double radius)
Returns true if given point is in the opposite side of the surface.
Vector3D velocity
Definition: Collider3.h:93
double GetFrictionCoefficient() const
Returns friction coefficient.
void SetOnBeginUpdateCallback(const OnBeginUpdateCallback &callback)
Sets the callback function to be called when Collider3::update function is invoked.
void SetSurface(const Surface3Ptr &newSurface)
Assigns the surface instance from the subclass.
Abstract base class for generic collider object.
Definition: Collider3.h:27