2010-09-09 22:06:57 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ *
|
2013-03-02 15:26:18 +00:00
|
|
|
* Copyright (c) 2010-2013 Daniel Chappuis *
|
2010-09-09 22:06:57 +00:00
|
|
|
*********************************************************************************
|
|
|
|
* *
|
2011-11-13 17:49:03 +00:00
|
|
|
* This software is provided 'as-is', without any express or implied warranty. *
|
|
|
|
* In no event will the authors be held liable for any damages arising from the *
|
|
|
|
* use of this software. *
|
2010-09-09 22:06:57 +00:00
|
|
|
* *
|
2011-11-13 17:49:03 +00:00
|
|
|
* Permission is granted to anyone to use this software for any purpose, *
|
|
|
|
* including commercial applications, and to alter it and redistribute it *
|
|
|
|
* freely, subject to the following restrictions: *
|
|
|
|
* *
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
|
|
* that you wrote the original software. If you use this software in a *
|
|
|
|
* product, an acknowledgment in the product documentation would be *
|
|
|
|
* appreciated but is not required. *
|
|
|
|
* *
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
|
|
* misrepresented as being the original software. *
|
|
|
|
* *
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution. *
|
2010-09-09 22:06:57 +00:00
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
2013-04-18 20:54:36 +00:00
|
|
|
#ifndef REACTPHYSICS3D_CONSTRAINT_H
|
|
|
|
#define REACTPHYSICS3D_CONSTRAINT_H
|
2010-09-09 22:06:57 +00:00
|
|
|
|
|
|
|
// Libraries
|
2013-05-08 21:33:04 +00:00
|
|
|
#include "../configuration.h"
|
2012-09-18 20:09:49 +00:00
|
|
|
#include "../body/RigidBody.h"
|
2010-09-09 22:06:57 +00:00
|
|
|
#include "../mathematics/mathematics.h"
|
|
|
|
|
|
|
|
// ReactPhysics3D namespace
|
|
|
|
namespace reactphysics3d {
|
2013-05-29 20:45:02 +00:00
|
|
|
|
2012-01-18 23:06:33 +00:00
|
|
|
// Enumeration for the type of a constraint
|
2013-06-12 18:43:54 +00:00
|
|
|
enum ConstraintType {CONTACT, BALLSOCKETJOINT, SLIDERJOINT, HINGEJOINT, FIXEDJOINT};
|
2010-09-09 22:06:57 +00:00
|
|
|
|
2013-05-02 20:41:57 +00:00
|
|
|
// Class declarations
|
|
|
|
struct ConstraintSolverData;
|
2013-08-26 19:28:48 +00:00
|
|
|
class Constraint;
|
|
|
|
|
|
|
|
// Structure JointListElement
|
|
|
|
/**
|
|
|
|
* This structure represents a single element of a linked list of joints
|
|
|
|
*/
|
|
|
|
struct JointListElement {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// -------------------- Attributes -------------------- //
|
|
|
|
|
|
|
|
/// Pointer to the actual joint
|
|
|
|
Constraint* joint;
|
|
|
|
|
|
|
|
/// Next element of the list
|
|
|
|
JointListElement* next;
|
|
|
|
|
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
JointListElement(Constraint* initJoint, JointListElement* initNext)
|
|
|
|
:joint(initJoint), next(initNext){
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2013-05-02 20:41:57 +00:00
|
|
|
|
2013-04-24 17:24:28 +00:00
|
|
|
// Structure ConstraintInfo
|
|
|
|
/**
|
|
|
|
* This structure is used to gather the information needed to create a constraint.
|
|
|
|
*/
|
|
|
|
struct ConstraintInfo {
|
|
|
|
|
|
|
|
public :
|
|
|
|
|
|
|
|
// -------------------- Attributes -------------------- //
|
|
|
|
|
|
|
|
/// First rigid body of the constraint
|
|
|
|
RigidBody* body1;
|
|
|
|
|
|
|
|
/// Second rigid body of the constraint
|
|
|
|
RigidBody* body2;
|
|
|
|
|
|
|
|
/// Type of the constraint
|
|
|
|
ConstraintType type;
|
|
|
|
|
2013-06-26 20:28:31 +00:00
|
|
|
/// True if the two bodies of the constraint are allowed to collide with each other
|
|
|
|
bool isCollisionEnabled;
|
|
|
|
|
2013-05-08 21:33:04 +00:00
|
|
|
/// Position correction technique used for the constraint (used for joints).
|
|
|
|
/// By default, the BAUMGARTE technique is used
|
|
|
|
JointsPositionCorrectionTechnique positionCorrectionTechnique;
|
|
|
|
|
2013-04-24 17:24:28 +00:00
|
|
|
/// Constructor
|
|
|
|
ConstraintInfo(ConstraintType constraintType)
|
2013-05-08 21:33:04 +00:00
|
|
|
: body1(NULL), body2(NULL), type(constraintType),
|
2013-06-26 20:28:31 +00:00
|
|
|
positionCorrectionTechnique(NON_LINEAR_GAUSS_SEIDEL),
|
|
|
|
isCollisionEnabled(true) {}
|
2013-04-24 17:24:28 +00:00
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
ConstraintInfo(RigidBody* rigidBody1, RigidBody* rigidBody2, ConstraintType constraintType)
|
2013-05-08 21:33:04 +00:00
|
|
|
: body1(rigidBody1), body2(rigidBody2), type(constraintType),
|
2013-06-26 20:28:31 +00:00
|
|
|
positionCorrectionTechnique(NON_LINEAR_GAUSS_SEIDEL),
|
|
|
|
isCollisionEnabled(true) {
|
2013-04-24 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
virtual ~ConstraintInfo() {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
// Class Constraint
|
|
|
|
/**
|
|
|
|
* This abstract class represents a constraint in the physics engine.
|
2013-08-26 19:28:48 +00:00
|
|
|
* A constraint can be a collision contact point or a joint for
|
|
|
|
* instance.
|
2013-03-05 22:09:50 +00:00
|
|
|
*/
|
2010-09-09 22:06:57 +00:00
|
|
|
class Constraint {
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2010-09-09 22:06:57 +00:00
|
|
|
protected :
|
2012-10-09 20:21:02 +00:00
|
|
|
|
|
|
|
// -------------------- Attributes -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Pointer to the first body of the constraint
|
2012-10-09 20:21:02 +00:00
|
|
|
RigidBody* const mBody1;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Pointer to the second body of the constraint
|
2012-10-09 20:21:02 +00:00
|
|
|
RigidBody* const mBody2;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// True if the constraint is active
|
2012-10-09 20:21:02 +00:00
|
|
|
bool mActive;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Type of the constraint
|
2012-10-09 20:21:02 +00:00
|
|
|
const ConstraintType mType;
|
|
|
|
|
2013-05-02 20:41:57 +00:00
|
|
|
/// Body 1 index in the velocity array to solve the constraint
|
|
|
|
uint mIndexBody1;
|
|
|
|
|
|
|
|
/// Body 2 index in the velocity array to solve the constraint
|
|
|
|
uint mIndexBody2;
|
|
|
|
|
2013-05-08 21:33:04 +00:00
|
|
|
/// Position correction technique used for the constraint (used for joints)
|
|
|
|
JointsPositionCorrectionTechnique mPositionCorrectionTechnique;
|
|
|
|
|
2013-06-26 20:28:31 +00:00
|
|
|
/// True if the two bodies of the constraint are allowed to collide with each other
|
|
|
|
bool mIsCollisionEnabled;
|
|
|
|
|
2013-08-26 19:28:48 +00:00
|
|
|
/// True if the joint has already been added into an island
|
|
|
|
bool mIsAlreadyInIsland;
|
|
|
|
|
2012-10-09 20:21:02 +00:00
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Private copy-constructor
|
2012-10-09 20:21:02 +00:00
|
|
|
Constraint(const Constraint& constraint);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Private assignment operator
|
2012-10-09 20:21:02 +00:00
|
|
|
Constraint& operator=(const Constraint& constraint);
|
2010-09-11 16:25:43 +00:00
|
|
|
|
2010-09-09 22:06:57 +00:00
|
|
|
public :
|
2012-10-09 20:21:02 +00:00
|
|
|
|
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Constructor
|
2013-04-24 17:24:28 +00:00
|
|
|
Constraint(const ConstraintInfo& constraintInfo);
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Destructor
|
2012-10-09 20:21:02 +00:00
|
|
|
virtual ~Constraint();
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the reference to the body 1
|
2012-10-09 20:21:02 +00:00
|
|
|
RigidBody* const getBody1() const;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the reference to the body 2
|
2012-10-09 20:21:02 +00:00
|
|
|
RigidBody* const getBody2() const;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return true if the constraint is active
|
2012-10-09 20:21:02 +00:00
|
|
|
bool isActive() const;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the type of the constraint
|
2012-10-09 20:21:02 +00:00
|
|
|
ConstraintType getType() const;
|
2013-04-24 17:24:28 +00:00
|
|
|
|
2013-06-26 20:28:31 +00:00
|
|
|
/// Return true if the collision between the two bodies of the constraint is enabled
|
|
|
|
bool isCollisionEnabled() const;
|
|
|
|
|
2013-08-26 19:28:48 +00:00
|
|
|
/// Return true if the joint has already been added into an island
|
|
|
|
bool isAlreadyInIsland() const;
|
|
|
|
|
2013-04-24 17:24:28 +00:00
|
|
|
/// Return the number of bytes used by the constraint
|
|
|
|
virtual size_t getSizeInBytes() const = 0;
|
2013-05-02 20:41:57 +00:00
|
|
|
|
|
|
|
/// Initialize before solving the constraint
|
|
|
|
virtual void initBeforeSolve(const ConstraintSolverData& constraintSolverData) = 0;
|
|
|
|
|
2013-05-12 10:43:07 +00:00
|
|
|
/// Warm start the constraint (apply the previous impulse at the beginning of the step)
|
|
|
|
virtual void warmstart(const ConstraintSolverData& constraintSolverData) = 0;
|
|
|
|
|
2013-05-08 21:33:04 +00:00
|
|
|
/// Solve the velocity constraint
|
|
|
|
virtual void solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) = 0;
|
|
|
|
|
|
|
|
/// Solve the position constraint
|
|
|
|
virtual void solvePositionConstraint(const ConstraintSolverData& constraintSolverData) = 0;
|
2013-08-26 19:28:48 +00:00
|
|
|
|
|
|
|
// -------------------- Friendship -------------------- //
|
|
|
|
|
|
|
|
friend class DynamicsWorld;
|
|
|
|
friend class Island;
|
2010-09-09 22:06:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Return the reference to the body 1
|
2012-09-18 20:09:49 +00:00
|
|
|
inline RigidBody* const Constraint::getBody1() const {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mBody1;
|
2010-09-09 22:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the reference to the body 2
|
2012-09-18 20:09:49 +00:00
|
|
|
inline RigidBody* const Constraint::getBody2() const {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mBody2;
|
2010-09-09 22:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if the constraint is active
|
|
|
|
inline bool Constraint::isActive() const {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mActive;
|
2010-09-09 22:06:57 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 23:06:33 +00:00
|
|
|
// Return the type of the constraint
|
|
|
|
inline ConstraintType Constraint::getType() const {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mType;
|
2013-06-26 20:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if the collision between the two bodies of the constraint is enabled
|
|
|
|
inline bool Constraint::isCollisionEnabled() const {
|
|
|
|
return mIsCollisionEnabled;
|
|
|
|
}
|
2011-10-18 22:03:05 +00:00
|
|
|
|
2013-08-26 19:28:48 +00:00
|
|
|
// Return true if the joint has already been added into an island
|
|
|
|
inline bool Constraint::isAlreadyInIsland() const {
|
|
|
|
return mIsAlreadyInIsland;
|
|
|
|
}
|
|
|
|
|
2013-02-28 18:50:52 +00:00
|
|
|
}
|
2010-09-09 22:06:57 +00:00
|
|
|
|
|
|
|
#endif
|