hx3d  1
2D/3D Simple Game Framework
manifold.hpp
1 /*
2  Contact manifold.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_PHYSICS_2D_MANIFOLD
22 #define HX3D_PHYSICS_2D_MANIFOLD
23 
24 #include "hx3d/physics/2d/colliders/polygon.hpp"
25 #include "hx3d/physics/2d/colliders/circle.hpp"
26 
27 namespace hx3d {
28 namespace physics2d {
29 
33 class Manifold {
34 public:
39 
41  float penetration;
42 
44  bool disabled;
45 
47  glm::vec2 normal;
49  std::vector<glm::vec2> contacts;
50 
52  float mixedRestitution; // e
54  float mixedDynamicFriction; // df
56  float mixedStaticFriction; // sf
57 
59 
66  Manifold(const Ptr<Collider>& a, const Ptr<Collider>& b);
67 
71  bool solve();
72 
76  void initialize();
77 
81  void applyImpulse();
82 
86  void positionalCorrection();
87 
92 
93  friend bool operator<(const Manifold& m1, const Manifold& m2);
94 };
95 
99 bool operator<(const Manifold& m1, const Manifold& m2);
100 
101 } /* physics2d */
102 } /* hx3d */
103 
104 #endif
Manifold(const Ptr< Collider > &a, const Ptr< Collider > &b)
Create a manifold.
Definition: manifold.cpp:10
std::vector< glm::vec2 > contacts
Contact points.
Definition: manifold.hpp:49
hx3d framework namespace
Definition: audio.hpp:26
Ptr< Collider > b
Second collider.
Definition: manifold.hpp:38
friend bool operator<(const Manifold &m1, const Manifold &m2)
Compare two manifolds using their penetration coefficients.
Definition: manifold.cpp:126
bool disabled
Is the contact disabled ?
Definition: manifold.hpp:44
void initialize()
Initialize the manifold.
Definition: manifold.cpp:34
float mixedStaticFriction
Mixed static friction (sf)
Definition: manifold.hpp:56
float penetration
Penetration coefficient.
Definition: manifold.hpp:41
bool solve()
Solve the contact.
Definition: manifold.cpp:19
float mixedDynamicFriction
Mixed dynamic friction (df)
Definition: manifold.hpp:54
Contact manifold definition.
Definition: manifold.hpp:33
void positionalCorrection()
Do positional correction on the colliders.
Definition: manifold.cpp:107
void applyImpulse()
Apply impulses to the colliders.
Definition: manifold.cpp:53
void infiniteMassCorrection()
Do infinite mass correction on the colliders.
Definition: manifold.cpp:119
Ptr< Collider > a
First collider.
Definition: manifold.hpp:36
float mixedRestitution
Mixed restitution (e)
Definition: manifold.hpp:52
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34
glm::vec2 normal
Normal vector.
Definition: manifold.hpp:47