2009-07-03 12:17:18 +00:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Copyright (C) 2009 Daniel Chappuis *
|
|
|
|
|
****************************************************************************
|
|
|
|
|
* This file is part of ReactPhysics3D. *
|
|
|
|
|
* *
|
|
|
|
|
* ReactPhysics3D is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published *
|
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* ReactPhysics3D is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
|
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef CONTACT_H
|
|
|
|
|
#define CONTACT_H
|
|
|
|
|
|
|
|
|
|
// Libraries
|
|
|
|
|
#include "Constraint.h"
|
|
|
|
|
#include "../mathematics/mathematics.h"
|
|
|
|
|
|
|
|
|
|
// ReactPhysics3D namespace
|
|
|
|
|
namespace reactphysics3d {
|
|
|
|
|
|
2010-03-28 21:54:41 +00:00
|
|
|
|
// Constants
|
|
|
|
|
const double FRICTION_COEFFICIENT = 0.2; // Friction coefficient
|
|
|
|
|
const double PENETRATION_FACTOR = 0.1; // Penetration factor (between 0 and 1) which specify the importance of the
|
|
|
|
|
// penetration depth in order to calculate the correct impulse for the contact
|
|
|
|
|
|
2009-07-03 12:17:18 +00:00
|
|
|
|
/* -------------------------------------------------------------------
|
|
|
|
|
Class Contact :
|
|
|
|
|
This class represents a collision contact between two bodies in
|
|
|
|
|
the physics engine. The contact class inherits from the
|
2010-03-10 22:28:40 +00:00
|
|
|
|
Constraint class. The collision detection system computes
|
2009-07-03 12:17:18 +00:00
|
|
|
|
contact informations that will be used to perform the collision
|
2010-03-28 21:54:41 +00:00
|
|
|
|
response. Each contact contains only one contact point. A contact
|
|
|
|
|
constraint has two auxiliary constraints in order two represent
|
|
|
|
|
the two friction forces at the contact surface.
|
2009-07-03 12:17:18 +00:00
|
|
|
|
-------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
class Contact : public Constraint {
|
2010-02-18 22:26:48 +00:00
|
|
|
|
protected :
|
2010-03-28 21:54:41 +00:00
|
|
|
|
const Vector3D normal; // Normal vector of the contact (From body1 toward body2)
|
|
|
|
|
const double penetrationDepth; // Penetration depth
|
|
|
|
|
const Vector3D point; // Contact point
|
2010-03-10 22:28:40 +00:00
|
|
|
|
std::vector<Vector3D> frictionVectors; // Two orthogonal vectors that span the tangential friction plane
|
2010-02-18 22:26:48 +00:00
|
|
|
|
|
2010-03-10 22:28:40 +00:00
|
|
|
|
void computeFrictionVectors(); // Compute the two friction vectors that span the tangential friction plane
|
2009-07-03 12:17:18 +00:00
|
|
|
|
|
|
|
|
|
public :
|
2010-03-28 21:54:41 +00:00
|
|
|
|
Contact(Body* const body1, Body* const body2, const Vector3D& normal, double penetrationDepth, const Vector3D& point); // Constructor
|
|
|
|
|
virtual ~Contact(); // Destructor
|
2009-07-03 12:17:18 +00:00
|
|
|
|
|
2010-02-18 22:26:48 +00:00
|
|
|
|
Vector3D getNormal() const; // Return the normal vector of the contact
|
2010-03-28 21:54:41 +00:00
|
|
|
|
Vector3D getPoint() const; // Return the contact point
|
2010-03-10 22:28:40 +00:00
|
|
|
|
virtual void evaluate(); // Evaluate the constraint
|
2010-03-28 21:54:41 +00:00
|
|
|
|
unsigned int getNbAuxConstraints() const; // Return the number of auxiliary constraints
|
2010-02-06 19:39:33 +00:00
|
|
|
|
|
2010-03-28 21:54:41 +00:00
|
|
|
|
void draw() const; // TODO : Delete this (Used to debug collision detection)
|
2009-07-03 12:17:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
2010-03-28 21:54:41 +00:00
|
|
|
|
// Compute the two unit orthogonal vectors "v1" and "v2" that span the tangential friction plane
|
2010-03-10 22:28:40 +00:00
|
|
|
|
// The two vectors have to be such that : v1 x v2 = contactNormal
|
|
|
|
|
inline void Contact::computeFrictionVectors() {
|
2010-02-18 22:26:48 +00:00
|
|
|
|
// Delete the current friction vectors
|
|
|
|
|
frictionVectors.clear();
|
|
|
|
|
|
2010-03-28 21:54:41 +00:00
|
|
|
|
// Compute the first orthogonal vector
|
|
|
|
|
Vector3D vector1 = normal.getOneOrthogonalVector();
|
|
|
|
|
frictionVectors.push_back(vector1);
|
|
|
|
|
|
|
|
|
|
// Compute the second orthogonal vector using the cross product
|
|
|
|
|
frictionVectors.push_back(normal.crossProduct(vector1));
|
2010-02-18 22:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-03 12:17:18 +00:00
|
|
|
|
// Return the normal vector of the contact
|
2009-11-29 21:55:41 +00:00
|
|
|
|
inline Vector3D Contact::getNormal() const {
|
|
|
|
|
return normal;
|
2009-08-06 12:10:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-06 19:39:33 +00:00
|
|
|
|
// Return the contact points
|
2010-03-28 21:54:41 +00:00
|
|
|
|
inline Vector3D Contact::getPoint() const {
|
|
|
|
|
return point;
|
2010-02-06 19:39:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-07-03 12:17:18 +00:00
|
|
|
|
} // End of the ReactPhysics3D namespace
|
|
|
|
|
|
|
|
|
|
#endif
|