physics
contact.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "body.hpp"
7 #include "spherical_joint.hpp"
8 #include "hinge_joint.hpp"
9 #include "mouse_joint.hpp"
10 #include "collision.hpp"
11 
12 enum ContactType { FACE=0, EDGE=1};
13 
17 class Contact {
18 public:
19  vec3 normal = vec3(0,0,0);
20  vec3 tangent = vec3(0,0,0);
21  vec3 bitangent = vec3(0,0,0);
23  float penetration = 0;
24  float bias = 0;
26  float effective_mass_tangent = 0.0f;
27  float effective_mass_normal = 0.0f;
28  float Pn = 0;
29  float Pt = 0;
30  float Pbt = 0;
33 
36 
38  vector<int> id;
39  int warmStartNo = 0;
43  Contact(CollisionBody &hullA, CollisionBody &hullB);
47  int applyImpulse();
51  int preStep(float dt);
52 
53  static vector<Contact> allContacts;
54  static unsigned int iterations;
55 
56 };
57 
61 vector<Contact> getContacts(CollisionBody &body);
65 vector<Face> getMostParallelFace(const CollisionBody &hull, vec3 normal);
69 vector<Face> getMostAntiparallelFace(const CollisionBody &hull, vec3 normal);
73 vector<Face> getOrthogonalFaces(const CollisionBody &hull, vec3 normal);
109 vector<Contact> createMinimalContacts(vector<Contact> &contacts);
113 vec3 closestPointOnTri(vec3 sphereCentre, vec3 p0, vec3 p1, vec3 p2);
121 int simulate(float deltaTime);
122 
124 
125 
vector< Contact > boxCylinderContacts(CollisionBody &body_a, CollisionBody &body_b)
A data structure to contain the data received from a collision between a box and a box...
int warmStartNo
Definition: contact.hpp:39
A data structure to pass data received from a collision to the solver.
Definition: contact.hpp:17
vec3 tangent
Definition: contact.hpp:20
CollisionBody * col_body_b
Definition: contact.hpp:35
float Pn
Definition: contact.hpp:28
vec3 normal
Definition: contact.hpp:19
RigidBody * body_a
Definition: contact.hpp:31
int preStep(float dt)
Apply impulse from previous frame for better coherence.
ContactType
Definition: contact.hpp:12
CollisionBody * col_body_a
Definition: contact.hpp:34
vector< Contact > sphereTriContacts(CollisionBody &body_a, CollisionBody &body_b)
A data structure to contain the data received from a collision between a sphere and a tri...
vector< Contact > sphereSphereContacts(CollisionBody &body_a, CollisionBody &body_b)
A data structure to contain the data received from a collision between a sphere and a sphere...
static vector< Contact > allContacts
Definition: contact.hpp:53
float bias
Definition: contact.hpp:24
int applyImpulse()
Impulse-solver function, applies both normal impulse and friction impulses.
vector< Contact > cylinderCylinderContacts(CollisionBody &body_a, CollisionBody &body_b)
A data structure to contain the data received from a collision between a Cylinder and a Cylinder...
vector< Face > getMostAntiparallelFace(const CollisionBody &hull, vec3 normal)
Find the Face on the CollisionBody that is most anti-parallel to the vector, normal.
vector< Contact > sphereBoxContacts(CollisionBody &body_a, CollisionBody &body_b)
A data structure to contain the data received from a collision between a sphere and a box...
RigidBody structure for organising data to model physics simulations of convex hull collisions...
Definition: body.hpp:224
vec3 closestPointOnTri(vec3 sphereCentre, vec3 p0, vec3 p1, vec3 p2)
Return the point on a tri that is closest to a point.
vector< Contact > hullHullContacts(CollisionBody &body_a, CollisionBody &body_b)
A data structure to contain the data received from a collision between a box and a box...
vector< vec3 > collisionPoints(CollisionBody &body_a, CollisionBody &body_b)
Return collision points on each CollisionBody.
vector< Contact > createMinimalContacts(vector< Contact > &contacts)
Reduce a vector of Contact&#39;s to 4 that are the most stable.
ContactType type
Definition: contact.hpp:37
float Pbt
Definition: contact.hpp:30
float effective_mass_normal
Definition: contact.hpp:27
static unsigned int iterations
Definition: contact.hpp:54
vector< Face > getOrthogonalFaces(const CollisionBody &hull, vec3 normal)
Find the Face&#39;s that are orthogonal to the vector, normal, used for clipping to generate contact poin...
Contact(CollisionBody &hullA, CollisionBody &hullB)
Constructor, instantiated with the collision query between two CollisionBody objects.
vector< Contact > createContacts(CollisionBody &body_a, CollisionBody &body_b)
Generate contacts between two CollisionBody&#39;s.
vec3 bitangent
Definition: contact.hpp:21
vector< Contact > getContacts(CollisionBody &body)
Get contacts for a CollisionBody.
vector< Contact > sphereCylinderContacts(CollisionBody &body_a, CollisionBody &body_b)
A data structure to contain the data received from a collision between a Sphere and a Cylinder...
float penetration
Definition: contact.hpp:23
float effective_mass_tangent
Definition: contact.hpp:26
CollisionBody structure for organising data to model physics simulations of convex hull collisions...
Definition: body.hpp:121
vector< int > id
Definition: contact.hpp:38
vector< Face > getMostParallelFace(const CollisionBody &hull, vec3 normal)
Find the Face on the CollisionBody that is most parallel to the vector, normal.
float Pt
Definition: contact.hpp:29
RigidBody * body_b
Definition: contact.hpp:32
Definition: contact.hpp:12
Definition: contact.hpp:12
int simulate(float deltaTime)
Access function for the physics time step function, called on the client-side manually in the update ...
vec3 collision_point
Definition: contact.hpp:22
vector< Contact > GJKEPAContacts(CollisionBody &body_a, CollisionBody &body_b)
float effective_mass_bitangent
Definition: contact.hpp:25