Dura2D  v0.1.0
An educational 2D game physics library
Loading...
Searching...
No Matches
d2Constraint.h
Go to the documentation of this file.
1#ifndef CONSTRAINT_H
2#define CONSTRAINT_H
3
4#include "d2Body.h"
5
7{
8public:
11
12 d2Vec2 aPoint; // The constraint point in A's local space
13 d2Vec2 bPoint; // The constraint point in B's local space
14
17
18 virtual ~d2Constraint() = default;
19
21
23
24 virtual void PreSolve(const real dt) { (void)dt; }
25
26 virtual void Solve() {}
27
28 virtual void PostSolve() {}
29
30 void SetNext(d2Constraint* next) { this->next = next; }
31
32 void SetPrev(d2Constraint* prev) { this->prev = prev; }
33
34 d2Constraint* GetNext() { return next; }
35 const d2Constraint* GetNext() const { return next; }
36
37 d2Constraint* GetPrev() { return prev; }
38 const d2Constraint* GetPrev() const { return prev; }
39};
40
42{
43private:
44 d2MatMN jacobian;
45 d2VecN cachedLambda;
46 real bias;
47
48public:
50
51 d2JointConstraint(d2Body *a, d2Body *b, const d2Vec2 &anchorPoint);
52
53 void PreSolve(const real dt) override;
54
55 void Solve() override;
56
57 void PostSolve() override;
58};
59
61{
62private:
63 d2MatMN jacobian;
64 d2VecN cachedLambda;
65 real bias;
66 d2Vec2 normal; // Normal direction of the penetration in A's local space
67 real friction; // Friction coefficient between the two penetrating m_bodiesList
68
69public:
71
73 d2Body *b,
74 const d2Vec2 &aCollisionPoint,
75 const d2Vec2 &bCollisionPoint,
76 const d2Vec2 &normal);
77
78 void PreSolve(const real dt) override;
79
80 void Solve() override;
81
82 void PostSolve() override;
83};
84
85#endif
A class representing a 2D rigid body.
Definition d2Body.h:28
Definition d2Constraint.h:7
d2Body * a
Definition d2Constraint.h:9
d2Vec2 bPoint
Definition d2Constraint.h:13
d2VecN GetVelocities() const
const d2Constraint * GetNext() const
Definition d2Constraint.h:35
virtual void PreSolve(const real dt)
Definition d2Constraint.h:24
d2Vec2 aPoint
Definition d2Constraint.h:12
void SetPrev(d2Constraint *prev)
Definition d2Constraint.h:32
void SetNext(d2Constraint *next)
Definition d2Constraint.h:30
virtual void PostSolve()
Definition d2Constraint.h:28
d2Body * b
Definition d2Constraint.h:10
virtual void Solve()
Definition d2Constraint.h:26
d2Constraint * GetPrev()
Definition d2Constraint.h:37
const d2Constraint * GetPrev() const
Definition d2Constraint.h:38
d2Constraint * next
Definition d2Constraint.h:15
virtual ~d2Constraint()=default
d2Constraint * prev
Definition d2Constraint.h:16
d2Constraint * GetNext()
Definition d2Constraint.h:34
d2MatMN GetInvM() const
Definition d2Constraint.h:42
void Solve() override
d2JointConstraint(d2Body *a, d2Body *b, const d2Vec2 &anchorPoint)
void PostSolve() override
void PreSolve(const real dt) override
Definition d2Constraint.h:61
void Solve() override
d2PenetrationConstraint(d2Body *a, d2Body *b, const d2Vec2 &aCollisionPoint, const d2Vec2 &bCollisionPoint, const d2Vec2 &normal)
void PostSolve() override
void PreSolve(const real dt) override
float real
Definition d2Types.h:10
Represents an MxN matrix.
Definition d2Math.h:161
Represents a 2D vector.
Definition d2Math.h:22
Represents an N-dimensional vector.
Definition d2Math.h:114