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
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONSTRAINT_H
|
|
|
|
#define CONSTRAINT_H
|
|
|
|
|
|
|
|
// Libraries
|
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 {
|
2012-01-18 23:06:33 +00:00
|
|
|
|
|
|
|
// Enumeration for the type of a constraint
|
|
|
|
enum ConstraintType {CONTACT};
|
2010-09-09 22:06:57 +00:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------
|
|
|
|
Class Constraint :
|
|
|
|
This abstract class represents a constraint in the physics engine.
|
|
|
|
A constraint can be a collision contact or a joint for
|
2010-09-11 16:25:43 +00:00
|
|
|
instance. Each constraint can be made of several "mathematical
|
|
|
|
constraints" needed to represent the main constraint.
|
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 -------------------- //
|
|
|
|
|
|
|
|
// Pointer to the first body of the constraint
|
|
|
|
RigidBody* const mBody1;
|
|
|
|
|
|
|
|
// Pointer to the second body of the constraint
|
|
|
|
RigidBody* const mBody2;
|
|
|
|
|
|
|
|
// True if the constraint is active
|
|
|
|
bool mActive;
|
|
|
|
|
|
|
|
// Number mathematical constraints associated with this Constraint
|
|
|
|
uint mNbConstraints;
|
|
|
|
|
|
|
|
// Type of the constraint
|
|
|
|
const ConstraintType mType;
|
|
|
|
|
|
|
|
// Cached lambda values of each mathematical constraint for
|
|
|
|
// more precise initializaton of LCP solver
|
|
|
|
std::vector<decimal> mCachedLambdas;
|
|
|
|
|
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
|
|
|
// Private copy-constructor
|
|
|
|
Constraint(const Constraint& constraint);
|
|
|
|
|
|
|
|
// Private assignment operator
|
|
|
|
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 -------------------- //
|
|
|
|
|
|
|
|
// Constructor
|
2012-09-18 20:09:49 +00:00
|
|
|
Constraint(RigidBody* const body1, RigidBody* const body2, uint nbConstraints,
|
2012-10-09 20:21:02 +00:00
|
|
|
bool active, ConstraintType type);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
virtual ~Constraint();
|
|
|
|
|
|
|
|
// Return the reference to the body 1
|
|
|
|
RigidBody* const getBody1() const;
|
|
|
|
|
|
|
|
// Return the reference to the body 2
|
|
|
|
RigidBody* const getBody2() const;
|
|
|
|
|
|
|
|
// Return true if the constraint is active
|
|
|
|
bool isActive() const;
|
|
|
|
|
|
|
|
// Return the type of the constraint
|
|
|
|
ConstraintType getType() const;
|
|
|
|
|
|
|
|
// Return the number of mathematical constraints
|
|
|
|
unsigned int getNbConstraints() const;
|
|
|
|
|
|
|
|
// Get one cached lambda value
|
|
|
|
decimal getCachedLambda(int index) const;
|
|
|
|
|
|
|
|
// Set on cached lambda value
|
|
|
|
void setCachedLambda(int index, decimal lambda);
|
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;
|
2012-01-18 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 22:06:57 +00:00
|
|
|
// Return the number auxiliary constraints
|
2010-09-11 16:25:43 +00:00
|
|
|
inline uint Constraint::getNbConstraints() const {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mNbConstraints;
|
2010-09-09 22:06:57 +00:00
|
|
|
}
|
|
|
|
|
2011-10-18 22:03:05 +00:00
|
|
|
// Get one previous lambda value
|
2012-01-18 23:06:33 +00:00
|
|
|
inline decimal Constraint::getCachedLambda(int index) const {
|
2012-10-09 20:21:02 +00:00
|
|
|
assert(index >= 0 && index < mNbConstraints);
|
|
|
|
return mCachedLambdas[index];
|
2011-10-18 22:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set on cached lambda value
|
2012-01-18 23:06:33 +00:00
|
|
|
inline void Constraint::setCachedLambda(int index, decimal lambda) {
|
2012-10-09 20:21:02 +00:00
|
|
|
assert(index >= 0 && index < mNbConstraints);
|
|
|
|
mCachedLambdas[index] = lambda;
|
2011-10-18 22:03:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 18:50:52 +00:00
|
|
|
}
|
2010-09-09 22:06:57 +00:00
|
|
|
|
|
|
|
#endif
|