[DEV] continue renaming
This commit is contained in:
parent
b8685d12c3
commit
64da8e8c51
@ -19,14 +19,14 @@ using namespace reactphysics3d;
|
||||
* @param id ID of the body
|
||||
*/
|
||||
CollisionBody::CollisionBody(const Transform& transform, CollisionWorld& world, bodyindex id)
|
||||
: Body(id), mType(DYNAMIC), mTransform(transform), mProxyCollisionShapes(NULL),
|
||||
mNbCollisionShapes(0), mContactManifoldsList(NULL), mWorld(world) {
|
||||
: Body(id), m_type(DYNAMIC), m_transform(transform), m_proxyCollisionShapes(NULL),
|
||||
m_numberCollisionShapes(0), m_contactManifoldsList(NULL), m_world(world) {
|
||||
|
||||
}
|
||||
|
||||
// Destructor
|
||||
CollisionBody::~CollisionBody() {
|
||||
assert(mContactManifoldsList == NULL);
|
||||
assert(m_contactManifoldsList == NULL);
|
||||
|
||||
// Remove all the proxy collision shapes of the body
|
||||
removeAllCollisionShapes();
|
||||
@ -51,27 +51,27 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape,
|
||||
const Transform& transform) {
|
||||
|
||||
// Create a new proxy collision shape to attach the collision shape to the body
|
||||
ProxyShape* proxyShape = new (mWorld.mMemoryAllocator.allocate(
|
||||
ProxyShape* proxyShape = new (m_world.m_memoryAllocator.allocate(
|
||||
sizeof(ProxyShape))) ProxyShape(this, collisionShape,
|
||||
transform, float(1));
|
||||
|
||||
// Add it to the list of proxy collision shapes of the body
|
||||
if (mProxyCollisionShapes == NULL) {
|
||||
mProxyCollisionShapes = proxyShape;
|
||||
if (m_proxyCollisionShapes == NULL) {
|
||||
m_proxyCollisionShapes = proxyShape;
|
||||
}
|
||||
else {
|
||||
proxyShape->mNext = mProxyCollisionShapes;
|
||||
mProxyCollisionShapes = proxyShape;
|
||||
proxyShape->m_next = m_proxyCollisionShapes;
|
||||
m_proxyCollisionShapes = proxyShape;
|
||||
}
|
||||
|
||||
// Compute the world-space AABB of the new collision shape
|
||||
AABB aabb;
|
||||
collisionShape->computeAABB(aabb, mTransform * transform);
|
||||
collisionShape->computeAABB(aabb, m_transform * transform);
|
||||
|
||||
// Notify the collision detection about this new collision shape
|
||||
mWorld.m_collisionDetection.addProxyCollisionShape(proxyShape, aabb);
|
||||
m_world.m_collisionDetection.addProxyCollisionShape(proxyShape, aabb);
|
||||
|
||||
mNbCollisionShapes++;
|
||||
m_numberCollisionShapes++;
|
||||
|
||||
// Return a pointer to the collision shape
|
||||
return proxyShape;
|
||||
@ -86,94 +86,94 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape,
|
||||
*/
|
||||
void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) {
|
||||
|
||||
ProxyShape* current = mProxyCollisionShapes;
|
||||
ProxyShape* current = m_proxyCollisionShapes;
|
||||
|
||||
// If the the first proxy shape is the one to remove
|
||||
if (current == proxyShape) {
|
||||
mProxyCollisionShapes = current->mNext;
|
||||
m_proxyCollisionShapes = current->m_next;
|
||||
|
||||
if (m_isActive) {
|
||||
mWorld.m_collisionDetection.removeProxyCollisionShape(current);
|
||||
m_world.m_collisionDetection.removeProxyCollisionShape(current);
|
||||
}
|
||||
|
||||
current->~ProxyShape();
|
||||
mWorld.mMemoryAllocator.release(current, sizeof(ProxyShape));
|
||||
mNbCollisionShapes--;
|
||||
m_world.m_memoryAllocator.release(current, sizeof(ProxyShape));
|
||||
m_numberCollisionShapes--;
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for the proxy shape that contains the collision shape in parameter
|
||||
while(current->mNext != NULL) {
|
||||
while(current->m_next != NULL) {
|
||||
|
||||
// If we have found the collision shape to remove
|
||||
if (current->mNext == proxyShape) {
|
||||
if (current->m_next == proxyShape) {
|
||||
|
||||
// Remove the proxy collision shape
|
||||
ProxyShape* elementToRemove = current->mNext;
|
||||
current->mNext = elementToRemove->mNext;
|
||||
ProxyShape* elementToRemove = current->m_next;
|
||||
current->m_next = elementToRemove->m_next;
|
||||
|
||||
if (m_isActive) {
|
||||
mWorld.m_collisionDetection.removeProxyCollisionShape(elementToRemove);
|
||||
m_world.m_collisionDetection.removeProxyCollisionShape(elementToRemove);
|
||||
}
|
||||
|
||||
elementToRemove->~ProxyShape();
|
||||
mWorld.mMemoryAllocator.release(elementToRemove, sizeof(ProxyShape));
|
||||
mNbCollisionShapes--;
|
||||
m_world.m_memoryAllocator.release(elementToRemove, sizeof(ProxyShape));
|
||||
m_numberCollisionShapes--;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the next element in the list
|
||||
current = current->mNext;
|
||||
current = current->m_next;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all the collision shapes
|
||||
void CollisionBody::removeAllCollisionShapes() {
|
||||
|
||||
ProxyShape* current = mProxyCollisionShapes;
|
||||
ProxyShape* current = m_proxyCollisionShapes;
|
||||
|
||||
// Look for the proxy shape that contains the collision shape in parameter
|
||||
while(current != NULL) {
|
||||
|
||||
// Remove the proxy collision shape
|
||||
ProxyShape* nextElement = current->mNext;
|
||||
ProxyShape* nextElement = current->m_next;
|
||||
|
||||
if (m_isActive) {
|
||||
mWorld.m_collisionDetection.removeProxyCollisionShape(current);
|
||||
m_world.m_collisionDetection.removeProxyCollisionShape(current);
|
||||
}
|
||||
|
||||
current->~ProxyShape();
|
||||
mWorld.mMemoryAllocator.release(current, sizeof(ProxyShape));
|
||||
m_world.m_memoryAllocator.release(current, sizeof(ProxyShape));
|
||||
|
||||
// Get the next element in the list
|
||||
current = nextElement;
|
||||
}
|
||||
|
||||
mProxyCollisionShapes = NULL;
|
||||
m_proxyCollisionShapes = NULL;
|
||||
}
|
||||
|
||||
// Reset the contact manifold lists
|
||||
void CollisionBody::resetContactManifoldsList() {
|
||||
|
||||
// Delete the linked list of contact manifolds of that body
|
||||
ContactManifoldListElement* currentElement = mContactManifoldsList;
|
||||
ContactManifoldListElement* currentElement = m_contactManifoldsList;
|
||||
while (currentElement != NULL) {
|
||||
ContactManifoldListElement* nextElement = currentElement->next;
|
||||
|
||||
// Delete the current element
|
||||
currentElement->~ContactManifoldListElement();
|
||||
mWorld.mMemoryAllocator.release(currentElement, sizeof(ContactManifoldListElement));
|
||||
m_world.m_memoryAllocator.release(currentElement, sizeof(ContactManifoldListElement));
|
||||
|
||||
currentElement = nextElement;
|
||||
}
|
||||
mContactManifoldsList = NULL;
|
||||
m_contactManifoldsList = NULL;
|
||||
}
|
||||
|
||||
// Update the broad-phase state for this body (because it has moved for instance)
|
||||
void CollisionBody::updateBroadPhaseState() const {
|
||||
|
||||
// For all the proxy collision shapes of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Update the proxy
|
||||
updateProxyShapeInBroadPhase(shape);
|
||||
@ -185,10 +185,10 @@ void CollisionBody::updateProxyShapeInBroadPhase(ProxyShape* proxyShape, bool fo
|
||||
|
||||
// Recompute the world-space AABB of the collision shape
|
||||
AABB aabb;
|
||||
proxyShape->getCollisionShape()->computeAABB(aabb, mTransform * proxyShape->getLocalToBodyTransform());
|
||||
proxyShape->getCollisionShape()->computeAABB(aabb, m_transform * proxyShape->getLocalToBodyTransform());
|
||||
|
||||
// Update the broad-phase state for the proxy collision shape
|
||||
mWorld.m_collisionDetection.updateProxyCollisionShape(proxyShape, aabb, Vector3(0, 0, 0), forceReinsert);
|
||||
m_world.m_collisionDetection.updateProxyCollisionShape(proxyShape, aabb, Vector3(0, 0, 0), forceReinsert);
|
||||
}
|
||||
|
||||
// Set whether or not the body is active
|
||||
@ -206,23 +206,23 @@ void CollisionBody::setIsActive(bool isActive) {
|
||||
if (isActive) {
|
||||
|
||||
// For each proxy shape of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Compute the world-space AABB of the new collision shape
|
||||
AABB aabb;
|
||||
shape->getCollisionShape()->computeAABB(aabb, mTransform * shape->mLocalToBodyTransform);
|
||||
shape->getCollisionShape()->computeAABB(aabb, m_transform * shape->m_localToBodyTransform);
|
||||
|
||||
// Add the proxy shape to the collision detection
|
||||
mWorld.m_collisionDetection.addProxyCollisionShape(shape, aabb);
|
||||
m_world.m_collisionDetection.addProxyCollisionShape(shape, aabb);
|
||||
}
|
||||
}
|
||||
else { // If we have to deactivate the body
|
||||
|
||||
// For each proxy shape of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Remove the proxy shape from the collision detection
|
||||
mWorld.m_collisionDetection.removeProxyCollisionShape(shape);
|
||||
m_world.m_collisionDetection.removeProxyCollisionShape(shape);
|
||||
}
|
||||
|
||||
// Reset the contact manifold list of the body
|
||||
@ -235,9 +235,9 @@ void CollisionBody::setIsActive(bool isActive) {
|
||||
void CollisionBody::askForBroadPhaseCollisionCheck() const {
|
||||
|
||||
// For all the proxy collision shapes of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
mWorld.m_collisionDetection.askForBroadPhaseCollisionCheck(shape);
|
||||
m_world.m_collisionDetection.askForBroadPhaseCollisionCheck(shape);
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ int32_t CollisionBody::resetIsAlreadyInIslandAndCountManifolds() {
|
||||
|
||||
// Reset the m_isAlreadyInIsland variable of the contact manifolds for
|
||||
// this body
|
||||
ContactManifoldListElement* currentElement = mContactManifoldsList;
|
||||
ContactManifoldListElement* currentElement = m_contactManifoldsList;
|
||||
while (currentElement != NULL) {
|
||||
currentElement->contactManifold->m_isAlreadyInIsland = false;
|
||||
currentElement = currentElement->next;
|
||||
@ -270,7 +270,7 @@ int32_t CollisionBody::resetIsAlreadyInIslandAndCountManifolds() {
|
||||
bool CollisionBody::testPointInside(const Vector3& worldPoint) const {
|
||||
|
||||
// For each collision shape of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Test if the point is inside the collision shape
|
||||
if (shape->testPointInside(worldPoint)) return true;
|
||||
@ -296,7 +296,7 @@ bool CollisionBody::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
||||
Ray rayTemp(ray);
|
||||
|
||||
// For each collision shape of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Test if the ray hits the collision shape
|
||||
if (shape->raycast(rayTemp, raycastInfo)) {
|
||||
@ -316,16 +316,16 @@ AABB CollisionBody::getAABB() const {
|
||||
|
||||
AABB bodyAABB;
|
||||
|
||||
if (mProxyCollisionShapes == NULL) return bodyAABB;
|
||||
if (m_proxyCollisionShapes == NULL) return bodyAABB;
|
||||
|
||||
mProxyCollisionShapes->getCollisionShape()->computeAABB(bodyAABB, mTransform * mProxyCollisionShapes->getLocalToBodyTransform());
|
||||
m_proxyCollisionShapes->getCollisionShape()->computeAABB(bodyAABB, m_transform * m_proxyCollisionShapes->getLocalToBodyTransform());
|
||||
|
||||
// For each proxy shape of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes->mNext; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes->m_next; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Compute the world-space AABB of the collision shape
|
||||
AABB aabb;
|
||||
shape->getCollisionShape()->computeAABB(aabb, mTransform * shape->getLocalToBodyTransform());
|
||||
shape->getCollisionShape()->computeAABB(aabb, m_transform * shape->getLocalToBodyTransform());
|
||||
|
||||
// Merge the proxy shape AABB with the current body AABB
|
||||
bodyAABB.mergeWithAABB(aabb);
|
||||
|
@ -47,22 +47,22 @@ class CollisionBody : public Body {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Type of body (static, kinematic or dynamic)
|
||||
BodyType mType;
|
||||
BodyType m_type;
|
||||
|
||||
/// Position and orientation of the body
|
||||
Transform mTransform;
|
||||
Transform m_transform;
|
||||
|
||||
/// First element of the linked list of proxy collision shapes of this body
|
||||
ProxyShape* mProxyCollisionShapes;
|
||||
ProxyShape* m_proxyCollisionShapes;
|
||||
|
||||
/// Number of collision shapes
|
||||
uint32_t mNbCollisionShapes;
|
||||
uint32_t m_numberCollisionShapes;
|
||||
|
||||
/// First element of the linked list of contact manifolds involving this body
|
||||
ContactManifoldListElement* mContactManifoldsList;
|
||||
ContactManifoldListElement* m_contactManifoldsList;
|
||||
|
||||
/// Reference to the world the body belongs to
|
||||
CollisionWorld& mWorld;
|
||||
CollisionWorld& m_world;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -168,7 +168,7 @@ class CollisionBody : public Body {
|
||||
* @return the type of the body (STATIC, KINEMATIC, DYNAMIC)
|
||||
*/
|
||||
inline BodyType CollisionBody::getType() const {
|
||||
return mType;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
// Set the type of the body
|
||||
@ -185,9 +185,9 @@ inline BodyType CollisionBody::getType() const {
|
||||
* @param type The type of the body (STATIC, KINEMATIC, DYNAMIC)
|
||||
*/
|
||||
inline void CollisionBody::setType(BodyType type) {
|
||||
mType = type;
|
||||
m_type = type;
|
||||
|
||||
if (mType == STATIC) {
|
||||
if (m_type == STATIC) {
|
||||
|
||||
// Update the broad-phase state of the body
|
||||
updateBroadPhaseState();
|
||||
@ -200,7 +200,7 @@ inline void CollisionBody::setType(BodyType type) {
|
||||
* of the body int32_to world-space
|
||||
*/
|
||||
inline const Transform& CollisionBody::getTransform() const {
|
||||
return mTransform;
|
||||
return m_transform;
|
||||
}
|
||||
|
||||
// Set the current position and orientation
|
||||
@ -211,7 +211,7 @@ inline const Transform& CollisionBody::getTransform() const {
|
||||
inline void CollisionBody::setTransform(const Transform& transform) {
|
||||
|
||||
// Update the transform of the body
|
||||
mTransform = transform;
|
||||
m_transform = transform;
|
||||
|
||||
// Update the broad-phase state of the body
|
||||
updateBroadPhaseState();
|
||||
@ -223,7 +223,7 @@ inline void CollisionBody::setTransform(const Transform& transform) {
|
||||
* manifolds of this body
|
||||
*/
|
||||
inline const ContactManifoldListElement* CollisionBody::getContactManifoldsList() const {
|
||||
return mContactManifoldsList;
|
||||
return m_contactManifoldsList;
|
||||
}
|
||||
|
||||
// Return the linked list of proxy shapes of that body
|
||||
@ -232,7 +232,7 @@ inline const ContactManifoldListElement* CollisionBody::getContactManifoldsList(
|
||||
* proxy shapes of the body
|
||||
*/
|
||||
inline ProxyShape* CollisionBody::getProxyShapesList() {
|
||||
return mProxyCollisionShapes;
|
||||
return m_proxyCollisionShapes;
|
||||
}
|
||||
|
||||
// Return the linked list of proxy shapes of that body
|
||||
@ -241,7 +241,7 @@ inline ProxyShape* CollisionBody::getProxyShapesList() {
|
||||
* proxy shapes of the body
|
||||
*/
|
||||
inline const ProxyShape* CollisionBody::getProxyShapesList() const {
|
||||
return mProxyCollisionShapes;
|
||||
return m_proxyCollisionShapes;
|
||||
}
|
||||
|
||||
// Return the world-space coordinates of a point given the local-space coordinates of the body
|
||||
@ -250,7 +250,7 @@ inline const ProxyShape* CollisionBody::getProxyShapesList() const {
|
||||
* @return The point in world-space coordinates
|
||||
*/
|
||||
inline Vector3 CollisionBody::getWorldPoint(const Vector3& localPoint) const {
|
||||
return mTransform * localPoint;
|
||||
return m_transform * localPoint;
|
||||
}
|
||||
|
||||
// Return the world-space vector of a vector given in local-space coordinates of the body
|
||||
@ -259,7 +259,7 @@ inline Vector3 CollisionBody::getWorldPoint(const Vector3& localPoint) const {
|
||||
* @return The vector in world-space coordinates
|
||||
*/
|
||||
inline Vector3 CollisionBody::getWorldVector(const Vector3& localVector) const {
|
||||
return mTransform.getOrientation() * localVector;
|
||||
return m_transform.getOrientation() * localVector;
|
||||
}
|
||||
|
||||
// Return the body local-space coordinates of a point given in the world-space coordinates
|
||||
@ -268,7 +268,7 @@ inline Vector3 CollisionBody::getWorldVector(const Vector3& localVector) const {
|
||||
* @return The point in the local-space coordinates of the body
|
||||
*/
|
||||
inline Vector3 CollisionBody::getLocalPoint(const Vector3& worldPoint) const {
|
||||
return mTransform.getInverse() * worldPoint;
|
||||
return m_transform.getInverse() * worldPoint;
|
||||
}
|
||||
|
||||
// Return the body local-space coordinates of a vector given in the world-space coordinates
|
||||
@ -277,7 +277,7 @@ inline Vector3 CollisionBody::getLocalPoint(const Vector3& worldPoint) const {
|
||||
* @return The vector in the local-space coordinates of the body
|
||||
*/
|
||||
inline Vector3 CollisionBody::getLocalVector(const Vector3& worldVector) const {
|
||||
return mTransform.getOrientation().getInverse() * worldVector;
|
||||
return m_transform.getOrientation().getInverse() * worldVector;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,16 +22,16 @@ using namespace reactphysics3d;
|
||||
RigidBody::RigidBody(const Transform& transform, CollisionWorld& world, bodyindex id)
|
||||
: CollisionBody(transform, world, id), mInitMass(float(1.0)),
|
||||
mCenterOfMassLocal(0, 0, 0), mCenterOfMassWorld(transform.getPosition()),
|
||||
mIsGravityEnabled(true), mLinearDamping(float(0.0)), mAngularDamping(float(0.0)),
|
||||
mJointsList(NULL) {
|
||||
m_isGravityEnabled(true), mLinearDamping(float(0.0)), mAngularDamping(float(0.0)),
|
||||
m_jointsList(NULL) {
|
||||
|
||||
// Compute the inverse mass
|
||||
mMassInverse = float(1.0) / mInitMass;
|
||||
m_massInverse = float(1.0) / mInitMass;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
RigidBody::~RigidBody() {
|
||||
assert(mJointsList == NULL);
|
||||
assert(m_jointsList == NULL);
|
||||
}
|
||||
|
||||
// Set the type of the body
|
||||
@ -49,7 +49,7 @@ RigidBody::~RigidBody() {
|
||||
*/
|
||||
void RigidBody::setType(BodyType type) {
|
||||
|
||||
if (mType == type) return;
|
||||
if (m_type == type) return;
|
||||
|
||||
CollisionBody::setType(type);
|
||||
|
||||
@ -57,7 +57,7 @@ void RigidBody::setType(BodyType type) {
|
||||
recomputeMassInformation();
|
||||
|
||||
// If it is a static body
|
||||
if (mType == STATIC) {
|
||||
if (m_type == STATIC) {
|
||||
|
||||
// Reset the velocity to zero
|
||||
mLinearVelocity.setToZero();
|
||||
@ -65,16 +65,16 @@ void RigidBody::setType(BodyType type) {
|
||||
}
|
||||
|
||||
// If it is a static or a kinematic body
|
||||
if (mType == STATIC || mType == KINEMATIC) {
|
||||
if (m_type == STATIC || m_type == KINEMATIC) {
|
||||
|
||||
// Reset the inverse mass and inverse inertia tensor to zero
|
||||
mMassInverse = float(0.0);
|
||||
m_massInverse = float(0.0);
|
||||
mInertiaTensorLocal.setToZero();
|
||||
mInertiaTensorLocalInverse.setToZero();
|
||||
|
||||
}
|
||||
else { // If it is a dynamic body
|
||||
mMassInverse = float(1.0) / mInitMass;
|
||||
m_massInverse = float(1.0) / mInitMass;
|
||||
mInertiaTensorLocalInverse = mInertiaTensorLocal.getInverse();
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ void RigidBody::setType(BodyType type) {
|
||||
*/
|
||||
void RigidBody::setInertiaTensorLocal(const Matrix3x3& inertiaTensorLocal) {
|
||||
|
||||
if (mType != DYNAMIC) return;
|
||||
if (m_type != DYNAMIC) return;
|
||||
|
||||
mInertiaTensorLocal = inertiaTensorLocal;
|
||||
|
||||
@ -115,13 +115,13 @@ void RigidBody::setInertiaTensorLocal(const Matrix3x3& inertiaTensorLocal) {
|
||||
*/
|
||||
void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) {
|
||||
|
||||
if (mType != DYNAMIC) return;
|
||||
if (m_type != DYNAMIC) return;
|
||||
|
||||
const Vector3 oldCenterOfMass = mCenterOfMassWorld;
|
||||
mCenterOfMassLocal = centerOfMassLocal;
|
||||
|
||||
// Compute the center of mass in world-space coordinates
|
||||
mCenterOfMassWorld = mTransform * mCenterOfMassLocal;
|
||||
mCenterOfMassWorld = m_transform * mCenterOfMassLocal;
|
||||
|
||||
// Update the linear velocity of the center of mass
|
||||
mLinearVelocity += mAngularVelocity.cross(mCenterOfMassWorld - oldCenterOfMass);
|
||||
@ -133,34 +133,34 @@ void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) {
|
||||
*/
|
||||
void RigidBody::setMass(float mass) {
|
||||
|
||||
if (mType != DYNAMIC) return;
|
||||
if (m_type != DYNAMIC) return;
|
||||
|
||||
mInitMass = mass;
|
||||
|
||||
if (mInitMass > float(0.0)) {
|
||||
mMassInverse = float(1.0) / mInitMass;
|
||||
m_massInverse = float(1.0) / mInitMass;
|
||||
}
|
||||
else {
|
||||
mInitMass = float(1.0);
|
||||
mMassInverse = float(1.0);
|
||||
m_massInverse = float(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove a joint from the joints list
|
||||
void RigidBody::removeJointFromJointsList(MemoryAllocator& memoryAllocator, const Joint* joint) {
|
||||
void RigidBody::removeJointFrom_jointsList(MemoryAllocator& memoryAllocator, const Joint* joint) {
|
||||
|
||||
assert(joint != NULL);
|
||||
assert(mJointsList != NULL);
|
||||
assert(m_jointsList != NULL);
|
||||
|
||||
// Remove the joint from the linked list of the joints of the first body
|
||||
if (mJointsList->joint == joint) { // If the first element is the one to remove
|
||||
JointListElement* elementToRemove = mJointsList;
|
||||
mJointsList = elementToRemove->next;
|
||||
if (m_jointsList->joint == joint) { // If the first element is the one to remove
|
||||
JointListElement* elementToRemove = m_jointsList;
|
||||
m_jointsList = elementToRemove->next;
|
||||
elementToRemove->~JointListElement();
|
||||
memoryAllocator.release(elementToRemove, sizeof(JointListElement));
|
||||
}
|
||||
else { // If the element to remove is not the first one in the list
|
||||
JointListElement* currentElement = mJointsList;
|
||||
JointListElement* currentElement = m_jointsList;
|
||||
while (currentElement->next != NULL) {
|
||||
if (currentElement->next->joint == joint) {
|
||||
JointListElement* elementToRemove = currentElement->next;
|
||||
@ -197,27 +197,27 @@ ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape,
|
||||
assert(mass > float(0.0));
|
||||
|
||||
// Create a new proxy collision shape to attach the collision shape to the body
|
||||
ProxyShape* proxyShape = new (mWorld.mMemoryAllocator.allocate(
|
||||
ProxyShape* proxyShape = new (m_world.m_memoryAllocator.allocate(
|
||||
sizeof(ProxyShape))) ProxyShape(this, collisionShape,
|
||||
transform, mass);
|
||||
|
||||
// Add it to the list of proxy collision shapes of the body
|
||||
if (mProxyCollisionShapes == NULL) {
|
||||
mProxyCollisionShapes = proxyShape;
|
||||
if (m_proxyCollisionShapes == NULL) {
|
||||
m_proxyCollisionShapes = proxyShape;
|
||||
}
|
||||
else {
|
||||
proxyShape->mNext = mProxyCollisionShapes;
|
||||
mProxyCollisionShapes = proxyShape;
|
||||
proxyShape->m_next = m_proxyCollisionShapes;
|
||||
m_proxyCollisionShapes = proxyShape;
|
||||
}
|
||||
|
||||
// Compute the world-space AABB of the new collision shape
|
||||
AABB aabb;
|
||||
collisionShape->computeAABB(aabb, mTransform * transform);
|
||||
collisionShape->computeAABB(aabb, m_transform * transform);
|
||||
|
||||
// Notify the collision detection about this new collision shape
|
||||
mWorld.m_collisionDetection.addProxyCollisionShape(proxyShape, aabb);
|
||||
m_world.m_collisionDetection.addProxyCollisionShape(proxyShape, aabb);
|
||||
|
||||
mNbCollisionShapes++;
|
||||
m_numberCollisionShapes++;
|
||||
|
||||
// Recompute the center of mass, total mass and inertia tensor of the body with the new
|
||||
// collision shape
|
||||
@ -250,7 +250,7 @@ void RigidBody::removeCollisionShape(const ProxyShape* proxyShape) {
|
||||
void RigidBody::setLinearVelocity(const Vector3& linearVelocity) {
|
||||
|
||||
// If it is a static body, we do nothing
|
||||
if (mType == STATIC) return;
|
||||
if (m_type == STATIC) return;
|
||||
|
||||
// Update the linear velocity of the current body state
|
||||
mLinearVelocity = linearVelocity;
|
||||
@ -268,7 +268,7 @@ void RigidBody::setLinearVelocity(const Vector3& linearVelocity) {
|
||||
void RigidBody::setAngularVelocity(const Vector3& angularVelocity) {
|
||||
|
||||
// If it is a static body, we do nothing
|
||||
if (mType == STATIC) return;
|
||||
if (m_type == STATIC) return;
|
||||
|
||||
// Set the angular velocity
|
||||
mAngularVelocity = angularVelocity;
|
||||
@ -287,12 +287,12 @@ void RigidBody::setAngularVelocity(const Vector3& angularVelocity) {
|
||||
void RigidBody::setTransform(const Transform& transform) {
|
||||
|
||||
// Update the transform of the body
|
||||
mTransform = transform;
|
||||
m_transform = transform;
|
||||
|
||||
const Vector3 oldCenterOfMass = mCenterOfMassWorld;
|
||||
|
||||
// Compute the new center of mass in world-space coordinates
|
||||
mCenterOfMassWorld = mTransform * mCenterOfMassLocal;
|
||||
mCenterOfMassWorld = m_transform * mCenterOfMassLocal;
|
||||
|
||||
// Update the linear velocity of the center of mass
|
||||
mLinearVelocity += mAngularVelocity.cross(mCenterOfMassWorld - oldCenterOfMass);
|
||||
@ -306,40 +306,40 @@ void RigidBody::setTransform(const Transform& transform) {
|
||||
void RigidBody::recomputeMassInformation() {
|
||||
|
||||
mInitMass = float(0.0);
|
||||
mMassInverse = float(0.0);
|
||||
m_massInverse = float(0.0);
|
||||
mInertiaTensorLocal.setToZero();
|
||||
mInertiaTensorLocalInverse.setToZero();
|
||||
mCenterOfMassLocal.setToZero();
|
||||
|
||||
// If it is STATIC or KINEMATIC body
|
||||
if (mType == STATIC || mType == KINEMATIC) {
|
||||
mCenterOfMassWorld = mTransform.getPosition();
|
||||
if (m_type == STATIC || m_type == KINEMATIC) {
|
||||
mCenterOfMassWorld = m_transform.getPosition();
|
||||
return;
|
||||
}
|
||||
|
||||
assert(mType == DYNAMIC);
|
||||
assert(m_type == DYNAMIC);
|
||||
|
||||
// Compute the total mass of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
mInitMass += shape->getMass();
|
||||
mCenterOfMassLocal += shape->getLocalToBodyTransform().getPosition() * shape->getMass();
|
||||
}
|
||||
|
||||
if (mInitMass > float(0.0)) {
|
||||
mMassInverse = float(1.0) / mInitMass;
|
||||
m_massInverse = float(1.0) / mInitMass;
|
||||
}
|
||||
else {
|
||||
mInitMass = float(1.0);
|
||||
mMassInverse = float(1.0);
|
||||
m_massInverse = float(1.0);
|
||||
}
|
||||
|
||||
// Compute the center of mass
|
||||
const Vector3 oldCenterOfMass = mCenterOfMassWorld;
|
||||
mCenterOfMassLocal *= mMassInverse;
|
||||
mCenterOfMassWorld = mTransform * mCenterOfMassLocal;
|
||||
mCenterOfMassLocal *= m_massInverse;
|
||||
mCenterOfMassWorld = m_transform * mCenterOfMassLocal;
|
||||
|
||||
// Compute the total mass and inertia tensor using all the collision shapes
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Get the inertia tensor of the collision shape in its local-space
|
||||
Matrix3x3 inertiaTensor;
|
||||
@ -378,18 +378,18 @@ void RigidBody::updateBroadPhaseState() const {
|
||||
|
||||
PROFILE("RigidBody::updateBroadPhaseState()");
|
||||
|
||||
DynamicsWorld& world = static_cast<DynamicsWorld&>(mWorld);
|
||||
const Vector3 displacement = world.mTimeStep * mLinearVelocity;
|
||||
DynamicsWorld& world = static_cast<DynamicsWorld&>(m_world);
|
||||
const Vector3 displacement = world.m_timeStep * mLinearVelocity;
|
||||
|
||||
// For all the proxy collision shapes of the body
|
||||
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
|
||||
for (ProxyShape* shape = m_proxyCollisionShapes; shape != NULL; shape = shape->m_next) {
|
||||
|
||||
// Recompute the world-space AABB of the collision shape
|
||||
AABB aabb;
|
||||
shape->getCollisionShape()->computeAABB(aabb, mTransform *shape->getLocalToBodyTransform());
|
||||
shape->getCollisionShape()->computeAABB(aabb, m_transform *shape->getLocalToBodyTransform());
|
||||
|
||||
// Update the broad-phase state for the proxy collision shape
|
||||
mWorld.m_collisionDetection.updateProxyCollisionShape(shape, aabb, displacement);
|
||||
m_world.m_collisionDetection.updateProxyCollisionShape(shape, aabb, displacement);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,10 +63,10 @@ class RigidBody : public CollisionBody {
|
||||
Matrix3x3 mInertiaTensorLocalInverse;
|
||||
|
||||
/// Inverse of the mass of the body
|
||||
float mMassInverse;
|
||||
float m_massInverse;
|
||||
|
||||
/// True if the gravity needs to be applied to this rigid body
|
||||
bool mIsGravityEnabled;
|
||||
bool m_isGravityEnabled;
|
||||
|
||||
/// Material properties of the rigid body
|
||||
Material mMaterial;
|
||||
@ -78,7 +78,7 @@ class RigidBody : public CollisionBody {
|
||||
float mAngularDamping;
|
||||
|
||||
/// First element of the linked list of joints involving this body
|
||||
JointListElement* mJointsList;
|
||||
JointListElement* m_jointsList;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -89,7 +89,7 @@ class RigidBody : public CollisionBody {
|
||||
RigidBody& operator=(const RigidBody& body);
|
||||
|
||||
/// Remove a joint from the joints list
|
||||
void removeJointFromJointsList(MemoryAllocator& memoryAllocator, const Joint* joint);
|
||||
void removeJointFrom_jointsList(MemoryAllocator& memoryAllocator, const Joint* joint);
|
||||
|
||||
/// Update the transform of the body after a change of the center of mass
|
||||
void updateTransformWithCenterOfMass();
|
||||
@ -254,8 +254,8 @@ inline const Matrix3x3& RigidBody::getInertiaTensorLocal() const {
|
||||
inline Matrix3x3 RigidBody::getInertiaTensorWorld() const {
|
||||
|
||||
// Compute and return the inertia tensor in world coordinates
|
||||
return mTransform.getOrientation().getMatrix() * mInertiaTensorLocal *
|
||||
mTransform.getOrientation().getMatrix().getTranspose();
|
||||
return m_transform.getOrientation().getMatrix() * mInertiaTensorLocal *
|
||||
m_transform.getOrientation().getMatrix().getTranspose();
|
||||
}
|
||||
|
||||
// Return the inverse of the inertia tensor in world coordinates.
|
||||
@ -274,8 +274,8 @@ inline Matrix3x3 RigidBody::getInertiaTensorInverseWorld() const {
|
||||
// INVERSE WORLD TENSOR IN THE CLASS AND UPLDATE IT WHEN THE ORIENTATION OF THE BODY CHANGES
|
||||
|
||||
// Compute and return the inertia tensor in world coordinates
|
||||
return mTransform.getOrientation().getMatrix() * mInertiaTensorLocalInverse *
|
||||
mTransform.getOrientation().getMatrix().getTranspose();
|
||||
return m_transform.getOrientation().getMatrix() * mInertiaTensorLocalInverse *
|
||||
m_transform.getOrientation().getMatrix().getTranspose();
|
||||
}
|
||||
|
||||
// Return true if the gravity needs to be applied to this rigid body
|
||||
@ -283,7 +283,7 @@ inline Matrix3x3 RigidBody::getInertiaTensorInverseWorld() const {
|
||||
* @return True if the gravity is applied to the body
|
||||
*/
|
||||
inline bool RigidBody::isGravityEnabled() const {
|
||||
return mIsGravityEnabled;
|
||||
return m_isGravityEnabled;
|
||||
}
|
||||
|
||||
// Set the variable to know if the gravity is applied to this rigid body
|
||||
@ -291,7 +291,7 @@ inline bool RigidBody::isGravityEnabled() const {
|
||||
* @param isEnabled True if you want the gravity to be applied to this body
|
||||
*/
|
||||
inline void RigidBody::enableGravity(bool isEnabled) {
|
||||
mIsGravityEnabled = isEnabled;
|
||||
m_isGravityEnabled = isEnabled;
|
||||
}
|
||||
|
||||
// Return a reference to the material properties of the rigid body
|
||||
@ -351,7 +351,7 @@ inline void RigidBody::setAngularDamping(float angularDamping) {
|
||||
* @return The first element of the linked-list of all the joints involving this body
|
||||
*/
|
||||
inline const JointListElement* RigidBody::getJointsList() const {
|
||||
return mJointsList;
|
||||
return m_jointsList;
|
||||
}
|
||||
|
||||
// Return the first element of the linked list of joints involving this body
|
||||
@ -359,7 +359,7 @@ inline const JointListElement* RigidBody::getJointsList() const {
|
||||
* @return The first element of the linked-list of all the joints involving this body
|
||||
*/
|
||||
inline JointListElement* RigidBody::getJointsList() {
|
||||
return mJointsList;
|
||||
return m_jointsList;
|
||||
}
|
||||
|
||||
// Set the variable to know whether or not the body is sleeping
|
||||
@ -386,7 +386,7 @@ inline void RigidBody::setIsSleeping(bool isSleeping) {
|
||||
inline void RigidBody::applyForceToCenterOfMass(const Vector3& force) {
|
||||
|
||||
// If it is not a dynamic body, we do nothing
|
||||
if (mType != DYNAMIC) return;
|
||||
if (m_type != DYNAMIC) return;
|
||||
|
||||
// Awake the body if it was sleeping
|
||||
if (m_isSleeping) {
|
||||
@ -411,7 +411,7 @@ inline void RigidBody::applyForceToCenterOfMass(const Vector3& force) {
|
||||
inline void RigidBody::applyForce(const Vector3& force, const Vector3& point) {
|
||||
|
||||
// If it is not a dynamic body, we do nothing
|
||||
if (mType != DYNAMIC) return;
|
||||
if (m_type != DYNAMIC) return;
|
||||
|
||||
// Awake the body if it was sleeping
|
||||
if (m_isSleeping) {
|
||||
@ -434,7 +434,7 @@ inline void RigidBody::applyForce(const Vector3& force, const Vector3& point) {
|
||||
inline void RigidBody::applyTorque(const Vector3& torque) {
|
||||
|
||||
// If it is not a dynamic body, we do nothing
|
||||
if (mType != DYNAMIC) return;
|
||||
if (m_type != DYNAMIC) return;
|
||||
|
||||
// Awake the body if it was sleeping
|
||||
if (m_isSleeping) {
|
||||
@ -449,7 +449,7 @@ inline void RigidBody::applyTorque(const Vector3& torque) {
|
||||
inline void RigidBody::updateTransformWithCenterOfMass() {
|
||||
|
||||
// Translate the body according to the translation of the center of mass position
|
||||
mTransform.setPosition(mCenterOfMassWorld - mTransform.getOrientation() * mCenterOfMassLocal);
|
||||
m_transform.setPosition(mCenterOfMassWorld - m_transform.getOrientation() * mCenterOfMassLocal);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ using namespace std;
|
||||
|
||||
// Constructor
|
||||
CollisionDetection::CollisionDetection(CollisionWorld* world, MemoryAllocator& memoryAllocator)
|
||||
: mMemoryAllocator(memoryAllocator),
|
||||
mWorld(world), mBroadPhaseAlgorithm(*this),
|
||||
mIsCollisionShapesAdded(false) {
|
||||
: m_memoryAllocator(memoryAllocator),
|
||||
m_world(world), m_broadPhaseAlgorithm(*this),
|
||||
m_isCollisionShapesAdded(false) {
|
||||
|
||||
// Set the default collision dispatch configuration
|
||||
setCollisionDispatch(&mDefaultCollisionDispatch);
|
||||
setCollisionDispatch(&m_defaultCollisionDispatch);
|
||||
|
||||
// Fill-in the collision detection matrix with algorithms
|
||||
fillInCollisionMatrix();
|
||||
@ -73,29 +73,29 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac
|
||||
|
||||
// For each possible collision pair of bodies
|
||||
map<overlappingpairid, OverlappingPair*>::iterator it;
|
||||
for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) {
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ++it) {
|
||||
|
||||
OverlappingPair* pair = it->second;
|
||||
|
||||
const ProxyShape* shape1 = pair->getShape1();
|
||||
const ProxyShape* shape2 = pair->getShape2();
|
||||
|
||||
assert(shape1->mBroadPhaseID != shape2->mBroadPhaseID);
|
||||
assert(shape1->m_broadPhaseID != shape2->m_broadPhaseID);
|
||||
|
||||
// If both shapes1 and shapes2 sets are non-empty, we check that
|
||||
// shape1 is among on set and shape2 is among the other one
|
||||
if (!shapes1.empty() && !shapes2.empty() &&
|
||||
(shapes1.count(shape1->mBroadPhaseID) == 0 || shapes2.count(shape2->mBroadPhaseID) == 0) &&
|
||||
(shapes1.count(shape2->mBroadPhaseID) == 0 || shapes2.count(shape1->mBroadPhaseID) == 0)) {
|
||||
(shapes1.count(shape1->m_broadPhaseID) == 0 || shapes2.count(shape2->m_broadPhaseID) == 0) &&
|
||||
(shapes1.count(shape2->m_broadPhaseID) == 0 || shapes2.count(shape1->m_broadPhaseID) == 0)) {
|
||||
continue;
|
||||
}
|
||||
if (!shapes1.empty() && shapes2.empty() &&
|
||||
shapes1.count(shape1->mBroadPhaseID) == 0 && shapes1.count(shape2->mBroadPhaseID) == 0)
|
||||
shapes1.count(shape1->m_broadPhaseID) == 0 && shapes1.count(shape2->m_broadPhaseID) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!shapes2.empty() && shapes1.empty() &&
|
||||
shapes2.count(shape1->mBroadPhaseID) == 0 && shapes2.count(shape2->mBroadPhaseID) == 0)
|
||||
shapes2.count(shape1->m_broadPhaseID) == 0 && shapes2.count(shape2->m_broadPhaseID) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -133,12 +133,12 @@ void CollisionDetection::computeBroadPhase() {
|
||||
PROFILE("CollisionDetection::computeBroadPhase()");
|
||||
|
||||
// If new collision shapes have been added to bodies
|
||||
if (mIsCollisionShapesAdded) {
|
||||
if (m_isCollisionShapesAdded) {
|
||||
|
||||
// Ask the broad-phase to recompute the overlapping pairs of collision
|
||||
// shapes. This call can only add new overlapping pairs in the collision
|
||||
// detection.
|
||||
mBroadPhaseAlgorithm.computeOverlappingPairs();
|
||||
m_broadPhaseAlgorithm.computeOverlappingPairs();
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,25 +148,25 @@ void CollisionDetection::computeNarrowPhase() {
|
||||
PROFILE("CollisionDetection::computeNarrowPhase()");
|
||||
|
||||
// Clear the set of overlapping pairs in narrow-phase contact
|
||||
mContactOverlappingPairs.clear();
|
||||
m_contactOverlappingPairs.clear();
|
||||
|
||||
// For each possible collision pair of bodies
|
||||
map<overlappingpairid, OverlappingPair*>::iterator it;
|
||||
for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ) {
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ) {
|
||||
|
||||
OverlappingPair* pair = it->second;
|
||||
|
||||
ProxyShape* shape1 = pair->getShape1();
|
||||
ProxyShape* shape2 = pair->getShape2();
|
||||
|
||||
assert(shape1->mBroadPhaseID != shape2->mBroadPhaseID);
|
||||
assert(shape1->m_broadPhaseID != shape2->m_broadPhaseID);
|
||||
|
||||
// Check if the collision filtering allows collision between the two shapes and
|
||||
// that the two shapes are still overlapping. Otherwise, we destroy the
|
||||
// overlapping pair
|
||||
if (((shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) == 0 ||
|
||||
(shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) == 0) ||
|
||||
!mBroadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
||||
!m_broadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
||||
|
||||
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
||||
++it;
|
||||
@ -175,8 +175,8 @@ void CollisionDetection::computeNarrowPhase() {
|
||||
|
||||
// Destroy the overlapping pair
|
||||
itToRemove->second->~OverlappingPair();
|
||||
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||
mOverlappingPairs.erase(itToRemove);
|
||||
m_world->m_memoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||
m_overlappingPairs.erase(itToRemove);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
@ -196,12 +196,12 @@ void CollisionDetection::computeNarrowPhase() {
|
||||
|
||||
// Check if the bodies are in the set of bodies that cannot collide between each other
|
||||
bodyindexpair bodiesIndex = OverlappingPair::computeBodiesIndexPair(body1, body2);
|
||||
if (mNoCollisionPairs.count(bodiesIndex) > 0) continue;
|
||||
if (m_noCollisionPairs.count(bodiesIndex) > 0) continue;
|
||||
|
||||
// Select the narrow phase algorithm to use according to the two collision shapes
|
||||
const CollisionShapeType shape1Type = shape1->getCollisionShape()->getType();
|
||||
const CollisionShapeType shape2Type = shape2->getCollisionShape()->getType();
|
||||
NarrowPhaseAlgorithm* narrowPhaseAlgorithm = mCollisionMatrix[shape1Type][shape2Type];
|
||||
NarrowPhaseAlgorithm* narrowPhaseAlgorithm = m_collisionMatrix[shape1Type][shape2Type];
|
||||
|
||||
// If there is no collision algorithm between those two kinds of shapes
|
||||
if (narrowPhaseAlgorithm == NULL) continue;
|
||||
@ -230,35 +230,35 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
const std::set<uint32_t>& shapes1,
|
||||
const std::set<uint32_t>& shapes2) {
|
||||
|
||||
mContactOverlappingPairs.clear();
|
||||
m_contactOverlappingPairs.clear();
|
||||
|
||||
// For each possible collision pair of bodies
|
||||
map<overlappingpairid, OverlappingPair*>::iterator it;
|
||||
for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ) {
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ) {
|
||||
|
||||
OverlappingPair* pair = it->second;
|
||||
|
||||
ProxyShape* shape1 = pair->getShape1();
|
||||
ProxyShape* shape2 = pair->getShape2();
|
||||
|
||||
assert(shape1->mBroadPhaseID != shape2->mBroadPhaseID);
|
||||
assert(shape1->m_broadPhaseID != shape2->m_broadPhaseID);
|
||||
|
||||
// If both shapes1 and shapes2 sets are non-empty, we check that
|
||||
// shape1 is among on set and shape2 is among the other one
|
||||
if (!shapes1.empty() && !shapes2.empty() &&
|
||||
(shapes1.count(shape1->mBroadPhaseID) == 0 || shapes2.count(shape2->mBroadPhaseID) == 0) &&
|
||||
(shapes1.count(shape2->mBroadPhaseID) == 0 || shapes2.count(shape1->mBroadPhaseID) == 0)) {
|
||||
(shapes1.count(shape1->m_broadPhaseID) == 0 || shapes2.count(shape2->m_broadPhaseID) == 0) &&
|
||||
(shapes1.count(shape2->m_broadPhaseID) == 0 || shapes2.count(shape1->m_broadPhaseID) == 0)) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
if (!shapes1.empty() && shapes2.empty() &&
|
||||
shapes1.count(shape1->mBroadPhaseID) == 0 && shapes1.count(shape2->mBroadPhaseID) == 0)
|
||||
shapes1.count(shape1->m_broadPhaseID) == 0 && shapes1.count(shape2->m_broadPhaseID) == 0)
|
||||
{
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
if (!shapes2.empty() && shapes1.empty() &&
|
||||
shapes2.count(shape1->mBroadPhaseID) == 0 && shapes2.count(shape2->mBroadPhaseID) == 0)
|
||||
shapes2.count(shape1->m_broadPhaseID) == 0 && shapes2.count(shape2->m_broadPhaseID) == 0)
|
||||
{
|
||||
++it;
|
||||
continue;
|
||||
@ -269,7 +269,7 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
// overlapping pair
|
||||
if (((shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) == 0 ||
|
||||
(shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) == 0) ||
|
||||
!mBroadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
||||
!m_broadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
||||
|
||||
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
||||
++it;
|
||||
@ -278,8 +278,8 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
|
||||
// Destroy the overlapping pair
|
||||
itToRemove->second->~OverlappingPair();
|
||||
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||
mOverlappingPairs.erase(itToRemove);
|
||||
m_world->m_memoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||
m_overlappingPairs.erase(itToRemove);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
@ -295,7 +295,7 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
// Check if the two bodies are allowed to collide, otherwise, we do not test for collision
|
||||
if (body1->getType() != DYNAMIC && body2->getType() != DYNAMIC) continue;
|
||||
bodyindexpair bodiesIndex = OverlappingPair::computeBodiesIndexPair(body1, body2);
|
||||
if (mNoCollisionPairs.count(bodiesIndex) > 0) continue;
|
||||
if (m_noCollisionPairs.count(bodiesIndex) > 0) continue;
|
||||
|
||||
// Check if the two bodies are sleeping, if so, we do no test collision between them
|
||||
if (body1->isSleeping() && body2->isSleeping()) continue;
|
||||
@ -303,7 +303,7 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
// Select the narrow phase algorithm to use according to the two collision shapes
|
||||
const CollisionShapeType shape1Type = shape1->getCollisionShape()->getType();
|
||||
const CollisionShapeType shape2Type = shape2->getCollisionShape()->getType();
|
||||
NarrowPhaseAlgorithm* narrowPhaseAlgorithm = mCollisionMatrix[shape1Type][shape2Type];
|
||||
NarrowPhaseAlgorithm* narrowPhaseAlgorithm = m_collisionMatrix[shape1Type][shape2Type];
|
||||
|
||||
// If there is no collision algorithm between those two kinds of shapes
|
||||
if (narrowPhaseAlgorithm == NULL) continue;
|
||||
@ -332,7 +332,7 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
/// This method is called by the broad-phase collision detection algorithm
|
||||
void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, ProxyShape* shape2) {
|
||||
|
||||
assert(shape1->mBroadPhaseID != shape2->mBroadPhaseID);
|
||||
assert(shape1->m_broadPhaseID != shape2->m_broadPhaseID);
|
||||
|
||||
// If the two proxy collision shapes are from the same body, skip it
|
||||
if (shape1->getBody()->getID() == shape2->getBody()->getID()) return;
|
||||
@ -345,21 +345,21 @@ void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, Pro
|
||||
overlappingpairid pairID = OverlappingPair::computeID(shape1, shape2);
|
||||
|
||||
// Check if the overlapping pair already exists
|
||||
if (mOverlappingPairs.find(pairID) != mOverlappingPairs.end()) return;
|
||||
if (m_overlappingPairs.find(pairID) != m_overlappingPairs.end()) return;
|
||||
|
||||
// Compute the maximum number of contact manifolds for this pair
|
||||
int32_t nbMaxManifolds = CollisionShape::computeNbMaxContactManifolds(shape1->getCollisionShape()->getType(),
|
||||
shape2->getCollisionShape()->getType());
|
||||
|
||||
// Create the overlapping pair and add it int32_to the set of overlapping pairs
|
||||
OverlappingPair* newPair = new (mWorld->mMemoryAllocator.allocate(sizeof(OverlappingPair)))
|
||||
OverlappingPair(shape1, shape2, nbMaxManifolds, mWorld->mMemoryAllocator);
|
||||
OverlappingPair* newPair = new (m_world->m_memoryAllocator.allocate(sizeof(OverlappingPair)))
|
||||
OverlappingPair(shape1, shape2, nbMaxManifolds, m_world->m_memoryAllocator);
|
||||
assert(newPair != NULL);
|
||||
|
||||
#ifndef NDEBUG
|
||||
std::pair<map<overlappingpairid, OverlappingPair*>::iterator, bool> check =
|
||||
#endif
|
||||
mOverlappingPairs.insert(make_pair(pairID, newPair));
|
||||
m_overlappingPairs.insert(make_pair(pairID, newPair));
|
||||
assert(check.second);
|
||||
|
||||
// Wake up the two bodies
|
||||
@ -372,9 +372,9 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
|
||||
// Remove all the overlapping pairs involving this proxy shape
|
||||
std::map<overlappingpairid, OverlappingPair*>::iterator it;
|
||||
for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ) {
|
||||
if (it->second->getShape1()->mBroadPhaseID == proxyShape->mBroadPhaseID||
|
||||
it->second->getShape2()->mBroadPhaseID == proxyShape->mBroadPhaseID) {
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ) {
|
||||
if (it->second->getShape1()->m_broadPhaseID == proxyShape->m_broadPhaseID||
|
||||
it->second->getShape2()->m_broadPhaseID == proxyShape->m_broadPhaseID) {
|
||||
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
||||
++it;
|
||||
|
||||
@ -382,8 +382,8 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
|
||||
// Destroy the overlapping pair
|
||||
itToRemove->second->~OverlappingPair();
|
||||
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||
mOverlappingPairs.erase(itToRemove);
|
||||
m_world->m_memoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||
m_overlappingPairs.erase(itToRemove);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
@ -391,7 +391,7 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
}
|
||||
|
||||
// Remove the body from the broad-phase
|
||||
mBroadPhaseAlgorithm.removeProxyCollisionShape(proxyShape);
|
||||
m_broadPhaseAlgorithm.removeProxyCollisionShape(proxyShape);
|
||||
}
|
||||
|
||||
// Called by a narrow-phase collision algorithm when a new contact has been found
|
||||
@ -401,14 +401,14 @@ void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, const C
|
||||
if (overlappingPair->getNbContactPoints() == 0) {
|
||||
|
||||
// Trigger a callback event
|
||||
if (mWorld->mEventListener != NULL) mWorld->mEventListener->beginContact(contactInfo);
|
||||
if (m_world->m_eventListener != NULL) m_world->m_eventListener->beginContact(contactInfo);
|
||||
}
|
||||
|
||||
// Create a new contact
|
||||
createContact(overlappingPair, contactInfo);
|
||||
|
||||
// Trigger a callback event for the new contact
|
||||
if (mWorld->mEventListener != NULL) mWorld->mEventListener->newContact(contactInfo);
|
||||
if (m_world->m_eventListener != NULL) m_world->m_eventListener->newContact(contactInfo);
|
||||
}
|
||||
|
||||
// Create a new contact
|
||||
@ -416,7 +416,7 @@ void CollisionDetection::createContact(OverlappingPair* overlappingPair,
|
||||
const ContactPointInfo& contactInfo) {
|
||||
|
||||
// Create a new contact
|
||||
ContactPoint* contact = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPoint)))
|
||||
ContactPoint* contact = new (m_world->m_memoryAllocator.allocate(sizeof(ContactPoint)))
|
||||
ContactPoint(contactInfo);
|
||||
|
||||
// Add the contact to the contact manifold set of the corresponding overlapping pair
|
||||
@ -425,14 +425,14 @@ void CollisionDetection::createContact(OverlappingPair* overlappingPair,
|
||||
// Add the overlapping pair int32_to the set of pairs in contact during narrow-phase
|
||||
overlappingpairid pairId = OverlappingPair::computeID(overlappingPair->getShape1(),
|
||||
overlappingPair->getShape2());
|
||||
mContactOverlappingPairs[pairId] = overlappingPair;
|
||||
m_contactOverlappingPairs[pairId] = overlappingPair;
|
||||
}
|
||||
|
||||
void CollisionDetection::addAllContactManifoldsToBodies() {
|
||||
|
||||
// For each overlapping pairs in contact during the narrow-phase
|
||||
std::map<overlappingpairid, OverlappingPair*>::iterator it;
|
||||
for (it = mContactOverlappingPairs.begin(); it != mContactOverlappingPairs.end(); ++it) {
|
||||
for (it = m_contactOverlappingPairs.begin(); it != m_contactOverlappingPairs.end(); ++it) {
|
||||
|
||||
// Add all the contact manifolds of the pair int32_to the list of contact manifolds
|
||||
// of the two bodies involved in the contact
|
||||
@ -459,19 +459,19 @@ void CollisionDetection::addContactManifoldToBody(OverlappingPair* pair) {
|
||||
|
||||
// Add the contact manifold at the beginning of the linked
|
||||
// list of contact manifolds of the first body
|
||||
void* allocatedMemory1 = mWorld->mMemoryAllocator.allocate(sizeof(ContactManifoldListElement));
|
||||
void* allocatedMemory1 = m_world->m_memoryAllocator.allocate(sizeof(ContactManifoldListElement));
|
||||
ContactManifoldListElement* listElement1 = new (allocatedMemory1)
|
||||
ContactManifoldListElement(contactManifold,
|
||||
body1->mContactManifoldsList);
|
||||
body1->mContactManifoldsList = listElement1;
|
||||
body1->m_contactManifoldsList);
|
||||
body1->m_contactManifoldsList = listElement1;
|
||||
|
||||
// Add the contact manifold at the beginning of the linked
|
||||
// list of the contact manifolds of the second body
|
||||
void* allocatedMemory2 = mWorld->mMemoryAllocator.allocate(sizeof(ContactManifoldListElement));
|
||||
void* allocatedMemory2 = m_world->m_memoryAllocator.allocate(sizeof(ContactManifoldListElement));
|
||||
ContactManifoldListElement* listElement2 = new (allocatedMemory2)
|
||||
ContactManifoldListElement(contactManifold,
|
||||
body2->mContactManifoldsList);
|
||||
body2->mContactManifoldsList = listElement2;
|
||||
body2->m_contactManifoldsList);
|
||||
body2->m_contactManifoldsList = listElement2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,7 +480,7 @@ void CollisionDetection::clearContactPoints() {
|
||||
|
||||
// For each overlapping pair
|
||||
std::map<overlappingpairid, OverlappingPair*>::iterator it;
|
||||
for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) {
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ++it) {
|
||||
it->second->clearContactPoints();
|
||||
}
|
||||
}
|
||||
@ -491,23 +491,23 @@ void CollisionDetection::fillInCollisionMatrix() {
|
||||
// For each possible type of collision shape
|
||||
for (int32_t i=0; i<NB_COLLISION_SHAPE_TYPES; i++) {
|
||||
for (int32_t j=0; j<NB_COLLISION_SHAPE_TYPES; j++) {
|
||||
mCollisionMatrix[i][j] = mCollisionDispatch->selectAlgorithm(i, j);
|
||||
m_collisionMatrix[i][j] = m_collisionDispatch->selectAlgorithm(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the world event listener
|
||||
EventListener* CollisionDetection::getWorldEventListener() {
|
||||
return mWorld->mEventListener;
|
||||
return m_world->m_eventListener;
|
||||
}
|
||||
|
||||
/// Return a reference to the world memory allocator
|
||||
MemoryAllocator& CollisionDetection::getWorldMemoryAllocator() {
|
||||
return mWorld->mMemoryAllocator;
|
||||
return m_world->m_memoryAllocator;
|
||||
}
|
||||
|
||||
// Called by a narrow-phase collision algorithm when a new contact has been found
|
||||
void TestCollisionBetweenShapesCallback::notifyContact(OverlappingPair* overlappingPair,
|
||||
const ContactPointInfo& contactInfo) {
|
||||
mCollisionCallback->notifyContact(contactInfo);
|
||||
m_collisionCallback->notifyContact(contactInfo);
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ class TestCollisionBetweenShapesCallback : public NarrowPhaseCallback {
|
||||
|
||||
private:
|
||||
|
||||
CollisionCallback* mCollisionCallback;
|
||||
CollisionCallback* m_collisionCallback;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
TestCollisionBetweenShapesCallback(CollisionCallback* callback)
|
||||
: mCollisionCallback(callback) {
|
||||
: m_collisionCallback(callback) {
|
||||
|
||||
}
|
||||
|
||||
@ -60,38 +60,38 @@ class CollisionDetection : public NarrowPhaseCallback {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Collision Detection Dispatch configuration
|
||||
CollisionDispatch* mCollisionDispatch;
|
||||
CollisionDispatch* m_collisionDispatch;
|
||||
|
||||
/// Default collision dispatch configuration
|
||||
DefaultCollisionDispatch mDefaultCollisionDispatch;
|
||||
DefaultCollisionDispatch m_defaultCollisionDispatch;
|
||||
|
||||
/// Collision detection matrix (algorithms to use)
|
||||
NarrowPhaseAlgorithm* mCollisionMatrix[NB_COLLISION_SHAPE_TYPES][NB_COLLISION_SHAPE_TYPES];
|
||||
NarrowPhaseAlgorithm* m_collisionMatrix[NB_COLLISION_SHAPE_TYPES][NB_COLLISION_SHAPE_TYPES];
|
||||
|
||||
/// Reference to the memory allocator
|
||||
MemoryAllocator& mMemoryAllocator;
|
||||
MemoryAllocator& m_memoryAllocator;
|
||||
|
||||
/// Pointer to the physics world
|
||||
CollisionWorld* mWorld;
|
||||
CollisionWorld* m_world;
|
||||
|
||||
/// Broad-phase overlapping pairs
|
||||
std::map<overlappingpairid, OverlappingPair*> mOverlappingPairs;
|
||||
std::map<overlappingpairid, OverlappingPair*> m_overlappingPairs;
|
||||
|
||||
/// Overlapping pairs in contact (during the current Narrow-phase collision detection)
|
||||
std::map<overlappingpairid, OverlappingPair*> mContactOverlappingPairs;
|
||||
std::map<overlappingpairid, OverlappingPair*> m_contactOverlappingPairs;
|
||||
|
||||
/// Broad-phase algorithm
|
||||
BroadPhaseAlgorithm mBroadPhaseAlgorithm;
|
||||
BroadPhaseAlgorithm m_broadPhaseAlgorithm;
|
||||
|
||||
/// Narrow-phase GJK algorithm
|
||||
// TODO : Delete this
|
||||
GJKAlgorithm mNarrowPhaseGJKAlgorithm;
|
||||
GJKAlgorithm m_narrowPhaseGJKAlgorithm;
|
||||
|
||||
/// Set of pair of bodies that cannot collide between each other
|
||||
std::set<bodyindexpair> mNoCollisionPairs;
|
||||
std::set<bodyindexpair> m_noCollisionPairs;
|
||||
|
||||
/// True if some collision shapes have been added previously
|
||||
bool mIsCollisionShapesAdded;
|
||||
bool m_isCollisionShapesAdded;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -213,14 +213,14 @@ class CollisionDetection : public NarrowPhaseCallback {
|
||||
// Return the Narrow-phase collision detection algorithm to use between two types of shapes
|
||||
inline NarrowPhaseAlgorithm* CollisionDetection::getCollisionAlgorithm(CollisionShapeType shape1Type,
|
||||
CollisionShapeType shape2Type) const {
|
||||
return mCollisionMatrix[shape1Type][shape2Type];
|
||||
return m_collisionMatrix[shape1Type][shape2Type];
|
||||
}
|
||||
|
||||
// Set the collision dispatch configuration
|
||||
inline void CollisionDetection::setCollisionDispatch(CollisionDispatch* collisionDispatch) {
|
||||
mCollisionDispatch = collisionDispatch;
|
||||
m_collisionDispatch = collisionDispatch;
|
||||
|
||||
mCollisionDispatch->init(this, &mMemoryAllocator);
|
||||
m_collisionDispatch->init(this, &m_memoryAllocator);
|
||||
|
||||
// Fill-in the collision matrix with the new algorithms to use
|
||||
fillInCollisionMatrix();
|
||||
@ -231,34 +231,34 @@ inline void CollisionDetection::addProxyCollisionShape(ProxyShape* proxyShape,
|
||||
const AABB& aabb) {
|
||||
|
||||
// Add the body to the broad-phase
|
||||
mBroadPhaseAlgorithm.addProxyCollisionShape(proxyShape, aabb);
|
||||
m_broadPhaseAlgorithm.addProxyCollisionShape(proxyShape, aabb);
|
||||
|
||||
mIsCollisionShapesAdded = true;
|
||||
m_isCollisionShapesAdded = true;
|
||||
}
|
||||
|
||||
// Add a pair of bodies that cannot collide with each other
|
||||
inline void CollisionDetection::addNoCollisionPair(CollisionBody* body1,
|
||||
CollisionBody* body2) {
|
||||
mNoCollisionPairs.insert(OverlappingPair::computeBodiesIndexPair(body1, body2));
|
||||
m_noCollisionPairs.insert(OverlappingPair::computeBodiesIndexPair(body1, body2));
|
||||
}
|
||||
|
||||
// Remove a pair of bodies that cannot collide with each other
|
||||
inline void CollisionDetection::removeNoCollisionPair(CollisionBody* body1,
|
||||
CollisionBody* body2) {
|
||||
mNoCollisionPairs.erase(OverlappingPair::computeBodiesIndexPair(body1, body2));
|
||||
m_noCollisionPairs.erase(OverlappingPair::computeBodiesIndexPair(body1, body2));
|
||||
}
|
||||
|
||||
// Ask for a collision shape to be tested again during broad-phase.
|
||||
/// We simply put the shape in the list of collision shape that have moved in the
|
||||
/// previous frame so that it is tested for collision again in the broad-phase.
|
||||
inline void CollisionDetection::askForBroadPhaseCollisionCheck(ProxyShape* shape) {
|
||||
mBroadPhaseAlgorithm.addMovedCollisionShape(shape->mBroadPhaseID);
|
||||
m_broadPhaseAlgorithm.addMovedCollisionShape(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
// Update a proxy collision shape (that has moved for instance)
|
||||
inline void CollisionDetection::updateProxyCollisionShape(ProxyShape* shape, const AABB& aabb,
|
||||
const Vector3& displacement, bool forceReinsert) {
|
||||
mBroadPhaseAlgorithm.updateProxyCollisionShape(shape, aabb, displacement);
|
||||
m_broadPhaseAlgorithm.updateProxyCollisionShape(shape, aabb, displacement);
|
||||
}
|
||||
|
||||
// Ray casting method
|
||||
@ -272,7 +272,7 @@ inline void CollisionDetection::raycast(RaycastCallback* raycastCallback,
|
||||
|
||||
// Ask the broad-phase algorithm to call the testRaycastAgainstShape()
|
||||
// callback method for each proxy shape hit by the ray in the broad-phase
|
||||
mBroadPhaseAlgorithm.raycast(ray, rayCastTest, raycastWithCategoryMaskBits);
|
||||
m_broadPhaseAlgorithm.raycast(ray, rayCastTest, raycastWithCategoryMaskBits);
|
||||
}
|
||||
|
||||
// Test if the AABBs of two proxy shapes overlap
|
||||
@ -284,12 +284,12 @@ inline bool CollisionDetection::testAABBOverlap(const ProxyShape* shape1,
|
||||
return false;
|
||||
}
|
||||
|
||||
return mBroadPhaseAlgorithm.testOverlappingShapes(shape1, shape2);
|
||||
return m_broadPhaseAlgorithm.testOverlappingShapes(shape1, shape2);
|
||||
}
|
||||
|
||||
// Return a pointer to the world
|
||||
inline CollisionWorld* CollisionDetection::getWorld() {
|
||||
return mWorld;
|
||||
return m_world;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ using namespace reactphysics3d;
|
||||
// Constructor
|
||||
ContactManifold::ContactManifold(ProxyShape* shape1, ProxyShape* shape2,
|
||||
MemoryAllocator& memoryAllocator, short normalDirectionId)
|
||||
: mShape1(shape1), mShape2(shape2), mNormalDirectionId(normalDirectionId),
|
||||
mNbContactPoints(0), mFrictionImpulse1(0.0), mFrictionImpulse2(0.0),
|
||||
mFrictionTwistImpulse(0.0), m_isAlreadyInIsland(false),
|
||||
mMemoryAllocator(memoryAllocator) {
|
||||
: m_shape1(shape1), m_shape2(shape2), m_normalDirectionId(normalDirectionId),
|
||||
m_nbContactPoints(0), m_frictionImpulse1(0.0), m_frictionImpulse2(0.0),
|
||||
m_frictionTwistImpulse(0.0), m_isAlreadyInIsland(false),
|
||||
m_memoryAllocator(memoryAllocator) {
|
||||
|
||||
}
|
||||
|
||||
@ -30,54 +30,54 @@ ContactManifold::~ContactManifold() {
|
||||
void ContactManifold::addContactPoint(ContactPoint* contact) {
|
||||
|
||||
// For contact already in the manifold
|
||||
for (uint32_t i=0; i<mNbContactPoints; i++) {
|
||||
for (uint32_t i=0; i<m_nbContactPoints; i++) {
|
||||
|
||||
// Check if the new point point does not correspond to a same contact point
|
||||
// already in the manifold.
|
||||
float distance = (mContactPoints[i]->getWorldPointOnBody1() -
|
||||
float distance = (m_contactPoints[i]->getWorldPointOnBody1() -
|
||||
contact->getWorldPointOnBody1()).lengthSquare();
|
||||
if (distance <= PERSISTENT_CONTACT_DIST_THRESHOLD*PERSISTENT_CONTACT_DIST_THRESHOLD) {
|
||||
|
||||
// Delete the new contact
|
||||
contact->~ContactPoint();
|
||||
mMemoryAllocator.release(contact, sizeof(ContactPoint));
|
||||
m_memoryAllocator.release(contact, sizeof(ContactPoint));
|
||||
|
||||
assert(mNbContactPoints > 0);
|
||||
assert(m_nbContactPoints > 0);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If the contact manifold is full
|
||||
if (mNbContactPoints == MAX_CONTACT_POINTS_IN_MANIFOLD) {
|
||||
if (m_nbContactPoints == MAX_CONTACT_POINTS_IN_MANIFOLD) {
|
||||
int32_t indexMaxPenetration = getIndexOfDeepestPenetration(contact);
|
||||
int32_t indexToRemove = getIndexToRemove(indexMaxPenetration, contact->getLocalPointOnBody1());
|
||||
removeContactPoint(indexToRemove);
|
||||
}
|
||||
|
||||
// Add the new contact point in the manifold
|
||||
mContactPoints[mNbContactPoints] = contact;
|
||||
mNbContactPoints++;
|
||||
m_contactPoints[m_nbContactPoints] = contact;
|
||||
m_nbContactPoints++;
|
||||
|
||||
assert(mNbContactPoints > 0);
|
||||
assert(m_nbContactPoints > 0);
|
||||
}
|
||||
|
||||
// Remove a contact point from the manifold
|
||||
void ContactManifold::removeContactPoint(uint32_t index) {
|
||||
assert(index < mNbContactPoints);
|
||||
assert(mNbContactPoints > 0);
|
||||
assert(index < m_nbContactPoints);
|
||||
assert(m_nbContactPoints > 0);
|
||||
|
||||
// Call the destructor explicitly and tell the memory allocator that
|
||||
// the corresponding memory block is now free
|
||||
mContactPoints[index]->~ContactPoint();
|
||||
mMemoryAllocator.release(mContactPoints[index], sizeof(ContactPoint));
|
||||
m_contactPoints[index]->~ContactPoint();
|
||||
m_memoryAllocator.release(m_contactPoints[index], sizeof(ContactPoint));
|
||||
|
||||
// If we don't remove the last index
|
||||
if (index < mNbContactPoints - 1) {
|
||||
mContactPoints[index] = mContactPoints[mNbContactPoints - 1];
|
||||
if (index < m_nbContactPoints - 1) {
|
||||
m_contactPoints[index] = m_contactPoints[m_nbContactPoints - 1];
|
||||
}
|
||||
|
||||
mNbContactPoints--;
|
||||
m_nbContactPoints--;
|
||||
}
|
||||
|
||||
// Update the contact manifold
|
||||
@ -88,27 +88,27 @@ void ContactManifold::removeContactPoint(uint32_t index) {
|
||||
/// contact normal.
|
||||
void ContactManifold::update(const Transform& transform1, const Transform& transform2) {
|
||||
|
||||
if (mNbContactPoints == 0) return;
|
||||
if (m_nbContactPoints == 0) return;
|
||||
|
||||
// Update the world coordinates and penetration depth of the contact points in the manifold
|
||||
for (uint32_t i=0; i<mNbContactPoints; i++) {
|
||||
mContactPoints[i]->setWorldPointOnBody1(transform1 *
|
||||
mContactPoints[i]->getLocalPointOnBody1());
|
||||
mContactPoints[i]->setWorldPointOnBody2(transform2 *
|
||||
mContactPoints[i]->getLocalPointOnBody2());
|
||||
mContactPoints[i]->setPenetrationDepth((mContactPoints[i]->getWorldPointOnBody1() -
|
||||
mContactPoints[i]->getWorldPointOnBody2()).dot(mContactPoints[i]->getNormal()));
|
||||
for (uint32_t i=0; i<m_nbContactPoints; i++) {
|
||||
m_contactPoints[i]->setWorldPointOnBody1(transform1 *
|
||||
m_contactPoints[i]->getLocalPointOnBody1());
|
||||
m_contactPoints[i]->setWorldPointOnBody2(transform2 *
|
||||
m_contactPoints[i]->getLocalPointOnBody2());
|
||||
m_contactPoints[i]->setPenetrationDepth((m_contactPoints[i]->getWorldPointOnBody1() -
|
||||
m_contactPoints[i]->getWorldPointOnBody2()).dot(m_contactPoints[i]->getNormal()));
|
||||
}
|
||||
|
||||
const float squarePersistentContactThreshold = PERSISTENT_CONTACT_DIST_THRESHOLD *
|
||||
PERSISTENT_CONTACT_DIST_THRESHOLD;
|
||||
|
||||
// Remove the contact points that don't represent very well the contact manifold
|
||||
for (int32_t i=static_cast<int32_t>(mNbContactPoints)-1; i>=0; i--) {
|
||||
assert(i < static_cast<int32_t>(mNbContactPoints));
|
||||
for (int32_t i=static_cast<int32_t>(m_nbContactPoints)-1; i>=0; i--) {
|
||||
assert(i < static_cast<int32_t>(m_nbContactPoints));
|
||||
|
||||
// Compute the distance between contact points in the normal direction
|
||||
float distanceNormal = -mContactPoints[i]->getPenetrationDepth();
|
||||
float distanceNormal = -m_contactPoints[i]->getPenetrationDepth();
|
||||
|
||||
// If the contacts points are too far from each other in the normal direction
|
||||
if (distanceNormal > squarePersistentContactThreshold) {
|
||||
@ -117,9 +117,9 @@ void ContactManifold::update(const Transform& transform1, const Transform& trans
|
||||
else {
|
||||
// Compute the distance of the two contact points in the plane
|
||||
// orthogonal to the contact normal
|
||||
Vector3 projOfPoint1 = mContactPoints[i]->getWorldPointOnBody1() +
|
||||
mContactPoints[i]->getNormal() * distanceNormal;
|
||||
Vector3 projDifference = mContactPoints[i]->getWorldPointOnBody2() - projOfPoint1;
|
||||
Vector3 projOfPoint1 = m_contactPoints[i]->getWorldPointOnBody1() +
|
||||
m_contactPoints[i]->getNormal() * distanceNormal;
|
||||
Vector3 projDifference = m_contactPoints[i]->getWorldPointOnBody2() - projOfPoint1;
|
||||
|
||||
// If the orthogonal distance is larger than the valid distance
|
||||
// threshold, we remove the contact
|
||||
@ -134,16 +134,16 @@ void ContactManifold::update(const Transform& transform1, const Transform& trans
|
||||
/// This corresponding contact will be kept in the cache. The method returns -1 is
|
||||
/// the new contact is the deepest.
|
||||
int32_t ContactManifold::getIndexOfDeepestPenetration(ContactPoint* newContact) const {
|
||||
assert(mNbContactPoints == MAX_CONTACT_POINTS_IN_MANIFOLD);
|
||||
assert(m_nbContactPoints == MAX_CONTACT_POINTS_IN_MANIFOLD);
|
||||
int32_t indexMaxPenetrationDepth = -1;
|
||||
float maxPenetrationDepth = newContact->getPenetrationDepth();
|
||||
|
||||
// For each contact in the cache
|
||||
for (uint32_t i=0; i<mNbContactPoints; i++) {
|
||||
for (uint32_t i=0; i<m_nbContactPoints; i++) {
|
||||
|
||||
// If the current contact has a larger penetration depth
|
||||
if (mContactPoints[i]->getPenetrationDepth() > maxPenetrationDepth) {
|
||||
maxPenetrationDepth = mContactPoints[i]->getPenetrationDepth();
|
||||
if (m_contactPoints[i]->getPenetrationDepth() > maxPenetrationDepth) {
|
||||
maxPenetrationDepth = m_contactPoints[i]->getPenetrationDepth();
|
||||
indexMaxPenetrationDepth = i;
|
||||
}
|
||||
}
|
||||
@ -164,7 +164,7 @@ int32_t ContactManifold::getIndexOfDeepestPenetration(ContactPoint* newContact)
|
||||
/// by Erwin Coumans (http://wwww.bulletphysics.org).
|
||||
int32_t ContactManifold::getIndexToRemove(int32_t indexMaxPenetration, const Vector3& newPoint) const {
|
||||
|
||||
assert(mNbContactPoints == MAX_CONTACT_POINTS_IN_MANIFOLD);
|
||||
assert(m_nbContactPoints == MAX_CONTACT_POINTS_IN_MANIFOLD);
|
||||
|
||||
float area0 = 0.0; // Area with contact 1,2,3 and newPoint
|
||||
float area1 = 0.0; // Area with contact 0,2,3 and newPoint
|
||||
@ -173,33 +173,33 @@ int32_t ContactManifold::getIndexToRemove(int32_t indexMaxPenetration, const Vec
|
||||
|
||||
if (indexMaxPenetration != 0) {
|
||||
// Compute the area
|
||||
Vector3 vector1 = newPoint - mContactPoints[1]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = mContactPoints[3]->getLocalPointOnBody1() -
|
||||
mContactPoints[2]->getLocalPointOnBody1();
|
||||
Vector3 vector1 = newPoint - m_contactPoints[1]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = m_contactPoints[3]->getLocalPointOnBody1() -
|
||||
m_contactPoints[2]->getLocalPointOnBody1();
|
||||
Vector3 crossProduct = vector1.cross(vector2);
|
||||
area0 = crossProduct.lengthSquare();
|
||||
}
|
||||
if (indexMaxPenetration != 1) {
|
||||
// Compute the area
|
||||
Vector3 vector1 = newPoint - mContactPoints[0]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = mContactPoints[3]->getLocalPointOnBody1() -
|
||||
mContactPoints[2]->getLocalPointOnBody1();
|
||||
Vector3 vector1 = newPoint - m_contactPoints[0]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = m_contactPoints[3]->getLocalPointOnBody1() -
|
||||
m_contactPoints[2]->getLocalPointOnBody1();
|
||||
Vector3 crossProduct = vector1.cross(vector2);
|
||||
area1 = crossProduct.lengthSquare();
|
||||
}
|
||||
if (indexMaxPenetration != 2) {
|
||||
// Compute the area
|
||||
Vector3 vector1 = newPoint - mContactPoints[0]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = mContactPoints[3]->getLocalPointOnBody1() -
|
||||
mContactPoints[1]->getLocalPointOnBody1();
|
||||
Vector3 vector1 = newPoint - m_contactPoints[0]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = m_contactPoints[3]->getLocalPointOnBody1() -
|
||||
m_contactPoints[1]->getLocalPointOnBody1();
|
||||
Vector3 crossProduct = vector1.cross(vector2);
|
||||
area2 = crossProduct.lengthSquare();
|
||||
}
|
||||
if (indexMaxPenetration != 3) {
|
||||
// Compute the area
|
||||
Vector3 vector1 = newPoint - mContactPoints[0]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = mContactPoints[2]->getLocalPointOnBody1() -
|
||||
mContactPoints[1]->getLocalPointOnBody1();
|
||||
Vector3 vector1 = newPoint - m_contactPoints[0]->getLocalPointOnBody1();
|
||||
Vector3 vector2 = m_contactPoints[2]->getLocalPointOnBody1() -
|
||||
m_contactPoints[1]->getLocalPointOnBody1();
|
||||
Vector3 crossProduct = vector1.cross(vector2);
|
||||
area3 = crossProduct.lengthSquare();
|
||||
}
|
||||
@ -234,12 +234,12 @@ int32_t ContactManifold::getMaxArea(float area0, float area1, float area2, float
|
||||
|
||||
// Clear the contact manifold
|
||||
void ContactManifold::clear() {
|
||||
for (uint32_t i=0; i<mNbContactPoints; i++) {
|
||||
for (uint32_t i=0; i<m_nbContactPoints; i++) {
|
||||
|
||||
// Call the destructor explicitly and tell the memory allocator that
|
||||
// the corresponding memory block is now free
|
||||
mContactPoints[i]->~ContactPoint();
|
||||
mMemoryAllocator.release(mContactPoints[i], sizeof(ContactPoint));
|
||||
m_contactPoints[i]->~ContactPoint();
|
||||
m_memoryAllocator.release(m_contactPoints[i], sizeof(ContactPoint));
|
||||
}
|
||||
mNbContactPoints = 0;
|
||||
m_nbContactPoints = 0;
|
||||
}
|
||||
|
@ -69,43 +69,43 @@ class ContactManifold {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Pointer to the first proxy shape of the contact
|
||||
ProxyShape* mShape1;
|
||||
ProxyShape* m_shape1;
|
||||
|
||||
/// Pointer to the second proxy shape of the contact
|
||||
ProxyShape* mShape2;
|
||||
ProxyShape* m_shape2;
|
||||
|
||||
/// Contact points in the manifold
|
||||
ContactPoint* mContactPoints[MAX_CONTACT_POINTS_IN_MANIFOLD];
|
||||
ContactPoint* m_contactPoints[MAX_CONTACT_POINTS_IN_MANIFOLD];
|
||||
|
||||
/// Normal direction Id (Unique Id representing the normal direction)
|
||||
int16_t mNormalDirectionId;
|
||||
int16_t m_normalDirectionId;
|
||||
|
||||
/// Number of contacts in the cache
|
||||
uint32_t mNbContactPoints;
|
||||
uint32_t m_nbContactPoints;
|
||||
|
||||
/// First friction vector of the contact manifold
|
||||
Vector3 mFrictionVector1;
|
||||
Vector3 m_frictionVector1;
|
||||
|
||||
/// Second friction vector of the contact manifold
|
||||
Vector3 mFrictionVector2;
|
||||
Vector3 m_frictionVector2;
|
||||
|
||||
/// First friction constraint accumulated impulse
|
||||
float mFrictionImpulse1;
|
||||
float m_frictionImpulse1;
|
||||
|
||||
/// Second friction constraint accumulated impulse
|
||||
float mFrictionImpulse2;
|
||||
float m_frictionImpulse2;
|
||||
|
||||
/// Twist friction constraint accumulated impulse
|
||||
float mFrictionTwistImpulse;
|
||||
float m_frictionTwistImpulse;
|
||||
|
||||
/// Accumulated rolling resistance impulse
|
||||
Vector3 mRollingResistanceImpulse;
|
||||
Vector3 m_rollingResistanceImpulse;
|
||||
|
||||
/// True if the contact manifold has already been added int32_to an island
|
||||
bool m_isAlreadyInIsland;
|
||||
|
||||
/// Reference to the memory allocator
|
||||
MemoryAllocator& mMemoryAllocator;
|
||||
MemoryAllocator& m_memoryAllocator;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -172,13 +172,13 @@ class ContactManifold {
|
||||
const Vector3& getFrictionVector1() const;
|
||||
|
||||
/// set the first friction vector at the center of the contact manifold
|
||||
void setFrictionVector1(const Vector3& mFrictionVector1);
|
||||
void setFrictionVector1(const Vector3& m_frictionVector1);
|
||||
|
||||
/// Return the second friction vector at the center of the contact manifold
|
||||
const Vector3& getFrictionVector2() const;
|
||||
|
||||
/// set the second friction vector at the center of the contact manifold
|
||||
void setFrictionVector2(const Vector3& mFrictionVector2);
|
||||
void setFrictionVector2(const Vector3& m_frictionVector2);
|
||||
|
||||
/// Return the first friction accumulated impulse
|
||||
float getFrictionImpulse1() const;
|
||||
@ -219,93 +219,93 @@ class ContactManifold {
|
||||
|
||||
// Return a pointer to the first proxy shape of the contact
|
||||
inline ProxyShape* ContactManifold::getShape1() const {
|
||||
return mShape1;
|
||||
return m_shape1;
|
||||
}
|
||||
|
||||
// Return a pointer to the second proxy shape of the contact
|
||||
inline ProxyShape* ContactManifold::getShape2() const {
|
||||
return mShape2;
|
||||
return m_shape2;
|
||||
}
|
||||
|
||||
// Return a pointer to the first body of the contact manifold
|
||||
inline CollisionBody* ContactManifold::getBody1() const {
|
||||
return mShape1->getBody();
|
||||
return m_shape1->getBody();
|
||||
}
|
||||
|
||||
// Return a pointer to the second body of the contact manifold
|
||||
inline CollisionBody* ContactManifold::getBody2() const {
|
||||
return mShape2->getBody();
|
||||
return m_shape2->getBody();
|
||||
}
|
||||
|
||||
// Return the normal direction Id
|
||||
inline int16_t ContactManifold::getNormalDirectionId() const {
|
||||
return mNormalDirectionId;
|
||||
return m_normalDirectionId;
|
||||
}
|
||||
|
||||
// Return the number of contact points in the manifold
|
||||
inline uint32_t ContactManifold::getNbContactPoints() const {
|
||||
return mNbContactPoints;
|
||||
return m_nbContactPoints;
|
||||
}
|
||||
|
||||
// Return the first friction vector at the center of the contact manifold
|
||||
inline const Vector3& ContactManifold::getFrictionVector1() const {
|
||||
return mFrictionVector1;
|
||||
return m_frictionVector1;
|
||||
}
|
||||
|
||||
// set the first friction vector at the center of the contact manifold
|
||||
inline void ContactManifold::setFrictionVector1(const Vector3& frictionVector1) {
|
||||
mFrictionVector1 = frictionVector1;
|
||||
m_frictionVector1 = frictionVector1;
|
||||
}
|
||||
|
||||
// Return the second friction vector at the center of the contact manifold
|
||||
inline const Vector3& ContactManifold::getFrictionVector2() const {
|
||||
return mFrictionVector2;
|
||||
return m_frictionVector2;
|
||||
}
|
||||
|
||||
// set the second friction vector at the center of the contact manifold
|
||||
inline void ContactManifold::setFrictionVector2(const Vector3& frictionVector2) {
|
||||
mFrictionVector2 = frictionVector2;
|
||||
m_frictionVector2 = frictionVector2;
|
||||
}
|
||||
|
||||
// Return the first friction accumulated impulse
|
||||
inline float ContactManifold::getFrictionImpulse1() const {
|
||||
return mFrictionImpulse1;
|
||||
return m_frictionImpulse1;
|
||||
}
|
||||
|
||||
// Set the first friction accumulated impulse
|
||||
inline void ContactManifold::setFrictionImpulse1(float frictionImpulse1) {
|
||||
mFrictionImpulse1 = frictionImpulse1;
|
||||
m_frictionImpulse1 = frictionImpulse1;
|
||||
}
|
||||
|
||||
// Return the second friction accumulated impulse
|
||||
inline float ContactManifold::getFrictionImpulse2() const {
|
||||
return mFrictionImpulse2;
|
||||
return m_frictionImpulse2;
|
||||
}
|
||||
|
||||
// Set the second friction accumulated impulse
|
||||
inline void ContactManifold::setFrictionImpulse2(float frictionImpulse2) {
|
||||
mFrictionImpulse2 = frictionImpulse2;
|
||||
m_frictionImpulse2 = frictionImpulse2;
|
||||
}
|
||||
|
||||
// Return the friction twist accumulated impulse
|
||||
inline float ContactManifold::getFrictionTwistImpulse() const {
|
||||
return mFrictionTwistImpulse;
|
||||
return m_frictionTwistImpulse;
|
||||
}
|
||||
|
||||
// Set the friction twist accumulated impulse
|
||||
inline void ContactManifold::setFrictionTwistImpulse(float frictionTwistImpulse) {
|
||||
mFrictionTwistImpulse = frictionTwistImpulse;
|
||||
m_frictionTwistImpulse = frictionTwistImpulse;
|
||||
}
|
||||
|
||||
// Set the accumulated rolling resistance impulse
|
||||
inline void ContactManifold::setRollingResistanceImpulse(const Vector3& rollingResistanceImpulse) {
|
||||
mRollingResistanceImpulse = rollingResistanceImpulse;
|
||||
m_rollingResistanceImpulse = rollingResistanceImpulse;
|
||||
}
|
||||
|
||||
// Return a contact point of the manifold
|
||||
inline ContactPoint* ContactManifold::getContactPoint(uint32_t index) const {
|
||||
assert(index < mNbContactPoints);
|
||||
return mContactPoints[index];
|
||||
assert(index < m_nbContactPoints);
|
||||
return m_contactPoints[index];
|
||||
}
|
||||
|
||||
// Return true if the contact manifold has already been added int32_to an island
|
||||
@ -317,8 +317,8 @@ inline bool ContactManifold::isAlreadyInIsland() const {
|
||||
inline Vector3 ContactManifold::getAverageContactNormal() const {
|
||||
Vector3 averageNormal;
|
||||
|
||||
for (uint32_t i=0; i<mNbContactPoints; i++) {
|
||||
averageNormal += mContactPoints[i]->getNormal();
|
||||
for (uint32_t i=0; i<m_nbContactPoints; i++) {
|
||||
averageNormal += m_contactPoints[i]->getNormal();
|
||||
}
|
||||
|
||||
return averageNormal.getUnit();
|
||||
@ -328,8 +328,8 @@ inline Vector3 ContactManifold::getAverageContactNormal() const {
|
||||
inline float ContactManifold::getLargestContactDepth() const {
|
||||
float largestDepth = 0.0f;
|
||||
|
||||
for (uint32_t i=0; i<mNbContactPoints; i++) {
|
||||
float depth = mContactPoints[i]->getPenetrationDepth();
|
||||
for (uint32_t i=0; i<m_nbContactPoints; i++) {
|
||||
float depth = m_contactPoints[i]->getPenetrationDepth();
|
||||
if (depth > largestDepth) {
|
||||
largestDepth = depth;
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ using namespace reactphysics3d;
|
||||
// Constructor
|
||||
ContactManifoldSet::ContactManifoldSet(ProxyShape* shape1, ProxyShape* shape2,
|
||||
MemoryAllocator& memoryAllocator, int32_t nbMaxManifolds)
|
||||
: mNbMaxManifolds(nbMaxManifolds), mNbManifolds(0), mShape1(shape1),
|
||||
mShape2(shape2), mMemoryAllocator(memoryAllocator) {
|
||||
: m_nbMaxManifolds(nbMaxManifolds), m_nbManifolds(0), m_shape1(shape1),
|
||||
m_shape2(shape2), m_memoryAllocator(memoryAllocator) {
|
||||
assert(nbMaxManifolds >= 1);
|
||||
}
|
||||
|
||||
@ -31,13 +31,13 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) {
|
||||
int16_t normalDirectionId = computeCubemapNormalId(contact->getNormal());
|
||||
|
||||
// If there is no contact manifold yet
|
||||
if (mNbManifolds == 0) {
|
||||
if (m_nbManifolds == 0) {
|
||||
|
||||
createManifold(normalDirectionId);
|
||||
mManifolds[0]->addContactPoint(contact);
|
||||
assert(mManifolds[mNbManifolds-1]->getNbContactPoints() > 0);
|
||||
for (int32_t i=0; i<mNbManifolds; i++) {
|
||||
assert(mManifolds[i]->getNbContactPoints() > 0);
|
||||
m_manifolds[0]->addContactPoint(contact);
|
||||
assert(m_manifolds[m_nbManifolds-1]->getNbContactPoints() > 0);
|
||||
for (int32_t i=0; i<m_nbManifolds; i++) {
|
||||
assert(m_manifolds[i]->getNbContactPoints() > 0);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -45,7 +45,7 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) {
|
||||
|
||||
// Select the manifold with the most similar normal (if exists)
|
||||
int32_t similarManifoldIndex = 0;
|
||||
if (mNbMaxManifolds > 1) {
|
||||
if (m_nbMaxManifolds > 1) {
|
||||
similarManifoldIndex = selectManifoldWithSimilarNormal(normalDirectionId);
|
||||
}
|
||||
|
||||
@ -53,20 +53,20 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) {
|
||||
if (similarManifoldIndex != -1) {
|
||||
|
||||
// Add the contact point to that similar manifold
|
||||
mManifolds[similarManifoldIndex]->addContactPoint(contact);
|
||||
assert(mManifolds[similarManifoldIndex]->getNbContactPoints() > 0);
|
||||
m_manifolds[similarManifoldIndex]->addContactPoint(contact);
|
||||
assert(m_manifolds[similarManifoldIndex]->getNbContactPoints() > 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the maximum number of manifold has not been reached yet
|
||||
if (mNbManifolds < mNbMaxManifolds) {
|
||||
if (m_nbManifolds < m_nbMaxManifolds) {
|
||||
|
||||
// Create a new manifold for the contact point
|
||||
createManifold(normalDirectionId);
|
||||
mManifolds[mNbManifolds-1]->addContactPoint(contact);
|
||||
for (int32_t i=0; i<mNbManifolds; i++) {
|
||||
assert(mManifolds[i]->getNbContactPoints() > 0);
|
||||
m_manifolds[m_nbManifolds-1]->addContactPoint(contact);
|
||||
for (int32_t i=0; i<m_nbManifolds; i++) {
|
||||
assert(m_manifolds[i]->getNbContactPoints() > 0);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -77,9 +77,9 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) {
|
||||
// with the largest contact depth among their points
|
||||
int32_t smallestDepthIndex = -1;
|
||||
float minDepth = contact->getPenetrationDepth();
|
||||
assert(mNbManifolds == mNbMaxManifolds);
|
||||
for (int32_t i=0; i<mNbManifolds; i++) {
|
||||
float depth = mManifolds[i]->getLargestContactDepth();
|
||||
assert(m_nbManifolds == m_nbMaxManifolds);
|
||||
for (int32_t i=0; i<m_nbManifolds; i++) {
|
||||
float depth = m_manifolds[i]->getLargestContactDepth();
|
||||
if (depth < minDepth) {
|
||||
minDepth = depth;
|
||||
smallestDepthIndex = i;
|
||||
@ -92,21 +92,21 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) {
|
||||
|
||||
// Delete the new contact
|
||||
contact->~ContactPoint();
|
||||
mMemoryAllocator.release(contact, sizeof(ContactPoint));
|
||||
m_memoryAllocator.release(contact, sizeof(ContactPoint));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
assert(smallestDepthIndex >= 0 && smallestDepthIndex < mNbManifolds);
|
||||
assert(smallestDepthIndex >= 0 && smallestDepthIndex < m_nbManifolds);
|
||||
|
||||
// Here we need to replace an existing manifold with a new one (that contains
|
||||
// the new contact point)
|
||||
removeManifold(smallestDepthIndex);
|
||||
createManifold(normalDirectionId);
|
||||
mManifolds[mNbManifolds-1]->addContactPoint(contact);
|
||||
assert(mManifolds[mNbManifolds-1]->getNbContactPoints() > 0);
|
||||
for (int32_t i=0; i<mNbManifolds; i++) {
|
||||
assert(mManifolds[i]->getNbContactPoints() > 0);
|
||||
m_manifolds[m_nbManifolds-1]->addContactPoint(contact);
|
||||
assert(m_manifolds[m_nbManifolds-1]->getNbContactPoints() > 0);
|
||||
for (int32_t i=0; i<m_nbManifolds; i++) {
|
||||
assert(m_manifolds[i]->getNbContactPoints() > 0);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -117,8 +117,8 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) {
|
||||
int32_t ContactManifoldSet::selectManifoldWithSimilarNormal(int16_t normalDirectionId) const {
|
||||
|
||||
// Return the Id of the manifold with the same normal direction id (if exists)
|
||||
for (int32_t i=0; i<mNbManifolds; i++) {
|
||||
if (normalDirectionId == mManifolds[i]->getNormalDirectionId()) {
|
||||
for (int32_t i=0; i<m_nbManifolds; i++) {
|
||||
if (normalDirectionId == m_manifolds[i]->getNormalDirectionId()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -166,14 +166,14 @@ int16_t ContactManifoldSet::computeCubemapNormalId(const Vector3& normal) const
|
||||
// Update the contact manifolds
|
||||
void ContactManifoldSet::update() {
|
||||
|
||||
for (int32_t i=mNbManifolds-1; i>=0; i--) {
|
||||
for (int32_t i=m_nbManifolds-1; i>=0; i--) {
|
||||
|
||||
// Update the contact manifold
|
||||
mManifolds[i]->update(mShape1->getBody()->getTransform() * mShape1->getLocalToBodyTransform(),
|
||||
mShape2->getBody()->getTransform() * mShape2->getLocalToBodyTransform());
|
||||
m_manifolds[i]->update(m_shape1->getBody()->getTransform() * m_shape1->getLocalToBodyTransform(),
|
||||
m_shape2->getBody()->getTransform() * m_shape2->getLocalToBodyTransform());
|
||||
|
||||
// Remove the contact manifold if has no contact points anymore
|
||||
if (mManifolds[i]->getNbContactPoints() == 0) {
|
||||
if (m_manifolds[i]->getNbContactPoints() == 0) {
|
||||
removeManifold(i);
|
||||
}
|
||||
}
|
||||
@ -183,35 +183,35 @@ void ContactManifoldSet::update() {
|
||||
void ContactManifoldSet::clear() {
|
||||
|
||||
// Destroy all the contact manifolds
|
||||
for (int32_t i=mNbManifolds-1; i>=0; i--) {
|
||||
for (int32_t i=m_nbManifolds-1; i>=0; i--) {
|
||||
removeManifold(i);
|
||||
}
|
||||
|
||||
assert(mNbManifolds == 0);
|
||||
assert(m_nbManifolds == 0);
|
||||
}
|
||||
|
||||
// Create a new contact manifold and add it to the set
|
||||
void ContactManifoldSet::createManifold(int16_t normalDirectionId) {
|
||||
assert(mNbManifolds < mNbMaxManifolds);
|
||||
assert(m_nbManifolds < m_nbMaxManifolds);
|
||||
|
||||
mManifolds[mNbManifolds] = new (mMemoryAllocator.allocate(sizeof(ContactManifold)))
|
||||
ContactManifold(mShape1, mShape2, mMemoryAllocator, normalDirectionId);
|
||||
mNbManifolds++;
|
||||
m_manifolds[m_nbManifolds] = new (m_memoryAllocator.allocate(sizeof(ContactManifold)))
|
||||
ContactManifold(m_shape1, m_shape2, m_memoryAllocator, normalDirectionId);
|
||||
m_nbManifolds++;
|
||||
}
|
||||
|
||||
// Remove a contact manifold from the set
|
||||
void ContactManifoldSet::removeManifold(int32_t index) {
|
||||
|
||||
assert(mNbManifolds > 0);
|
||||
assert(index >= 0 && index < mNbManifolds);
|
||||
assert(m_nbManifolds > 0);
|
||||
assert(index >= 0 && index < m_nbManifolds);
|
||||
|
||||
// Delete the new contact
|
||||
mManifolds[index]->~ContactManifold();
|
||||
mMemoryAllocator.release(mManifolds[index], sizeof(ContactManifold));
|
||||
m_manifolds[index]->~ContactManifold();
|
||||
m_memoryAllocator.release(m_manifolds[index], sizeof(ContactManifold));
|
||||
|
||||
for (int32_t i=index; (i+1) < mNbManifolds; i++) {
|
||||
mManifolds[i] = mManifolds[i+1];
|
||||
for (int32_t i=index; (i+1) < m_nbManifolds; i++) {
|
||||
m_manifolds[i] = m_manifolds[i+1];
|
||||
}
|
||||
|
||||
mNbManifolds--;
|
||||
m_nbManifolds--;
|
||||
}
|
||||
|
@ -28,22 +28,22 @@ class ContactManifoldSet {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Maximum number of contact manifolds in the set
|
||||
int32_t mNbMaxManifolds;
|
||||
int32_t m_nbMaxManifolds;
|
||||
|
||||
/// Current number of contact manifolds in the set
|
||||
int32_t mNbManifolds;
|
||||
int32_t m_nbManifolds;
|
||||
|
||||
/// Pointer to the first proxy shape of the contact
|
||||
ProxyShape* mShape1;
|
||||
ProxyShape* m_shape1;
|
||||
|
||||
/// Pointer to the second proxy shape of the contact
|
||||
ProxyShape* mShape2;
|
||||
ProxyShape* m_shape2;
|
||||
|
||||
/// Reference to the memory allocator
|
||||
MemoryAllocator& mMemoryAllocator;
|
||||
MemoryAllocator& m_memoryAllocator;
|
||||
|
||||
/// Contact manifolds of the set
|
||||
ContactManifold* mManifolds[MAX_MANIFOLDS_IN_CONTACT_MANIFOLD_SET];
|
||||
ContactManifold* m_manifolds[MAX_MANIFOLDS_IN_CONTACT_MANIFOLD_SET];
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -99,30 +99,30 @@ class ContactManifoldSet {
|
||||
|
||||
// Return the first proxy shape
|
||||
inline ProxyShape* ContactManifoldSet::getShape1() const {
|
||||
return mShape1;
|
||||
return m_shape1;
|
||||
}
|
||||
|
||||
// Return the second proxy shape
|
||||
inline ProxyShape* ContactManifoldSet::getShape2() const {
|
||||
return mShape2;
|
||||
return m_shape2;
|
||||
}
|
||||
|
||||
// Return the number of manifolds in the set
|
||||
inline int32_t ContactManifoldSet::getNbContactManifolds() const {
|
||||
return mNbManifolds;
|
||||
return m_nbManifolds;
|
||||
}
|
||||
|
||||
// Return a given contact manifold
|
||||
inline ContactManifold* ContactManifoldSet::getContactManifold(int32_t index) const {
|
||||
assert(index >= 0 && index < mNbManifolds);
|
||||
return mManifolds[index];
|
||||
assert(index >= 0 && index < m_nbManifolds);
|
||||
return m_manifolds[index];
|
||||
}
|
||||
|
||||
// Return the total number of contact points in the set of manifolds
|
||||
inline int32_t ContactManifoldSet::getTotalNbContactPoints() const {
|
||||
int32_t nbPoints = 0;
|
||||
for (int32_t i=0; i<mNbManifolds; i++) {
|
||||
nbPoints += mManifolds[i]->getNbContactPoints();
|
||||
for (int32_t i=0; i<m_nbManifolds; i++) {
|
||||
nbPoints += m_manifolds[i]->getNbContactPoints();
|
||||
}
|
||||
return nbPoints;
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ using namespace reactphysics3d;
|
||||
* @param mass Mass of the collision shape (in kilograms)
|
||||
*/
|
||||
ProxyShape::ProxyShape(CollisionBody* body, CollisionShape* shape, const Transform& transform, float mass)
|
||||
:mBody(body), mCollisionShape(shape), mLocalToBodyTransform(transform), mMass(mass),
|
||||
mNext(NULL), mBroadPhaseID(-1), mCachedCollisionData(NULL), m_userData(NULL),
|
||||
mCollisionCategoryBits(0x0001), mCollideWithMaskBits(0xFFFF) {
|
||||
:m_body(body), m_collisionShape(shape), m_localToBodyTransform(transform), m_mass(mass),
|
||||
m_next(NULL), m_broadPhaseID(-1), m_cachedCollisionData(NULL), m_userData(NULL),
|
||||
m_collisionCategoryBits(0x0001), m_collideWithMaskBits(0xFFFF) {
|
||||
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ ProxyShape::ProxyShape(CollisionBody* body, CollisionShape* shape, const Transfo
|
||||
ProxyShape::~ProxyShape() {
|
||||
|
||||
// Release the cached collision data memory
|
||||
if (mCachedCollisionData != NULL) {
|
||||
free(mCachedCollisionData);
|
||||
if (m_cachedCollisionData != NULL) {
|
||||
free(m_cachedCollisionData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,9 +38,9 @@ ProxyShape::~ProxyShape() {
|
||||
* @return True if the point is inside the collision shape
|
||||
*/
|
||||
bool ProxyShape::testPointInside(const Vector3& worldPoint) {
|
||||
const Transform localToWorld = mBody->getTransform() * mLocalToBodyTransform;
|
||||
const Transform localToWorld = m_body->getTransform() * m_localToBodyTransform;
|
||||
const Vector3 localPoint = localToWorld.getInverse() * worldPoint;
|
||||
return mCollisionShape->testPointInside(localPoint, this);
|
||||
return m_collisionShape->testPointInside(localPoint, this);
|
||||
}
|
||||
|
||||
// Raycast method with feedback information
|
||||
@ -53,7 +53,7 @@ bool ProxyShape::testPointInside(const Vector3& worldPoint) {
|
||||
bool ProxyShape::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
||||
|
||||
// If the corresponding body is not active, it cannot be hit by rays
|
||||
if (!mBody->isActive()) return false;
|
||||
if (!m_body->isActive()) return false;
|
||||
|
||||
// Convert the ray int32_to the local-space of the collision shape
|
||||
const Transform localToWorldTransform = getLocalToWorldTransform();
|
||||
@ -62,7 +62,7 @@ bool ProxyShape::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
||||
worldToLocalTransform * ray.point2,
|
||||
ray.maxFraction);
|
||||
|
||||
bool isHit = mCollisionShape->raycast(rayLocal, raycastInfo, this);
|
||||
bool isHit = m_collisionShape->raycast(rayLocal, raycastInfo, this);
|
||||
|
||||
// Convert the raycast info int32_to world-space
|
||||
raycastInfo.worldPoint = localToWorldTransform * raycastInfo.worldPoint;
|
||||
|
@ -28,25 +28,25 @@ class ProxyShape {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Pointer to the parent body
|
||||
CollisionBody* mBody;
|
||||
CollisionBody* m_body;
|
||||
|
||||
/// Internal collision shape
|
||||
CollisionShape* mCollisionShape;
|
||||
CollisionShape* m_collisionShape;
|
||||
|
||||
/// Local-space to parent body-space transform (does not change over time)
|
||||
Transform mLocalToBodyTransform;
|
||||
Transform m_localToBodyTransform;
|
||||
|
||||
/// Mass (in kilogramms) of the corresponding collision shape
|
||||
float mMass;
|
||||
float m_mass;
|
||||
|
||||
/// Pointer to the next proxy shape of the body (linked list)
|
||||
ProxyShape* mNext;
|
||||
ProxyShape* m_next;
|
||||
|
||||
/// Broad-phase ID (node ID in the dynamic AABB tree)
|
||||
int32_t mBroadPhaseID;
|
||||
int32_t m_broadPhaseID;
|
||||
|
||||
/// Cached collision data
|
||||
void* mCachedCollisionData;
|
||||
void* m_cachedCollisionData;
|
||||
|
||||
/// Pointer to user data
|
||||
void* m_userData;
|
||||
@ -54,15 +54,15 @@ class ProxyShape {
|
||||
/// Bits used to define the collision category of this shape.
|
||||
/// You can set a single bit to one to define a category value for this
|
||||
/// shape. This value is one (0x0001) by default. This variable can be used
|
||||
/// together with the mCollideWithMaskBits variable so that given
|
||||
/// together with the m_collideWithMaskBits variable so that given
|
||||
/// categories of shapes collide with each other and do not collide with
|
||||
/// other categories.
|
||||
unsigned short mCollisionCategoryBits;
|
||||
unsigned short m_collisionCategoryBits;
|
||||
|
||||
/// Bits mask used to state which collision categories this shape can
|
||||
/// collide with. This value is 0xFFFF by default. It means that this
|
||||
/// proxy shape will collide with every collision categories by default.
|
||||
unsigned short mCollideWithMaskBits;
|
||||
unsigned short m_collideWithMaskBits;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -158,7 +158,7 @@ class ProxyShape {
|
||||
|
||||
// Return the pointer to the cached collision data
|
||||
inline void** ProxyShape::getCachedCollisionData() {
|
||||
return &mCachedCollisionData;
|
||||
return &m_cachedCollisionData;
|
||||
}
|
||||
|
||||
// Return the collision shape
|
||||
@ -166,7 +166,7 @@ inline void** ProxyShape::getCachedCollisionData() {
|
||||
* @return Pointer to the int32_ternal collision shape
|
||||
*/
|
||||
inline const CollisionShape* ProxyShape::getCollisionShape() const {
|
||||
return mCollisionShape;
|
||||
return m_collisionShape;
|
||||
}
|
||||
|
||||
// Return the parent body
|
||||
@ -174,7 +174,7 @@ inline const CollisionShape* ProxyShape::getCollisionShape() const {
|
||||
* @return Pointer to the parent body
|
||||
*/
|
||||
inline CollisionBody* ProxyShape::getBody() const {
|
||||
return mBody;
|
||||
return m_body;
|
||||
}
|
||||
|
||||
// Return the mass of the collision shape
|
||||
@ -182,7 +182,7 @@ inline CollisionBody* ProxyShape::getBody() const {
|
||||
* @return Mass of the collision shape (in kilograms)
|
||||
*/
|
||||
inline float ProxyShape::getMass() const {
|
||||
return mMass;
|
||||
return m_mass;
|
||||
}
|
||||
|
||||
// Return a pointer to the user data attached to this body
|
||||
@ -207,18 +207,18 @@ inline void ProxyShape::setUserData(void* userData) {
|
||||
* to the local-space of the parent body
|
||||
*/
|
||||
inline const Transform& ProxyShape::getLocalToBodyTransform() const {
|
||||
return mLocalToBodyTransform;
|
||||
return m_localToBodyTransform;
|
||||
}
|
||||
|
||||
// Set the local to parent body transform
|
||||
inline void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
|
||||
|
||||
mLocalToBodyTransform = transform;
|
||||
m_localToBodyTransform = transform;
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Notify the body that the proxy shape has to be updated in the broad-phase
|
||||
mBody->updateProxyShapeInBroadPhase(this, true);
|
||||
m_body->updateProxyShapeInBroadPhase(this, true);
|
||||
}
|
||||
|
||||
// Return the local to world transform
|
||||
@ -227,7 +227,7 @@ inline void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
|
||||
* shape to the world-space
|
||||
*/
|
||||
inline const Transform ProxyShape::getLocalToWorldTransform() const {
|
||||
return mBody->mTransform * mLocalToBodyTransform;
|
||||
return m_body->m_transform * m_localToBodyTransform;
|
||||
}
|
||||
|
||||
// Return the next proxy shape in the linked list of proxy shapes
|
||||
@ -235,7 +235,7 @@ inline const Transform ProxyShape::getLocalToWorldTransform() const {
|
||||
* @return Pointer to the next proxy shape in the linked list of proxy shapes
|
||||
*/
|
||||
inline ProxyShape* ProxyShape::getNext() {
|
||||
return mNext;
|
||||
return m_next;
|
||||
}
|
||||
|
||||
// Return the next proxy shape in the linked list of proxy shapes
|
||||
@ -243,7 +243,7 @@ inline ProxyShape* ProxyShape::getNext() {
|
||||
* @return Pointer to the next proxy shape in the linked list of proxy shapes
|
||||
*/
|
||||
inline const ProxyShape* ProxyShape::getNext() const {
|
||||
return mNext;
|
||||
return m_next;
|
||||
}
|
||||
|
||||
// Return the collision category bits
|
||||
@ -251,7 +251,7 @@ inline const ProxyShape* ProxyShape::getNext() const {
|
||||
* @return The collision category bits mask of the proxy shape
|
||||
*/
|
||||
inline unsigned short ProxyShape::getCollisionCategoryBits() const {
|
||||
return mCollisionCategoryBits;
|
||||
return m_collisionCategoryBits;
|
||||
}
|
||||
|
||||
// Set the collision category bits
|
||||
@ -259,7 +259,7 @@ inline unsigned short ProxyShape::getCollisionCategoryBits() const {
|
||||
* @param collisionCategoryBits The collision category bits mask of the proxy shape
|
||||
*/
|
||||
inline void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategoryBits) {
|
||||
mCollisionCategoryBits = collisionCategoryBits;
|
||||
m_collisionCategoryBits = collisionCategoryBits;
|
||||
}
|
||||
|
||||
// Return the collision bits mask
|
||||
@ -267,7 +267,7 @@ inline void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategor
|
||||
* @return The bits mask that specifies with which collision category this shape will collide
|
||||
*/
|
||||
inline unsigned short ProxyShape::getCollideWithMaskBits() const {
|
||||
return mCollideWithMaskBits;
|
||||
return m_collideWithMaskBits;
|
||||
}
|
||||
|
||||
// Set the collision bits mask
|
||||
@ -275,7 +275,7 @@ inline unsigned short ProxyShape::getCollideWithMaskBits() const {
|
||||
* @param collideWithMaskBits The bits mask that specifies with which collision category this shape will collide
|
||||
*/
|
||||
inline void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBits) {
|
||||
mCollideWithMaskBits = collideWithMaskBits;
|
||||
m_collideWithMaskBits = collideWithMaskBits;
|
||||
}
|
||||
|
||||
// Return the local scaling vector of the collision shape
|
||||
@ -283,7 +283,7 @@ inline void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBit
|
||||
* @return The local scaling vector
|
||||
*/
|
||||
inline Vector3 ProxyShape::getLocalScaling() const {
|
||||
return mCollisionShape->getScaling();
|
||||
return m_collisionShape->getScaling();
|
||||
}
|
||||
|
||||
// Set the local scaling vector of the collision shape
|
||||
@ -293,12 +293,12 @@ inline Vector3 ProxyShape::getLocalScaling() const {
|
||||
inline void ProxyShape::setLocalScaling(const Vector3& scaling) {
|
||||
|
||||
// Set the local scaling of the collision shape
|
||||
mCollisionShape->setLocalScaling(scaling);
|
||||
m_collisionShape->setLocalScaling(scaling);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Notify the body that the proxy shape has to be updated in the broad-phase
|
||||
mBody->updateProxyShapeInBroadPhase(this, true);
|
||||
m_body->updateProxyShapeInBroadPhase(this, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,17 +102,17 @@ void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const A
|
||||
int32_t nodeId = m_dynamicAABBTree.addObject(aabb, proxyShape);
|
||||
|
||||
// Set the broad-phase ID of the proxy shape
|
||||
proxyShape->mBroadPhaseID = nodeId;
|
||||
proxyShape->m_broadPhaseID = nodeId;
|
||||
|
||||
// Add the collision shape int32_to the array of bodies that have moved (or have been created)
|
||||
// during the last simulation step
|
||||
addMovedCollisionShape(proxyShape->mBroadPhaseID);
|
||||
addMovedCollisionShape(proxyShape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
// Remove a proxy collision shape from the broad-phase collision detection
|
||||
void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
|
||||
int32_t broadPhaseID = proxyShape->mBroadPhaseID;
|
||||
int32_t broadPhaseID = proxyShape->m_broadPhaseID;
|
||||
|
||||
// Remove the collision shape from the dynamic AABB tree
|
||||
m_dynamicAABBTree.removeObject(broadPhaseID);
|
||||
@ -126,7 +126,7 @@ void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
void BroadPhaseAlgorithm::updateProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb,
|
||||
const Vector3& displacement, bool forceReinsert) {
|
||||
|
||||
int32_t broadPhaseID = proxyShape->mBroadPhaseID;
|
||||
int32_t broadPhaseID = proxyShape->m_broadPhaseID;
|
||||
|
||||
assert(broadPhaseID >= 0);
|
||||
|
||||
@ -249,7 +249,7 @@ void BroadPhaseAlgorithm::notifyOverlappingNodes(int32_t node1ID, int32_t node2I
|
||||
// DynamicAABBTree:reportAllShapesOverlappingWithAABB()
|
||||
void AABBOverlapCallback::notifyOverlappingNode(int32_t nodeId) {
|
||||
|
||||
mBroadPhaseAlgorithm.notifyOverlappingNodes(m_referenceNodeId, nodeId);
|
||||
m_broadPhaseAlgorithm.notifyOverlappingNodes(m_referenceNodeId, nodeId);
|
||||
}
|
||||
|
||||
// Called for a broad-phase shape that has to be tested for raycast
|
||||
|
@ -45,7 +45,7 @@ class AABBOverlapCallback : public DynamicAABBTreeOverlapCallback {
|
||||
|
||||
private:
|
||||
|
||||
BroadPhaseAlgorithm& mBroadPhaseAlgorithm;
|
||||
BroadPhaseAlgorithm& m_broadPhaseAlgorithm;
|
||||
|
||||
int32_t m_referenceNodeId;
|
||||
|
||||
@ -53,7 +53,7 @@ class AABBOverlapCallback : public DynamicAABBTreeOverlapCallback {
|
||||
|
||||
// Constructor
|
||||
AABBOverlapCallback(BroadPhaseAlgorithm& broadPhaseAlgo, int32_t referenceNodeId)
|
||||
: mBroadPhaseAlgorithm(broadPhaseAlgo), m_referenceNodeId(referenceNodeId) {
|
||||
: m_broadPhaseAlgorithm(broadPhaseAlgo), m_referenceNodeId(referenceNodeId) {
|
||||
|
||||
}
|
||||
|
||||
@ -203,8 +203,8 @@ inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1, const Broad
|
||||
inline bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1,
|
||||
const ProxyShape* shape2) const {
|
||||
// Get the two AABBs of the collision shapes
|
||||
const AABB& aabb1 = m_dynamicAABBTree.getFatAABB(shape1->mBroadPhaseID);
|
||||
const AABB& aabb2 = m_dynamicAABBTree.getFatAABB(shape2->mBroadPhaseID);
|
||||
const AABB& aabb1 = m_dynamicAABBTree.getFatAABB(shape1->m_broadPhaseID);
|
||||
const AABB& aabb2 = m_dynamicAABBTree.getFatAABB(shape2->m_broadPhaseID);
|
||||
|
||||
// Check if the two AABBs are overlapping
|
||||
return aabb1.testCollision(aabb2);
|
||||
|
@ -31,7 +31,7 @@ DynamicAABBTree::~DynamicAABBTree() {
|
||||
// Initialize the tree
|
||||
void DynamicAABBTree::init() {
|
||||
|
||||
mRootNodeID = TreeNode::NULL_TREE_NODE;
|
||||
m_rootNodeID = TreeNode::NULL_TREE_NODE;
|
||||
mNbNodes = 0;
|
||||
mNbAllocatedNodes = 8;
|
||||
|
||||
@ -206,17 +206,17 @@ bool DynamicAABBTree::updateObject(int32_t nodeID, const AABB& newAABB, const Ve
|
||||
void DynamicAABBTree::insertLeafNode(int32_t nodeID) {
|
||||
|
||||
// If the tree is empty
|
||||
if (mRootNodeID == TreeNode::NULL_TREE_NODE) {
|
||||
mRootNodeID = nodeID;
|
||||
mNodes[mRootNodeID].parentID = TreeNode::NULL_TREE_NODE;
|
||||
if (m_rootNodeID == TreeNode::NULL_TREE_NODE) {
|
||||
m_rootNodeID = nodeID;
|
||||
mNodes[m_rootNodeID].parentID = TreeNode::NULL_TREE_NODE;
|
||||
return;
|
||||
}
|
||||
|
||||
assert(mRootNodeID != TreeNode::NULL_TREE_NODE);
|
||||
assert(m_rootNodeID != TreeNode::NULL_TREE_NODE);
|
||||
|
||||
// Find the best sibling node for the new node
|
||||
AABB newNodeAABB = mNodes[nodeID].aabb;
|
||||
int32_t currentNodeID = mRootNodeID;
|
||||
int32_t currentNodeID = m_rootNodeID;
|
||||
while (!mNodes[currentNodeID].isLeaf()) {
|
||||
|
||||
int32_t leftChild = mNodes[currentNodeID].children[0];
|
||||
@ -300,7 +300,7 @@ void DynamicAABBTree::insertLeafNode(int32_t nodeID) {
|
||||
mNodes[newParentNode].children[1] = nodeID;
|
||||
mNodes[siblingNode].parentID = newParentNode;
|
||||
mNodes[nodeID].parentID = newParentNode;
|
||||
mRootNodeID = newParentNode;
|
||||
m_rootNodeID = newParentNode;
|
||||
}
|
||||
|
||||
// Move up in the tree to change the AABBs that have changed
|
||||
@ -339,8 +339,8 @@ void DynamicAABBTree::removeLeafNode(int32_t nodeID) {
|
||||
assert(mNodes[nodeID].isLeaf());
|
||||
|
||||
// If we are removing the root node (root node is a leaf in this case)
|
||||
if (mRootNodeID == nodeID) {
|
||||
mRootNodeID = TreeNode::NULL_TREE_NODE;
|
||||
if (m_rootNodeID == nodeID) {
|
||||
m_rootNodeID = TreeNode::NULL_TREE_NODE;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -395,7 +395,7 @@ void DynamicAABBTree::removeLeafNode(int32_t nodeID) {
|
||||
else { // If the parent of the node to remove is the root node
|
||||
|
||||
// The sibling node becomes the new root node
|
||||
mRootNodeID = siblingNodeID;
|
||||
m_rootNodeID = siblingNodeID;
|
||||
mNodes[siblingNodeID].parentID = TreeNode::NULL_TREE_NODE;
|
||||
releaseNode(parentNodeID);
|
||||
}
|
||||
@ -455,7 +455,7 @@ int32_t DynamicAABBTree::balanceSubTreeAtNode(int32_t nodeID) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
mRootNodeID = nodeCID;
|
||||
m_rootNodeID = nodeCID;
|
||||
}
|
||||
|
||||
assert(!nodeC->isLeaf());
|
||||
@ -525,7 +525,7 @@ int32_t DynamicAABBTree::balanceSubTreeAtNode(int32_t nodeID) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
mRootNodeID = nodeBID;
|
||||
m_rootNodeID = nodeBID;
|
||||
}
|
||||
|
||||
assert(!nodeB->isLeaf());
|
||||
@ -578,7 +578,7 @@ void DynamicAABBTree::reportAllShapesOverlappingWithAABB(const AABB& aabb,
|
||||
|
||||
// Create a stack with the nodes to visit
|
||||
Stack<int32_t, 64> stack;
|
||||
stack.push(mRootNodeID);
|
||||
stack.push(m_rootNodeID);
|
||||
|
||||
// While there are still nodes to visit
|
||||
while(stack.getNbElements() > 0) {
|
||||
@ -619,7 +619,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback &ca
|
||||
float maxFraction = ray.maxFraction;
|
||||
|
||||
Stack<int32_t, 128> stack;
|
||||
stack.push(mRootNodeID);
|
||||
stack.push(m_rootNodeID);
|
||||
|
||||
// Walk through the tree from the root looking for proxy shapes
|
||||
// that overlap with the ray AABB
|
||||
@ -679,7 +679,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback &ca
|
||||
void DynamicAABBTree::check() const {
|
||||
|
||||
// Recursively check each node
|
||||
checkNode(mRootNodeID);
|
||||
checkNode(m_rootNodeID);
|
||||
|
||||
int32_t nbFreeNodes = 0;
|
||||
int32_t freeNodeID = mFreeNodeID;
|
||||
@ -700,7 +700,7 @@ void DynamicAABBTree::checkNode(int32_t nodeID) const {
|
||||
if (nodeID == TreeNode::NULL_TREE_NODE) return;
|
||||
|
||||
// If it is the root
|
||||
if (nodeID == mRootNodeID) {
|
||||
if (nodeID == m_rootNodeID) {
|
||||
assert(mNodes[nodeID].parentID == TreeNode::NULL_TREE_NODE);
|
||||
}
|
||||
|
||||
@ -749,7 +749,7 @@ void DynamicAABBTree::checkNode(int32_t nodeID) const {
|
||||
|
||||
// Compute the height of the tree
|
||||
int32_t DynamicAABBTree::computeHeight() {
|
||||
return computeHeight(mRootNodeID);
|
||||
return computeHeight(m_rootNodeID);
|
||||
}
|
||||
|
||||
// Compute the height of a given node in the tree
|
||||
|
@ -116,7 +116,7 @@ class DynamicAABBTree {
|
||||
TreeNode* mNodes;
|
||||
|
||||
/// ID of the root node of the tree
|
||||
int32_t mRootNodeID;
|
||||
int32_t m_rootNodeID;
|
||||
|
||||
/// ID of the first node of the list of free (allocated) nodes in the tree that we can use
|
||||
int32_t mFreeNodeID;
|
||||
@ -242,7 +242,7 @@ inline void* DynamicAABBTree::getNodeDataPointer(int32_t nodeID) const {
|
||||
|
||||
// Return the root AABB of the tree
|
||||
inline AABB DynamicAABBTree::getRootAABB() const {
|
||||
return getFatAABB(mRootNodeID);
|
||||
return getFatAABB(m_rootNodeID);
|
||||
}
|
||||
|
||||
// Add an object int32_to the tree. This method creates a new leaf node in the tree and
|
||||
|
@ -268,5 +268,5 @@ void SmoothCollisionNarrowPhaseCallback::notifyContact(OverlappingPair* overlapp
|
||||
|
||||
// Add the narrow-phase contact int32_to the list of contact to process for
|
||||
// smooth mesh collision
|
||||
mContactPoints.push_back(smoothContactInfo);
|
||||
m_contactPoints.push_back(smoothContactInfo);
|
||||
}
|
||||
|
@ -134,14 +134,14 @@ class SmoothCollisionNarrowPhaseCallback : public NarrowPhaseCallback {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<SmoothMeshContactInfo>& mContactPoints;
|
||||
std::vector<SmoothMeshContactInfo>& m_contactPoints;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
SmoothCollisionNarrowPhaseCallback(std::vector<SmoothMeshContactInfo>& contactPoints)
|
||||
: mContactPoints(contactPoints) {
|
||||
: m_contactPoints(contactPoints) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class EPAAlgorithm {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Reference to the memory allocator
|
||||
MemoryAllocator* mMemoryAllocator;
|
||||
MemoryAllocator* m_memoryAllocator;
|
||||
|
||||
/// Triangle comparison operator
|
||||
TriangleComparison mTriangleComparison;
|
||||
@ -131,7 +131,7 @@ inline void EPAAlgorithm::addFaceCandidate(TriangleEPA* triangle, TriangleEPA**
|
||||
|
||||
// Initalize the algorithm
|
||||
inline void EPAAlgorithm::init(MemoryAllocator* memoryAllocator) {
|
||||
mMemoryAllocator = memoryAllocator;
|
||||
m_memoryAllocator = memoryAllocator;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
NarrowPhaseAlgorithm::NarrowPhaseAlgorithm()
|
||||
: mMemoryAllocator(NULL), mCurrentOverlappingPair(NULL) {
|
||||
: m_memoryAllocator(NULL), mCurrentOverlappingPair(NULL) {
|
||||
|
||||
}
|
||||
|
||||
@ -24,5 +24,5 @@ NarrowPhaseAlgorithm::~NarrowPhaseAlgorithm() {
|
||||
// Initalize the algorithm
|
||||
void NarrowPhaseAlgorithm::init(CollisionDetection* collisionDetection, MemoryAllocator* memoryAllocator) {
|
||||
m_collisionDetection = collisionDetection;
|
||||
mMemoryAllocator = memoryAllocator;
|
||||
m_memoryAllocator = memoryAllocator;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class NarrowPhaseAlgorithm {
|
||||
CollisionDetection* m_collisionDetection;
|
||||
|
||||
/// Pointer to the memory allocator
|
||||
MemoryAllocator* mMemoryAllocator;
|
||||
MemoryAllocator* m_memoryAllocator;
|
||||
|
||||
/// Overlapping pair of the bodies currently tested for collision
|
||||
OverlappingPair* mCurrentOverlappingPair;
|
||||
|
@ -13,7 +13,7 @@
|
||||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
CollisionShape::CollisionShape(CollisionShapeType type) : mType(type), mScaling(1.0, 1.0, 1.0) {
|
||||
CollisionShape::CollisionShape(CollisionShapeType type) : m_type(type), mScaling(1.0, 1.0, 1.0) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ class CollisionShape {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Type of the collision shape
|
||||
CollisionShapeType mType;
|
||||
CollisionShapeType m_type;
|
||||
|
||||
/// Scaling vector of the collision shape
|
||||
Vector3 mScaling;
|
||||
@ -110,7 +110,7 @@ class CollisionShape {
|
||||
* @return The type of the collision shape (box, sphere, cylinder, ...)
|
||||
*/
|
||||
inline CollisionShapeType CollisionShape::getType() const {
|
||||
return mType;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
// Return true if the collision shape type is a convex shape
|
||||
|
@ -244,6 +244,6 @@ void ConvexMeshShape::recalculateBounds() {
|
||||
|
||||
// Raycast method with feedback information
|
||||
bool ConvexMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const {
|
||||
return proxyShape->mBody->mWorld.m_collisionDetection.mNarrowPhaseGJKAlgorithm.raycast(
|
||||
return proxyShape->m_body->m_world.m_collisionDetection.m_narrowPhaseGJKAlgorithm.raycast(
|
||||
ray, proxyShape, raycastInfo);
|
||||
}
|
||||
|
@ -235,8 +235,8 @@ inline bool ConvexMeshShape::testPointInside(const Vector3& localPoint,
|
||||
ProxyShape* proxyShape) const {
|
||||
|
||||
// Use the GJK algorithm to test if the point is inside the convex mesh
|
||||
return proxyShape->mBody->mWorld.m_collisionDetection.
|
||||
mNarrowPhaseGJKAlgorithm.testPointInside(localPoint, proxyShape);
|
||||
return proxyShape->m_body->m_world.m_collisionDetection.
|
||||
m_narrowPhaseGJKAlgorithm.testPointInside(localPoint, proxyShape);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ BallAndSocketJoint::BallAndSocketJoint(const BallAndSocketJointInfo& jointInfo)
|
||||
: Joint(jointInfo), m_impulse(Vector3(0, 0, 0)) {
|
||||
|
||||
// Compute the local-space anchor point for each body
|
||||
m_localAnchorPointBody1 = mBody1->getTransform().getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = mBody2->getTransform().getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody1 = m_body1->getTransform().getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = m_body2->getTransform().getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -31,18 +31,18 @@ BallAndSocketJoint::~BallAndSocketJoint() {
|
||||
void BallAndSocketJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Initialize the bodies index in the velocity array
|
||||
mIndexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody1)->second;
|
||||
mIndexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody2)->second;
|
||||
m_indexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body1)->second;
|
||||
m_indexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body2)->second;
|
||||
|
||||
// Get the bodies center of mass and orientations
|
||||
const Vector3& x1 = mBody1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = mBody2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = mBody1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = mBody2->getTransform().getOrientation();
|
||||
const Vector3& x1 = m_body1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = m_body2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = m_body1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = m_body2->getTransform().getOrientation();
|
||||
|
||||
// Get the inertia tensor of bodies
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Compute the vector from body center to the anchor point in world-space
|
||||
m_r1World = orientationBody1 * m_localAnchorPointBody1;
|
||||
@ -53,7 +53,7 @@ void BallAndSocketJoint::initBeforeSolve(const ConstraintSolverData& constraintS
|
||||
Matrix3x3 skewSymmetricMatrixU2= Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(m_r2World);
|
||||
|
||||
// Compute the matrix K=JM^-1J^t (3x3 matrix)
|
||||
float inverseMassBodies = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
float inverseMassBodies = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
Matrix3x3 massMatrix = Matrix3x3(inverseMassBodies, 0, 0,
|
||||
0, inverseMassBodies, 0,
|
||||
0, 0, inverseMassBodies) +
|
||||
@ -62,13 +62,13 @@ void BallAndSocketJoint::initBeforeSolve(const ConstraintSolverData& constraintS
|
||||
|
||||
// Compute the inverse mass matrix K^-1
|
||||
m_inverseMassMatrix.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrix = massMatrix.getInverse();
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the constraint
|
||||
m_biasVector.setToZero();
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
float biasFactor = (BETA / constraintSolverData.timeStep);
|
||||
m_biasVector = biasFactor * (x2 + m_r2World - x1 - m_r1World);
|
||||
}
|
||||
@ -85,24 +85,24 @@ void BallAndSocketJoint::initBeforeSolve(const ConstraintSolverData& constraintS
|
||||
void BallAndSocketJoint::warmstart(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Compute the impulse P=J^T * lambda for the body 1
|
||||
const Vector3 linearImpulseBody1 = -m_impulse;
|
||||
const Vector3 angularImpulseBody1 = m_impulse.cross(m_r1World);
|
||||
|
||||
// Apply the impulse to the body 1
|
||||
v1 += mBody1->mMassInverse * linearImpulseBody1;
|
||||
v1 += m_body1->m_massInverse * linearImpulseBody1;
|
||||
w1 += m_i1 * angularImpulseBody1;
|
||||
|
||||
// Compute the impulse P=J^T * lambda for the body 2
|
||||
const Vector3 angularImpulseBody2 = -m_impulse.cross(m_r2World);
|
||||
|
||||
// Apply the impulse to the body to the body 2
|
||||
v2 += mBody2->mMassInverse * m_impulse;
|
||||
v2 += m_body2->m_massInverse * m_impulse;
|
||||
w2 += m_i2 * angularImpulseBody2;
|
||||
}
|
||||
|
||||
@ -110,10 +110,10 @@ void BallAndSocketJoint::warmstart(const ConstraintSolverData& constraintSolverD
|
||||
void BallAndSocketJoint::solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Compute J*v
|
||||
const Vector3 Jv = v2 + w2.cross(m_r2World) - v1 - w1.cross(m_r1World);
|
||||
@ -127,14 +127,14 @@ void BallAndSocketJoint::solveVelocityConstraint(const ConstraintSolverData& con
|
||||
const Vector3 angularImpulseBody1 = deltaLambda.cross(m_r1World);
|
||||
|
||||
// Apply the impulse to the body 1
|
||||
v1 += mBody1->mMassInverse * linearImpulseBody1;
|
||||
v1 += m_body1->m_massInverse * linearImpulseBody1;
|
||||
w1 += m_i1 * angularImpulseBody1;
|
||||
|
||||
// Compute the impulse P=J^T * lambda for the body 2
|
||||
const Vector3 angularImpulseBody2 = -deltaLambda.cross(m_r2World);
|
||||
|
||||
// Apply the impulse to the body 2
|
||||
v2 += mBody2->mMassInverse * deltaLambda;
|
||||
v2 += m_body2->m_massInverse * deltaLambda;
|
||||
w2 += m_i2 * angularImpulseBody2;
|
||||
}
|
||||
|
||||
@ -143,21 +143,21 @@ void BallAndSocketJoint::solvePositionConstraint(const ConstraintSolverData& con
|
||||
|
||||
// If the error position correction technique is not the non-linear-gauss-seidel, we do
|
||||
// do not execute this method
|
||||
if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
if (m_positionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
|
||||
// Get the bodies center of mass and orientations
|
||||
Vector3& x1 = constraintSolverData.positions[mIndexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[mIndexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[mIndexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[mIndexBody2];
|
||||
Vector3& x1 = constraintSolverData.positions[m_indexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[m_indexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[m_indexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
float inverseMassBody1 = mBody1->mMassInverse;
|
||||
float inverseMassBody2 = mBody2->mMassInverse;
|
||||
float inverseMassBody1 = m_body1->m_massInverse;
|
||||
float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// Recompute the inverse inertia tensors
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Compute the vector from body center to the anchor point in world-space
|
||||
m_r1World = q1 * m_localAnchorPointBody1;
|
||||
@ -175,7 +175,7 @@ void BallAndSocketJoint::solvePositionConstraint(const ConstraintSolverData& con
|
||||
skewSymmetricMatrixU1 * m_i1 * skewSymmetricMatrixU1.getTranspose() +
|
||||
skewSymmetricMatrixU2 * m_i2 * skewSymmetricMatrixU2.getTranspose();
|
||||
m_inverseMassMatrix.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrix = massMatrix.getInverse();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ struct BallAndSocketJointInfo : public JointInfo {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Anchor point (in world-space coordinates)
|
||||
Vector3 m_m_m_m_anchorPointWorldSpace;
|
||||
Vector3 m_anchorPointWorldSpace;
|
||||
|
||||
/// Constructor
|
||||
/**
|
||||
@ -35,7 +35,7 @@ struct BallAndSocketJointInfo : public JointInfo {
|
||||
BallAndSocketJointInfo(RigidBody* rigidBody1, RigidBody* rigidBody2,
|
||||
const Vector3& initAnchorPointWorldSpace)
|
||||
: JointInfo(rigidBody1, rigidBody2, BALLSOCKETJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace) {}
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace) {}
|
||||
};
|
||||
|
||||
// Class BallAndSocketJoint
|
||||
|
@ -13,21 +13,21 @@ using namespace std;
|
||||
|
||||
// Constructor
|
||||
ContactPoint::ContactPoint(const ContactPointInfo& contactInfo)
|
||||
: mBody1(contactInfo.shape1->getBody()), mBody2(contactInfo.shape2->getBody()),
|
||||
: m_body1(contactInfo.shape1->getBody()), m_body2(contactInfo.shape2->getBody()),
|
||||
mNormal(contactInfo.normal),
|
||||
mPenetrationDepth(contactInfo.penetrationDepth),
|
||||
mLocalPointOnBody1(contactInfo.localPoint1),
|
||||
mLocalPointOnBody2(contactInfo.localPoint2),
|
||||
mWorldPointOnBody1(contactInfo.shape1->getBody()->getTransform() *
|
||||
m_worldPointOnBody1(contactInfo.shape1->getBody()->getTransform() *
|
||||
contactInfo.shape1->getLocalToBodyTransform() *
|
||||
contactInfo.localPoint1),
|
||||
mWorldPointOnBody2(contactInfo.shape2->getBody()->getTransform() *
|
||||
m_worldPointOnBody2(contactInfo.shape2->getBody()->getTransform() *
|
||||
contactInfo.shape2->getLocalToBodyTransform() *
|
||||
contactInfo.localPoint2),
|
||||
mIsRestingContact(false) {
|
||||
|
||||
mFrictionVectors[0] = Vector3(0, 0, 0);
|
||||
mFrictionVectors[1] = Vector3(0, 0, 0);
|
||||
m_frictionVectors[0] = Vector3(0, 0, 0);
|
||||
m_frictionVectors[1] = Vector3(0, 0, 0);
|
||||
|
||||
assert(mPenetrationDepth > 0.0);
|
||||
|
||||
|
@ -81,10 +81,10 @@ class ContactPoint {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// First rigid body of the contact
|
||||
CollisionBody* mBody1;
|
||||
CollisionBody* m_body1;
|
||||
|
||||
/// Second rigid body of the contact
|
||||
CollisionBody* mBody2;
|
||||
CollisionBody* m_body2;
|
||||
|
||||
/// Normalized normal vector of the contact (from body1 toward body2) in world space
|
||||
const Vector3 mNormal;
|
||||
@ -99,28 +99,28 @@ class ContactPoint {
|
||||
const Vector3 mLocalPointOnBody2;
|
||||
|
||||
/// Contact point on body 1 in world space
|
||||
Vector3 mWorldPointOnBody1;
|
||||
Vector3 m_worldPointOnBody1;
|
||||
|
||||
/// Contact point on body 2 in world space
|
||||
Vector3 mWorldPointOnBody2;
|
||||
Vector3 m_worldPointOnBody2;
|
||||
|
||||
/// True if the contact is a resting contact (exists for more than one time step)
|
||||
bool mIsRestingContact;
|
||||
|
||||
/// Two orthogonal vectors that span the tangential friction plane
|
||||
Vector3 mFrictionVectors[2];
|
||||
Vector3 m_frictionVectors[2];
|
||||
|
||||
/// Cached penetration impulse
|
||||
float mPenetrationImpulse;
|
||||
|
||||
/// Cached first friction impulse
|
||||
float mFrictionImpulse1;
|
||||
float m_frictionImpulse1;
|
||||
|
||||
/// Cached second friction impulse
|
||||
float mFrictionImpulse2;
|
||||
float m_frictionImpulse2;
|
||||
|
||||
/// Cached rolling resistance impulse
|
||||
Vector3 mRollingResistanceImpulse;
|
||||
Vector3 m_rollingResistanceImpulse;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -221,12 +221,12 @@ class ContactPoint {
|
||||
|
||||
// Return the reference to the body 1
|
||||
inline CollisionBody* ContactPoint::getBody1() const {
|
||||
return mBody1;
|
||||
return m_body1;
|
||||
}
|
||||
|
||||
// Return the reference to the body 2
|
||||
inline CollisionBody* ContactPoint::getBody2() const {
|
||||
return mBody2;
|
||||
return m_body2;
|
||||
}
|
||||
|
||||
// Return the normal vector of the contact
|
||||
@ -251,12 +251,12 @@ inline Vector3 ContactPoint::getLocalPointOnBody2() const {
|
||||
|
||||
// Return the contact world point on body 1
|
||||
inline Vector3 ContactPoint::getWorldPointOnBody1() const {
|
||||
return mWorldPointOnBody1;
|
||||
return m_worldPointOnBody1;
|
||||
}
|
||||
|
||||
// Return the contact world point on body 2
|
||||
inline Vector3 ContactPoint::getWorldPointOnBody2() const {
|
||||
return mWorldPointOnBody2;
|
||||
return m_worldPointOnBody2;
|
||||
}
|
||||
|
||||
// Return the cached penetration impulse
|
||||
@ -266,17 +266,17 @@ inline float ContactPoint::getPenetrationImpulse() const {
|
||||
|
||||
// Return the cached first friction impulse
|
||||
inline float ContactPoint::getFrictionImpulse1() const {
|
||||
return mFrictionImpulse1;
|
||||
return m_frictionImpulse1;
|
||||
}
|
||||
|
||||
// Return the cached second friction impulse
|
||||
inline float ContactPoint::getFrictionImpulse2() const {
|
||||
return mFrictionImpulse2;
|
||||
return m_frictionImpulse2;
|
||||
}
|
||||
|
||||
// Return the cached rolling resistance impulse
|
||||
inline Vector3 ContactPoint::getRollingResistanceImpulse() const {
|
||||
return mRollingResistanceImpulse;
|
||||
return m_rollingResistanceImpulse;
|
||||
}
|
||||
|
||||
// Set the cached penetration impulse
|
||||
@ -286,27 +286,27 @@ inline void ContactPoint::setPenetrationImpulse(float impulse) {
|
||||
|
||||
// Set the first cached friction impulse
|
||||
inline void ContactPoint::setFrictionImpulse1(float impulse) {
|
||||
mFrictionImpulse1 = impulse;
|
||||
m_frictionImpulse1 = impulse;
|
||||
}
|
||||
|
||||
// Set the second cached friction impulse
|
||||
inline void ContactPoint::setFrictionImpulse2(float impulse) {
|
||||
mFrictionImpulse2 = impulse;
|
||||
m_frictionImpulse2 = impulse;
|
||||
}
|
||||
|
||||
// Set the cached rolling resistance impulse
|
||||
inline void ContactPoint::setRollingResistanceImpulse(const Vector3& impulse) {
|
||||
mRollingResistanceImpulse = impulse;
|
||||
m_rollingResistanceImpulse = impulse;
|
||||
}
|
||||
|
||||
// Set the contact world point on body 1
|
||||
inline void ContactPoint::setWorldPointOnBody1(const Vector3& worldPoint) {
|
||||
mWorldPointOnBody1 = worldPoint;
|
||||
m_worldPointOnBody1 = worldPoint;
|
||||
}
|
||||
|
||||
// Set the contact world point on body 2
|
||||
inline void ContactPoint::setWorldPointOnBody2(const Vector3& worldPoint) {
|
||||
mWorldPointOnBody2 = worldPoint;
|
||||
m_worldPointOnBody2 = worldPoint;
|
||||
}
|
||||
|
||||
// Return true if the contact is a resting contact
|
||||
@ -321,22 +321,22 @@ inline void ContactPoint::setIsRestingContact(bool isRestingContact) {
|
||||
|
||||
// Get the first friction vector
|
||||
inline Vector3 ContactPoint::getFrictionVector1() const {
|
||||
return mFrictionVectors[0];
|
||||
return m_frictionVectors[0];
|
||||
}
|
||||
|
||||
// Set the first friction vector
|
||||
inline void ContactPoint::setFrictionVector1(const Vector3& frictionVector1) {
|
||||
mFrictionVectors[0] = frictionVector1;
|
||||
m_frictionVectors[0] = frictionVector1;
|
||||
}
|
||||
|
||||
// Get the second friction vector
|
||||
inline Vector3 ContactPoint::getFrictionVector2() const {
|
||||
return mFrictionVectors[1];
|
||||
return m_frictionVectors[1];
|
||||
}
|
||||
|
||||
// Set the second friction vector
|
||||
inline void ContactPoint::setFrictionVector2(const Vector3& frictionVector2) {
|
||||
mFrictionVectors[1] = frictionVector2;
|
||||
m_frictionVectors[1] = frictionVector2;
|
||||
}
|
||||
|
||||
// Return the penetration depth of the contact
|
||||
|
@ -18,16 +18,16 @@ FixedJoint::FixedJoint(const FixedJointInfo& jointInfo)
|
||||
: Joint(jointInfo), m_impulseTranslation(0, 0, 0), m_impulseRotation(0, 0, 0) {
|
||||
|
||||
// Compute the local-space anchor point for each body
|
||||
const Transform& transform1 = mBody1->getTransform();
|
||||
const Transform& transform2 = mBody2->getTransform();
|
||||
m_localAnchorPointBody1 = transform1.getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = transform2.getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
const Transform& transform1 = m_body1->getTransform();
|
||||
const Transform& transform2 = m_body2->getTransform();
|
||||
m_localAnchorPointBody1 = transform1.getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = transform2.getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
|
||||
// Compute the inverse of the initial orientation difference between the two bodies
|
||||
mInitOrientationDifferenceInv = transform2.getOrientation() *
|
||||
m_initOrientationDifferenceInv = transform2.getOrientation() *
|
||||
transform1.getOrientation().getInverse();
|
||||
mInitOrientationDifferenceInv.normalize();
|
||||
mInitOrientationDifferenceInv.inverse();
|
||||
m_initOrientationDifferenceInv.normalize();
|
||||
m_initOrientationDifferenceInv.inverse();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -39,18 +39,18 @@ FixedJoint::~FixedJoint() {
|
||||
void FixedJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Initialize the bodies index in the velocity array
|
||||
mIndexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody1)->second;
|
||||
mIndexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody2)->second;
|
||||
m_indexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body1)->second;
|
||||
m_indexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body2)->second;
|
||||
|
||||
// Get the bodies positions and orientations
|
||||
const Vector3& x1 = mBody1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = mBody2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = mBody1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = mBody2->getTransform().getOrientation();
|
||||
const Vector3& x1 = m_body1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = m_body2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = m_body1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = m_body2->getTransform().getOrientation();
|
||||
|
||||
// Get the inertia tensor of bodies
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Compute the vector from body center to the anchor point in world-space
|
||||
m_r1World = orientationBody1 * m_localAnchorPointBody1;
|
||||
@ -61,7 +61,7 @@ void FixedJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat
|
||||
Matrix3x3 skewSymmetricMatrixU2= Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(m_r2World);
|
||||
|
||||
// Compute the matrix K=JM^-1J^t (3x3 matrix) for the 3 translation constraints
|
||||
float inverseMassBodies = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
float inverseMassBodies = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
Matrix3x3 massMatrix = Matrix3x3(inverseMassBodies, 0, 0,
|
||||
0, inverseMassBodies, 0,
|
||||
0, 0, inverseMassBodies) +
|
||||
@ -70,31 +70,31 @@ void FixedJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat
|
||||
|
||||
// Compute the inverse mass matrix K^-1 for the 3 translation constraints
|
||||
m_inverseMassMatrixTranslation.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixTranslation = massMatrix.getInverse();
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the constraint for the 3 translation constraints
|
||||
float biasFactor = (BETA / constraintSolverData.timeStep);
|
||||
mBiasTranslation.setToZero();
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBiasTranslation = biasFactor * (x2 + m_r2World - x1 - m_r1World);
|
||||
m_biasTranslation.setToZero();
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
m_biasTranslation = biasFactor * (x2 + m_r2World - x1 - m_r1World);
|
||||
}
|
||||
|
||||
// Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation
|
||||
// contraints (3x3 matrix)
|
||||
m_inverseMassMatrixRotation = m_i1 + m_i2;
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixRotation = m_inverseMassMatrixRotation.getInverse();
|
||||
}
|
||||
|
||||
// Compute the bias "b" for the 3 rotation constraints
|
||||
mBiasRotation.setToZero();
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
m_biasRotation.setToZero();
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
Quaternion currentOrientationDifference = orientationBody2 * orientationBody1.getInverse();
|
||||
currentOrientationDifference.normalize();
|
||||
const Quaternion qError = currentOrientationDifference * mInitOrientationDifferenceInv;
|
||||
mBiasRotation = biasFactor * float(2.0) * qError.getVectorV();
|
||||
const Quaternion qError = currentOrientationDifference * m_initOrientationDifferenceInv;
|
||||
m_biasRotation = biasFactor * float(2.0) * qError.getVectorV();
|
||||
}
|
||||
|
||||
// If warm-starting is not enabled
|
||||
@ -110,14 +110,14 @@ void FixedJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat
|
||||
void FixedJoint::warmstart(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Get the inverse mass of the bodies
|
||||
const float inverseMassBody1 = mBody1->mMassInverse;
|
||||
const float inverseMassBody2 = mBody2->mMassInverse;
|
||||
const float inverseMassBody1 = m_body1->m_massInverse;
|
||||
const float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// Compute the impulse P=J^T * lambda for the 3 translation constraints for body 1
|
||||
Vector3 linearImpulseBody1 = -m_impulseTranslation;
|
||||
@ -145,14 +145,14 @@ void FixedJoint::warmstart(const ConstraintSolverData& constraintSolverData) {
|
||||
void FixedJoint::solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Get the inverse mass of the bodies
|
||||
float inverseMassBody1 = mBody1->mMassInverse;
|
||||
float inverseMassBody2 = mBody2->mMassInverse;
|
||||
float inverseMassBody1 = m_body1->m_massInverse;
|
||||
float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// --------------- Translation Constraints --------------- //
|
||||
|
||||
@ -161,7 +161,7 @@ void FixedJoint::solveVelocityConstraint(const ConstraintSolverData& constraintS
|
||||
|
||||
// Compute the Lagrange multiplier lambda
|
||||
const Vector3 deltaLambda = m_inverseMassMatrixTranslation *
|
||||
(-JvTranslation - mBiasTranslation);
|
||||
(-JvTranslation - m_biasTranslation);
|
||||
m_impulseTranslation += deltaLambda;
|
||||
|
||||
// Compute the impulse P=J^T * lambda for body 1
|
||||
@ -185,7 +185,7 @@ void FixedJoint::solveVelocityConstraint(const ConstraintSolverData& constraintS
|
||||
const Vector3 JvRotation = w2 - w1;
|
||||
|
||||
// Compute the Lagrange multiplier lambda for the 3 rotation constraints
|
||||
Vector3 deltaLambda2 = m_inverseMassMatrixRotation * (-JvRotation - mBiasRotation);
|
||||
Vector3 deltaLambda2 = m_inverseMassMatrixRotation * (-JvRotation - m_biasRotation);
|
||||
m_impulseRotation += deltaLambda2;
|
||||
|
||||
// Compute the impulse P=J^T * lambda for the 3 rotation constraints for body 1
|
||||
@ -203,21 +203,21 @@ void FixedJoint::solvePositionConstraint(const ConstraintSolverData& constraintS
|
||||
|
||||
// If the error position correction technique is not the non-linear-gauss-seidel, we do
|
||||
// do not execute this method
|
||||
if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
if (m_positionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
|
||||
// Get the bodies positions and orientations
|
||||
Vector3& x1 = constraintSolverData.positions[mIndexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[mIndexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[mIndexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[mIndexBody2];
|
||||
Vector3& x1 = constraintSolverData.positions[m_indexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[m_indexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[m_indexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
float inverseMassBody1 = mBody1->mMassInverse;
|
||||
float inverseMassBody2 = mBody2->mMassInverse;
|
||||
float inverseMassBody1 = m_body1->m_massInverse;
|
||||
float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// Recompute the inverse inertia tensors
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Compute the vector from body center to the anchor point in world-space
|
||||
m_r1World = q1 * m_localAnchorPointBody1;
|
||||
@ -230,14 +230,14 @@ void FixedJoint::solvePositionConstraint(const ConstraintSolverData& constraintS
|
||||
// --------------- Translation Constraints --------------- //
|
||||
|
||||
// Compute the matrix K=JM^-1J^t (3x3 matrix) for the 3 translation constraints
|
||||
float inverseMassBodies = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
float inverseMassBodies = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
Matrix3x3 massMatrix = Matrix3x3(inverseMassBodies, 0, 0,
|
||||
0, inverseMassBodies, 0,
|
||||
0, 0, inverseMassBodies) +
|
||||
skewSymmetricMatrixU1 * m_i1 * skewSymmetricMatrixU1.getTranspose() +
|
||||
skewSymmetricMatrixU2 * m_i2 * skewSymmetricMatrixU2.getTranspose();
|
||||
m_inverseMassMatrixTranslation.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixTranslation = massMatrix.getInverse();
|
||||
}
|
||||
|
||||
@ -277,14 +277,14 @@ void FixedJoint::solvePositionConstraint(const ConstraintSolverData& constraintS
|
||||
// Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation
|
||||
// contraints (3x3 matrix)
|
||||
m_inverseMassMatrixRotation = m_i1 + m_i2;
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixRotation = m_inverseMassMatrixRotation.getInverse();
|
||||
}
|
||||
|
||||
// Compute the position error for the 3 rotation constraints
|
||||
Quaternion currentOrientationDifference = q2 * q1.getInverse();
|
||||
currentOrientationDifference.normalize();
|
||||
const Quaternion qError = currentOrientationDifference * mInitOrientationDifferenceInv;
|
||||
const Quaternion qError = currentOrientationDifference * m_initOrientationDifferenceInv;
|
||||
const Vector3 errorRotation = float(2.0) * qError.getVectorV();
|
||||
|
||||
// Compute the Lagrange multiplier lambda for the 3 rotation constraints
|
||||
|
@ -23,7 +23,7 @@ struct FixedJointInfo : public JointInfo {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Anchor point (in world-space coordinates)
|
||||
Vector3 m_m_m_m_anchorPointWorldSpace;
|
||||
Vector3 m_anchorPointWorldSpace;
|
||||
|
||||
/// Constructor
|
||||
/**
|
||||
@ -35,7 +35,7 @@ struct FixedJointInfo : public JointInfo {
|
||||
FixedJointInfo(RigidBody* rigidBody1, RigidBody* rigidBody2,
|
||||
const Vector3& initAnchorPointWorldSpace)
|
||||
: JointInfo(rigidBody1, rigidBody2, FIXEDJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace){}
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace){}
|
||||
};
|
||||
|
||||
// Class FixedJoint
|
||||
@ -85,13 +85,13 @@ class FixedJoint : public Joint {
|
||||
Matrix3x3 m_inverseMassMatrixRotation;
|
||||
|
||||
/// Bias vector for the 3 translation constraints
|
||||
Vector3 mBiasTranslation;
|
||||
Vector3 m_biasTranslation;
|
||||
|
||||
/// Bias vector for the 3 rotation constraints
|
||||
Vector3 mBiasRotation;
|
||||
Vector3 m_biasRotation;
|
||||
|
||||
/// Inverse of the initial orientation difference between the two bodies
|
||||
Quaternion mInitOrientationDifferenceInv;
|
||||
Quaternion m_initOrientationDifferenceInv;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
|
@ -27,10 +27,10 @@ HingeJoint::HingeJoint(const HingeJointInfo& jointInfo)
|
||||
assert(mUpperLimit >= 0 && mUpperLimit <= 2.0 * PI);
|
||||
|
||||
// Compute the local-space anchor point for each body
|
||||
Transform transform1 = mBody1->getTransform();
|
||||
Transform transform2 = mBody2->getTransform();
|
||||
m_localAnchorPointBody1 = transform1.getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = transform2.getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
Transform transform1 = m_body1->getTransform();
|
||||
Transform transform2 = m_body2->getTransform();
|
||||
m_localAnchorPointBody1 = transform1.getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = transform2.getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
|
||||
// Compute the local-space hinge axis
|
||||
mHingeLocalAxisBody1 = transform1.getOrientation().getInverse() * jointInfo.rotationAxisWorld;
|
||||
@ -39,10 +39,10 @@ HingeJoint::HingeJoint(const HingeJointInfo& jointInfo)
|
||||
mHingeLocalAxisBody2.normalize();
|
||||
|
||||
// Compute the inverse of the initial orientation difference between the two bodies
|
||||
mInitOrientationDifferenceInv = transform2.getOrientation() *
|
||||
m_initOrientationDifferenceInv = transform2.getOrientation() *
|
||||
transform1.getOrientation().getInverse();
|
||||
mInitOrientationDifferenceInv.normalize();
|
||||
mInitOrientationDifferenceInv.inverse();
|
||||
m_initOrientationDifferenceInv.normalize();
|
||||
m_initOrientationDifferenceInv.inverse();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -54,18 +54,18 @@ HingeJoint::~HingeJoint() {
|
||||
void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Initialize the bodies index in the velocity array
|
||||
mIndexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody1)->second;
|
||||
mIndexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody2)->second;
|
||||
m_indexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body1)->second;
|
||||
m_indexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body2)->second;
|
||||
|
||||
// Get the bodies positions and orientations
|
||||
const Vector3& x1 = mBody1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = mBody2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = mBody1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = mBody2->getTransform().getOrientation();
|
||||
const Vector3& x1 = m_body1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = m_body2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = m_body1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = m_body2->getTransform().getOrientation();
|
||||
|
||||
// Get the inertia tensor of bodies
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Compute the vector from body center to the anchor point in world-space
|
||||
m_r1World = orientationBody1 * m_localAnchorPointBody1;
|
||||
@ -103,21 +103,21 @@ void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat
|
||||
Matrix3x3 skewSymmetricMatrixU2= Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(m_r2World);
|
||||
|
||||
// Compute the inverse mass matrix K=JM^-1J^t for the 3 translation constraints (3x3 matrix)
|
||||
float inverseMassBodies = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
float inverseMassBodies = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
Matrix3x3 massMatrix = Matrix3x3(inverseMassBodies, 0, 0,
|
||||
0, inverseMassBodies, 0,
|
||||
0, 0, inverseMassBodies) +
|
||||
skewSymmetricMatrixU1 * m_i1 * skewSymmetricMatrixU1.getTranspose() +
|
||||
skewSymmetricMatrixU2 * m_i2 * skewSymmetricMatrixU2.getTranspose();
|
||||
m_inverseMassMatrixTranslation.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixTranslation = massMatrix.getInverse();
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the translation constraints
|
||||
mBTranslation.setToZero();
|
||||
float biasFactor = (BETA / constraintSolverData.timeStep);
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBTranslation = biasFactor * (x2 + m_r2World - x1 - m_r1World);
|
||||
}
|
||||
|
||||
@ -136,13 +136,13 @@ void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat
|
||||
mC2CrossA1.dot(I2C2CrossA1);
|
||||
const Matrix2x2 matrixKRotation(el11, el12, el21, el22);
|
||||
m_inverseMassMatrixRotation.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixRotation = matrixKRotation.getInverse();
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the rotation constraints
|
||||
mBRotation.setToZero();
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBRotation = biasFactor * Vector2(mA1.dot(b2), mA1.dot(c2));
|
||||
}
|
||||
|
||||
@ -169,13 +169,13 @@ void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat
|
||||
|
||||
// Compute the bias "b" of the lower limit constraint
|
||||
mBLowerLimit = 0.0;
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBLowerLimit = biasFactor * lowerLimitError;
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the upper limit constraint
|
||||
mBUpperLimit = 0.0;
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBUpperLimit = biasFactor * upperLimitError;
|
||||
}
|
||||
}
|
||||
@ -186,14 +186,14 @@ void HingeJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDat
|
||||
void HingeJoint::warmstart(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
const float inverseMassBody1 = mBody1->mMassInverse;
|
||||
const float inverseMassBody2 = mBody2->mMassInverse;
|
||||
const float inverseMassBody1 = m_body1->m_massInverse;
|
||||
const float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// Compute the impulse P=J^T * lambda for the 2 rotation constraints
|
||||
Vector3 rotationImpulse = -mB2CrossA1 * m_impulseRotation.x - mC2CrossA1 * m_impulseRotation.y;
|
||||
@ -242,14 +242,14 @@ void HingeJoint::warmstart(const ConstraintSolverData& constraintSolverData) {
|
||||
void HingeJoint::solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
float inverseMassBody1 = mBody1->mMassInverse;
|
||||
float inverseMassBody2 = mBody2->mMassInverse;
|
||||
float inverseMassBody1 = m_body1->m_massInverse;
|
||||
float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// --------------- Translation Constraints --------------- //
|
||||
|
||||
@ -389,21 +389,21 @@ void HingeJoint::solvePositionConstraint(const ConstraintSolverData& constraintS
|
||||
|
||||
// If the error position correction technique is not the non-linear-gauss-seidel, we do
|
||||
// do not execute this method
|
||||
if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
if (m_positionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
|
||||
// Get the bodies positions and orientations
|
||||
Vector3& x1 = constraintSolverData.positions[mIndexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[mIndexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[mIndexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[mIndexBody2];
|
||||
Vector3& x1 = constraintSolverData.positions[m_indexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[m_indexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[m_indexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
float inverseMassBody1 = mBody1->mMassInverse;
|
||||
float inverseMassBody2 = mBody2->mMassInverse;
|
||||
float inverseMassBody1 = m_body1->m_massInverse;
|
||||
float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// Recompute the inverse inertia tensors
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Compute the vector from body center to the anchor point in world-space
|
||||
m_r1World = q1 * m_localAnchorPointBody1;
|
||||
@ -435,14 +435,14 @@ void HingeJoint::solvePositionConstraint(const ConstraintSolverData& constraintS
|
||||
// --------------- Translation Constraints --------------- //
|
||||
|
||||
// Compute the matrix K=JM^-1J^t (3x3 matrix) for the 3 translation constraints
|
||||
float inverseMassBodies = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
float inverseMassBodies = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
Matrix3x3 massMatrix = Matrix3x3(inverseMassBodies, 0, 0,
|
||||
0, inverseMassBodies, 0,
|
||||
0, 0, inverseMassBodies) +
|
||||
skewSymmetricMatrixU1 * m_i1 * skewSymmetricMatrixU1.getTranspose() +
|
||||
skewSymmetricMatrixU2 * m_i2 * skewSymmetricMatrixU2.getTranspose();
|
||||
m_inverseMassMatrixTranslation.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixTranslation = massMatrix.getInverse();
|
||||
}
|
||||
|
||||
@ -494,7 +494,7 @@ void HingeJoint::solvePositionConstraint(const ConstraintSolverData& constraintS
|
||||
mC2CrossA1.dot(I2C2CrossA1);
|
||||
const Matrix2x2 matrixKRotation(el11, el12, el21, el22);
|
||||
m_inverseMassMatrixRotation.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixRotation = matrixKRotation.getInverse();
|
||||
}
|
||||
|
||||
@ -620,8 +620,8 @@ void HingeJoint::enableMotor(bool isMotorEnabled) {
|
||||
m_impulseMotor = 0.0;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
|
||||
// Set the minimum angle limit
|
||||
@ -666,8 +666,8 @@ void HingeJoint::resetLimits() {
|
||||
m_impulseUpperLimit = 0.0;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
|
||||
// Set the motor speed
|
||||
@ -678,8 +678,8 @@ void HingeJoint::setMotorSpeed(float motorSpeed) {
|
||||
mMotorSpeed = motorSpeed;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -695,8 +695,8 @@ void HingeJoint::setMaxMotorTorque(float maxMotorTorque) {
|
||||
mMaxMotorTorque = maxMotorTorque;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -752,7 +752,7 @@ float HingeJoint::computeCurrentHingeAngle(const Quaternion& orientationBody1,
|
||||
currentOrientationDiff.normalize();
|
||||
|
||||
// Compute the relative rotation considering the initial orientation difference
|
||||
Quaternion relativeRotation = currentOrientationDiff * mInitOrientationDifferenceInv;
|
||||
Quaternion relativeRotation = currentOrientationDiff * m_initOrientationDifferenceInv;
|
||||
relativeRotation.normalize();
|
||||
|
||||
// A quaternion q = [cos(theta/2); sin(theta/2) * rotAxis] where rotAxis is a unit
|
||||
|
@ -23,7 +23,7 @@ struct HingeJointInfo : public JointInfo {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Anchor point (in world-space coordinates)
|
||||
Vector3 m_m_m_m_anchorPointWorldSpace;
|
||||
Vector3 m_anchorPointWorldSpace;
|
||||
|
||||
/// Hinge rotation axis (in world-space coordinates)
|
||||
Vector3 rotationAxisWorld;
|
||||
@ -62,7 +62,7 @@ struct HingeJointInfo : public JointInfo {
|
||||
const Vector3& initAnchorPointWorldSpace,
|
||||
const Vector3& initRotationAxisWorld)
|
||||
: JointInfo(rigidBody1, rigidBody2, HINGEJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
rotationAxisWorld(initRotationAxisWorld), isLimitEnabled(false),
|
||||
isMotorEnabled(false), minAngleLimit(-1), maxAngleLimit(1),
|
||||
motorSpeed(0), maxMotorTorque(0) {}
|
||||
@ -81,7 +81,7 @@ struct HingeJointInfo : public JointInfo {
|
||||
const Vector3& initRotationAxisWorld,
|
||||
float initMinAngleLimit, float initMaxAngleLimit)
|
||||
: JointInfo(rigidBody1, rigidBody2, HINGEJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
rotationAxisWorld(initRotationAxisWorld), isLimitEnabled(true),
|
||||
isMotorEnabled(false), minAngleLimit(initMinAngleLimit),
|
||||
maxAngleLimit(initMaxAngleLimit), motorSpeed(0),
|
||||
@ -104,7 +104,7 @@ struct HingeJointInfo : public JointInfo {
|
||||
float initMinAngleLimit, float initMaxAngleLimit,
|
||||
float initMotorSpeed, float initMaxMotorTorque)
|
||||
: JointInfo(rigidBody1, rigidBody2, HINGEJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
rotationAxisWorld(initRotationAxisWorld), isLimitEnabled(true),
|
||||
isMotorEnabled(false), minAngleLimit(initMinAngleLimit),
|
||||
maxAngleLimit(initMaxAngleLimit), motorSpeed(initMotorSpeed),
|
||||
@ -201,7 +201,7 @@ class HingeJoint : public Joint {
|
||||
float mBUpperLimit;
|
||||
|
||||
/// Inverse of the initial orientation difference between the bodies
|
||||
Quaternion mInitOrientationDifferenceInv;
|
||||
Quaternion m_initOrientationDifferenceInv;
|
||||
|
||||
/// True if the joint limits are enabled
|
||||
bool mIsLimitEnabled;
|
||||
|
@ -12,12 +12,12 @@ using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
Joint::Joint(const JointInfo& jointInfo)
|
||||
:mBody1(jointInfo.body1), mBody2(jointInfo.body2), mType(jointInfo.type),
|
||||
mPositionCorrectionTechnique(jointInfo.positionCorrectionTechnique),
|
||||
mIsCollisionEnabled(jointInfo.isCollisionEnabled), m_isAlreadyInIsland(false) {
|
||||
:m_body1(jointInfo.body1), m_body2(jointInfo.body2), m_type(jointInfo.type),
|
||||
m_positionCorrectionTechnique(jointInfo.positionCorrectionTechnique),
|
||||
m_isCollisionEnabled(jointInfo.isCollisionEnabled), m_isAlreadyInIsland(false) {
|
||||
|
||||
assert(mBody1 != NULL);
|
||||
assert(mBody2 != NULL);
|
||||
assert(m_body1 != NULL);
|
||||
assert(m_body2 != NULL);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
@ -100,25 +100,25 @@ class Joint {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Pointer to the first body of the joint
|
||||
RigidBody* const mBody1;
|
||||
RigidBody* const m_body1;
|
||||
|
||||
/// Pointer to the second body of the joint
|
||||
RigidBody* const mBody2;
|
||||
RigidBody* const m_body2;
|
||||
|
||||
/// Type of the joint
|
||||
const JointType mType;
|
||||
const JointType m_type;
|
||||
|
||||
/// Body 1 index in the velocity array to solve the constraint
|
||||
uint32_t mIndexBody1;
|
||||
uint32_t m_indexBody1;
|
||||
|
||||
/// Body 2 index in the velocity array to solve the constraint
|
||||
uint32_t mIndexBody2;
|
||||
uint32_t m_indexBody2;
|
||||
|
||||
/// Position correction technique used for the constraint (used for joints)
|
||||
JointsPositionCorrectionTechnique mPositionCorrectionTechnique;
|
||||
JointsPositionCorrectionTechnique m_positionCorrectionTechnique;
|
||||
|
||||
/// True if the two bodies of the constraint are allowed to collide with each other
|
||||
bool mIsCollisionEnabled;
|
||||
bool m_isCollisionEnabled;
|
||||
|
||||
/// True if the joint has already been added int32_to an island
|
||||
bool m_isAlreadyInIsland;
|
||||
@ -186,7 +186,7 @@ class Joint {
|
||||
* @return The first body involved in the joint
|
||||
*/
|
||||
inline RigidBody* Joint::getBody1() const {
|
||||
return mBody1;
|
||||
return m_body1;
|
||||
}
|
||||
|
||||
// Return the reference to the body 2
|
||||
@ -194,7 +194,7 @@ inline RigidBody* Joint::getBody1() const {
|
||||
* @return The second body involved in the joint
|
||||
*/
|
||||
inline RigidBody* Joint::getBody2() const {
|
||||
return mBody2;
|
||||
return m_body2;
|
||||
}
|
||||
|
||||
// Return true if the joint is active
|
||||
@ -202,7 +202,7 @@ inline RigidBody* Joint::getBody2() const {
|
||||
* @return True if the joint is active
|
||||
*/
|
||||
inline bool Joint::isActive() const {
|
||||
return (mBody1->isActive() && mBody2->isActive());
|
||||
return (m_body1->isActive() && m_body2->isActive());
|
||||
}
|
||||
|
||||
// Return the type of the joint
|
||||
@ -210,7 +210,7 @@ inline bool Joint::isActive() const {
|
||||
* @return The type of the joint
|
||||
*/
|
||||
inline JointType Joint::getType() const {
|
||||
return mType;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
// Return true if the collision between the two bodies of the joint is enabled
|
||||
@ -219,7 +219,7 @@ inline JointType Joint::getType() const {
|
||||
* is enabled and false otherwise
|
||||
*/
|
||||
inline bool Joint::isCollisionEnabled() const {
|
||||
return mIsCollisionEnabled;
|
||||
return m_isCollisionEnabled;
|
||||
}
|
||||
|
||||
// Return true if the joint has already been added int32_to an island
|
||||
|
@ -27,19 +27,19 @@ SliderJoint::SliderJoint(const SliderJointInfo& jointInfo)
|
||||
assert(mMaxMotorForce >= 0.0);
|
||||
|
||||
// Compute the local-space anchor point for each body
|
||||
const Transform& transform1 = mBody1->getTransform();
|
||||
const Transform& transform2 = mBody2->getTransform();
|
||||
m_localAnchorPointBody1 = transform1.getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = transform2.getInverse() * jointInfo.m_m_m_m_anchorPointWorldSpace;
|
||||
const Transform& transform1 = m_body1->getTransform();
|
||||
const Transform& transform2 = m_body2->getTransform();
|
||||
m_localAnchorPointBody1 = transform1.getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
m_localAnchorPointBody2 = transform2.getInverse() * jointInfo.m_anchorPointWorldSpace;
|
||||
|
||||
// Compute the inverse of the initial orientation difference between the two bodies
|
||||
mInitOrientationDifferenceInv = transform2.getOrientation() *
|
||||
m_initOrientationDifferenceInv = transform2.getOrientation() *
|
||||
transform1.getOrientation().getInverse();
|
||||
mInitOrientationDifferenceInv.normalize();
|
||||
mInitOrientationDifferenceInv.inverse();
|
||||
m_initOrientationDifferenceInv.normalize();
|
||||
m_initOrientationDifferenceInv.inverse();
|
||||
|
||||
// Compute the slider axis in local-space of body 1
|
||||
mSliderAxisBody1 = mBody1->getTransform().getOrientation().getInverse() *
|
||||
mSliderAxisBody1 = m_body1->getTransform().getOrientation().getInverse() *
|
||||
jointInfo.sliderAxisWorldSpace;
|
||||
mSliderAxisBody1.normalize();
|
||||
}
|
||||
@ -53,18 +53,18 @@ SliderJoint::~SliderJoint() {
|
||||
void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Initialize the bodies index in the veloc ity array
|
||||
mIndexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody1)->second;
|
||||
mIndexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(mBody2)->second;
|
||||
m_indexBody1 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body1)->second;
|
||||
m_indexBody2 = constraintSolverData.mapBodyToConstrainedVelocityIndex.find(m_body2)->second;
|
||||
|
||||
// Get the bodies positions and orientations
|
||||
const Vector3& x1 = mBody1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = mBody2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = mBody1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = mBody2->getTransform().getOrientation();
|
||||
const Vector3& x1 = m_body1->mCenterOfMassWorld;
|
||||
const Vector3& x2 = m_body2->mCenterOfMassWorld;
|
||||
const Quaternion& orientationBody1 = m_body1->getTransform().getOrientation();
|
||||
const Quaternion& orientationBody2 = m_body2->getTransform().getOrientation();
|
||||
|
||||
// Get the inertia tensor of bodies
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Vector from body center to the anchor point
|
||||
mR1 = orientationBody1 * m_localAnchorPointBody1;
|
||||
@ -105,7 +105,7 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa
|
||||
|
||||
// Compute the inverse of the mass matrix K=JM^-1J^t for the 2 translation
|
||||
// constraints (2x2 matrix)
|
||||
float sumInverseMass = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
float sumInverseMass = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
Vector3 I1R1PlusUCrossN1 = m_i1 * mR1PlusUCrossN1;
|
||||
Vector3 I1R1PlusUCrossN2 = m_i1 * mR1PlusUCrossN2;
|
||||
Vector3 I2R2CrossN1 = m_i2 * mR2CrossN1;
|
||||
@ -120,14 +120,14 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa
|
||||
mR2CrossN2.dot(I2R2CrossN2);
|
||||
Matrix2x2 matrixKTranslation(el11, el12, el21, el22);
|
||||
m_inverseMassMatrixTranslationConstraint.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixTranslationConstraint = matrixKTranslation.getInverse();
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the translation constraint
|
||||
mBTranslation.setToZero();
|
||||
float biasFactor = (BETA / constraintSolverData.timeStep);
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBTranslation.x = u.dot(mN1);
|
||||
mBTranslation.y = u.dot(mN2);
|
||||
mBTranslation *= biasFactor;
|
||||
@ -136,16 +136,16 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa
|
||||
// Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation
|
||||
// contraints (3x3 matrix)
|
||||
m_inverseMassMatrixRotationConstraint = m_i1 + m_i2;
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixRotationConstraint = m_inverseMassMatrixRotationConstraint.getInverse();
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the rotation constraint
|
||||
mBRotation.setToZero();
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
Quaternion currentOrientationDifference = orientationBody2 * orientationBody1.getInverse();
|
||||
currentOrientationDifference.normalize();
|
||||
const Quaternion qError = currentOrientationDifference * mInitOrientationDifferenceInv;
|
||||
const Quaternion qError = currentOrientationDifference * m_initOrientationDifferenceInv;
|
||||
mBRotation = biasFactor * float(2.0) * qError.getVectorV();
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa
|
||||
if (mIsLimitEnabled && (mIsLowerLimitViolated || mIsUpperLimitViolated)) {
|
||||
|
||||
// Compute the inverse of the mass matrix K=JM^-1J^t for the limits (1x1 matrix)
|
||||
m_inverseMassMatrixLimit = mBody1->mMassInverse + mBody2->mMassInverse +
|
||||
m_inverseMassMatrixLimit = m_body1->m_massInverse + m_body2->m_massInverse +
|
||||
mR1PlusUCrossSliderAxis.dot(m_i1 * mR1PlusUCrossSliderAxis) +
|
||||
mR2CrossSliderAxis.dot(m_i2 * mR2CrossSliderAxis);
|
||||
m_inverseMassMatrixLimit = (m_inverseMassMatrixLimit > 0.0) ?
|
||||
@ -161,13 +161,13 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa
|
||||
|
||||
// Compute the bias "b" of the lower limit constraint
|
||||
mBLowerLimit = 0.0;
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBLowerLimit = biasFactor * lowerLimitError;
|
||||
}
|
||||
|
||||
// Compute the bias "b" of the upper limit constraint
|
||||
mBUpperLimit = 0.0;
|
||||
if (mPositionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
if (m_positionCorrectionTechnique == BAUMGARTE_JOINTS) {
|
||||
mBUpperLimit = biasFactor * upperLimitError;
|
||||
}
|
||||
}
|
||||
@ -176,7 +176,7 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa
|
||||
if (mIsMotorEnabled) {
|
||||
|
||||
// Compute the inverse of mass matrix K=JM^-1J^t for the motor (1x1 matrix)
|
||||
m_inverseMassMatrixMotor = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
m_inverseMassMatrixMotor = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
m_inverseMassMatrixMotor = (m_inverseMassMatrixMotor > 0.0) ?
|
||||
float(1.0) / m_inverseMassMatrixMotor : float(0.0);
|
||||
}
|
||||
@ -197,14 +197,14 @@ void SliderJoint::initBeforeSolve(const ConstraintSolverData& constraintSolverDa
|
||||
void SliderJoint::warmstart(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
const float inverseMassBody1 = mBody1->mMassInverse;
|
||||
const float inverseMassBody2 = mBody2->mMassInverse;
|
||||
const float inverseMassBody1 = m_body1->m_massInverse;
|
||||
const float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// Compute the impulse P=J^T * lambda for the lower and upper limits constraints of body 1
|
||||
float impulseLimits = m_impulseUpperLimit - m_impulseLowerLimit;
|
||||
@ -256,14 +256,14 @@ void SliderJoint::warmstart(const ConstraintSolverData& constraintSolverData) {
|
||||
void SliderJoint::solveVelocityConstraint(const ConstraintSolverData& constraintSolverData) {
|
||||
|
||||
// Get the velocities
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[mIndexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[mIndexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[mIndexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[mIndexBody2];
|
||||
Vector3& v1 = constraintSolverData.linearVelocities[m_indexBody1];
|
||||
Vector3& v2 = constraintSolverData.linearVelocities[m_indexBody2];
|
||||
Vector3& w1 = constraintSolverData.angularVelocities[m_indexBody1];
|
||||
Vector3& w2 = constraintSolverData.angularVelocities[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
float inverseMassBody1 = mBody1->mMassInverse;
|
||||
float inverseMassBody2 = mBody2->mMassInverse;
|
||||
float inverseMassBody1 = m_body1->m_massInverse;
|
||||
float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// --------------- Translation Constraints --------------- //
|
||||
|
||||
@ -414,21 +414,21 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint
|
||||
|
||||
// If the error position correction technique is not the non-linear-gauss-seidel, we do
|
||||
// do not execute this method
|
||||
if (mPositionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
if (m_positionCorrectionTechnique != NON_LINEAR_GAUSS_SEIDEL) return;
|
||||
|
||||
// Get the bodies positions and orientations
|
||||
Vector3& x1 = constraintSolverData.positions[mIndexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[mIndexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[mIndexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[mIndexBody2];
|
||||
Vector3& x1 = constraintSolverData.positions[m_indexBody1];
|
||||
Vector3& x2 = constraintSolverData.positions[m_indexBody2];
|
||||
Quaternion& q1 = constraintSolverData.orientations[m_indexBody1];
|
||||
Quaternion& q2 = constraintSolverData.orientations[m_indexBody2];
|
||||
|
||||
// Get the inverse mass and inverse inertia tensors of the bodies
|
||||
float inverseMassBody1 = mBody1->mMassInverse;
|
||||
float inverseMassBody2 = mBody2->mMassInverse;
|
||||
float inverseMassBody1 = m_body1->m_massInverse;
|
||||
float inverseMassBody2 = m_body2->m_massInverse;
|
||||
|
||||
// Recompute the inertia tensor of bodies
|
||||
m_i1 = mBody1->getInertiaTensorInverseWorld();
|
||||
m_i2 = mBody2->getInertiaTensorInverseWorld();
|
||||
m_i1 = m_body1->getInertiaTensorInverseWorld();
|
||||
m_i2 = m_body2->getInertiaTensorInverseWorld();
|
||||
|
||||
// Vector from body center to the anchor point
|
||||
mR1 = q1 * m_localAnchorPointBody1;
|
||||
@ -463,7 +463,7 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint
|
||||
|
||||
// Recompute the inverse of the mass matrix K=JM^-1J^t for the 2 translation
|
||||
// constraints (2x2 matrix)
|
||||
float sumInverseMass = mBody1->mMassInverse + mBody2->mMassInverse;
|
||||
float sumInverseMass = m_body1->m_massInverse + m_body2->m_massInverse;
|
||||
Vector3 I1R1PlusUCrossN1 = m_i1 * mR1PlusUCrossN1;
|
||||
Vector3 I1R1PlusUCrossN2 = m_i1 * mR1PlusUCrossN2;
|
||||
Vector3 I2R2CrossN1 = m_i2 * mR2CrossN1;
|
||||
@ -478,7 +478,7 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint
|
||||
mR2CrossN2.dot(I2R2CrossN2);
|
||||
Matrix2x2 matrixKTranslation(el11, el12, el21, el22);
|
||||
m_inverseMassMatrixTranslationConstraint.setToZero();
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixTranslationConstraint = matrixKTranslation.getInverse();
|
||||
}
|
||||
|
||||
@ -521,14 +521,14 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint
|
||||
// Compute the inverse of the mass matrix K=JM^-1J^t for the 3 rotation
|
||||
// contraints (3x3 matrix)
|
||||
m_inverseMassMatrixRotationConstraint = m_i1 + m_i2;
|
||||
if (mBody1->getType() == DYNAMIC || mBody2->getType() == DYNAMIC) {
|
||||
if (m_body1->getType() == DYNAMIC || m_body2->getType() == DYNAMIC) {
|
||||
m_inverseMassMatrixRotationConstraint = m_inverseMassMatrixRotationConstraint.getInverse();
|
||||
}
|
||||
|
||||
// Compute the position error for the 3 rotation constraints
|
||||
Quaternion currentOrientationDifference = q2 * q1.getInverse();
|
||||
currentOrientationDifference.normalize();
|
||||
const Quaternion qError = currentOrientationDifference * mInitOrientationDifferenceInv;
|
||||
const Quaternion qError = currentOrientationDifference * m_initOrientationDifferenceInv;
|
||||
const Vector3 errorRotation = float(2.0) * qError.getVectorV();
|
||||
|
||||
// Compute the Lagrange multiplier lambda for the 3 rotation constraints
|
||||
@ -561,7 +561,7 @@ void SliderJoint::solvePositionConstraint(const ConstraintSolverData& constraint
|
||||
if (mIsLowerLimitViolated || mIsUpperLimitViolated) {
|
||||
|
||||
// Compute the inverse of the mass matrix K=JM^-1J^t for the limits (1x1 matrix)
|
||||
m_inverseMassMatrixLimit = mBody1->mMassInverse + mBody2->mMassInverse +
|
||||
m_inverseMassMatrixLimit = m_body1->m_massInverse + m_body2->m_massInverse +
|
||||
mR1PlusUCrossSliderAxis.dot(m_i1 * mR1PlusUCrossSliderAxis) +
|
||||
mR2CrossSliderAxis.dot(m_i2 * mR2CrossSliderAxis);
|
||||
m_inverseMassMatrixLimit = (m_inverseMassMatrixLimit > 0.0) ?
|
||||
@ -663,8 +663,8 @@ void SliderJoint::enableMotor(bool isMotorEnabled) {
|
||||
m_impulseMotor = 0.0;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
|
||||
// Return the current translation value of the joint
|
||||
@ -676,10 +676,10 @@ float SliderJoint::getTranslation() const {
|
||||
// TODO : Check if we need to compare rigid body position or center of mass here
|
||||
|
||||
// Get the bodies positions and orientations
|
||||
const Vector3& x1 = mBody1->getTransform().getPosition();
|
||||
const Vector3& x2 = mBody2->getTransform().getPosition();
|
||||
const Quaternion& q1 = mBody1->getTransform().getOrientation();
|
||||
const Quaternion& q2 = mBody2->getTransform().getOrientation();
|
||||
const Vector3& x1 = m_body1->getTransform().getPosition();
|
||||
const Vector3& x2 = m_body2->getTransform().getPosition();
|
||||
const Quaternion& q1 = m_body1->getTransform().getOrientation();
|
||||
const Quaternion& q2 = m_body2->getTransform().getOrientation();
|
||||
|
||||
// Compute the two anchor points in world-space coordinates
|
||||
const Vector3 anchorBody1 = x1 + q1 * m_localAnchorPointBody1;
|
||||
@ -738,8 +738,8 @@ void SliderJoint::resetLimits() {
|
||||
m_impulseUpperLimit = 0.0;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
|
||||
// Set the motor speed
|
||||
@ -753,8 +753,8 @@ void SliderJoint::setMotorSpeed(float motorSpeed) {
|
||||
mMotorSpeed = motorSpeed;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -770,7 +770,7 @@ void SliderJoint::setMaxMotorForce(float maxMotorForce) {
|
||||
mMaxMotorForce = maxMotorForce;
|
||||
|
||||
// Wake up the two bodies of the joint
|
||||
mBody1->setIsSleeping(false);
|
||||
mBody2->setIsSleeping(false);
|
||||
m_body1->setIsSleeping(false);
|
||||
m_body2->setIsSleeping(false);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ struct SliderJointInfo : public JointInfo {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Anchor point (in world-space coordinates)
|
||||
Vector3 m_m_m_m_anchorPointWorldSpace;
|
||||
Vector3 m_anchorPointWorldSpace;
|
||||
|
||||
/// Slider axis (in world-space coordinates)
|
||||
Vector3 sliderAxisWorldSpace;
|
||||
@ -57,7 +57,7 @@ struct SliderJointInfo : public JointInfo {
|
||||
const Vector3& initAnchorPointWorldSpace,
|
||||
const Vector3& initSliderAxisWorldSpace)
|
||||
: JointInfo(rigidBody1, rigidBody2, SLIDERJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
sliderAxisWorldSpace(initSliderAxisWorldSpace),
|
||||
isLimitEnabled(false), isMotorEnabled(false), minTranslationLimit(-1.0),
|
||||
maxTranslationLimit(1.0), motorSpeed(0), maxMotorForce(0) {}
|
||||
@ -76,7 +76,7 @@ struct SliderJointInfo : public JointInfo {
|
||||
const Vector3& initSliderAxisWorldSpace,
|
||||
float initMinTranslationLimit, float initMaxTranslationLimit)
|
||||
: JointInfo(rigidBody1, rigidBody2, SLIDERJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
sliderAxisWorldSpace(initSliderAxisWorldSpace),
|
||||
isLimitEnabled(true), isMotorEnabled(false),
|
||||
minTranslationLimit(initMinTranslationLimit),
|
||||
@ -100,7 +100,7 @@ struct SliderJointInfo : public JointInfo {
|
||||
float initMinTranslationLimit, float initMaxTranslationLimit,
|
||||
float initMotorSpeed, float initMaxMotorForce)
|
||||
: JointInfo(rigidBody1, rigidBody2, SLIDERJOINT),
|
||||
m_m_m_m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
m_anchorPointWorldSpace(initAnchorPointWorldSpace),
|
||||
sliderAxisWorldSpace(initSliderAxisWorldSpace),
|
||||
isLimitEnabled(true), isMotorEnabled(true),
|
||||
minTranslationLimit(initMinTranslationLimit),
|
||||
@ -141,7 +141,7 @@ class SliderJoint : public Joint {
|
||||
Matrix3x3 m_i2;
|
||||
|
||||
/// Inverse of the initial orientation difference between the two bodies
|
||||
Quaternion mInitOrientationDifferenceInv;
|
||||
Quaternion m_initOrientationDifferenceInv;
|
||||
|
||||
/// First vector orthogonal to the slider axis local-space of body 1
|
||||
Vector3 mN1;
|
||||
|
@ -14,8 +14,8 @@ using namespace std;
|
||||
|
||||
// Constructor
|
||||
CollisionWorld::CollisionWorld()
|
||||
: m_collisionDetection(this, mMemoryAllocator), mCurrentBodyID(0),
|
||||
mEventListener(NULL) {
|
||||
: m_collisionDetection(this, m_memoryAllocator), m_currentBodyID(0),
|
||||
m_eventListener(NULL) {
|
||||
|
||||
}
|
||||
|
||||
@ -24,13 +24,13 @@ CollisionWorld::~CollisionWorld() {
|
||||
|
||||
// Destroy all the collision bodies that have not been removed
|
||||
std::set<CollisionBody*>::iterator itBodies;
|
||||
for (itBodies = mBodies.begin(); itBodies != mBodies.end(); ) {
|
||||
for (itBodies = m_bodies.begin(); itBodies != m_bodies.end(); ) {
|
||||
std::set<CollisionBody*>::iterator itToRemove = itBodies;
|
||||
++itBodies;
|
||||
destroyCollisionBody(*itToRemove);
|
||||
}
|
||||
|
||||
assert(mBodies.empty());
|
||||
assert(m_bodies.empty());
|
||||
}
|
||||
|
||||
// Create a collision body and add it to the world
|
||||
@ -47,13 +47,13 @@ CollisionBody* CollisionWorld::createCollisionBody(const Transform& transform) {
|
||||
assert(bodyID < std::numeric_limits<reactphysics3d::bodyindex>::max());
|
||||
|
||||
// Create the collision body
|
||||
CollisionBody* collisionBody = new (mMemoryAllocator.allocate(sizeof(CollisionBody)))
|
||||
CollisionBody* collisionBody = new (m_memoryAllocator.allocate(sizeof(CollisionBody)))
|
||||
CollisionBody(transform, *this, bodyID);
|
||||
|
||||
assert(collisionBody != NULL);
|
||||
|
||||
// Add the collision body to the world
|
||||
mBodies.insert(collisionBody);
|
||||
m_bodies.insert(collisionBody);
|
||||
|
||||
// Return the pointer to the rigid body
|
||||
return collisionBody;
|
||||
@ -69,16 +69,16 @@ void CollisionWorld::destroyCollisionBody(CollisionBody* collisionBody) {
|
||||
collisionBody->removeAllCollisionShapes();
|
||||
|
||||
// Add the body ID to the list of free IDs
|
||||
mFreeBodiesIDs.push_back(collisionBody->getID());
|
||||
m_freeBodiesIDs.push_back(collisionBody->getID());
|
||||
|
||||
// Call the destructor of the collision body
|
||||
collisionBody->~CollisionBody();
|
||||
|
||||
// Remove the collision body from the list of bodies
|
||||
mBodies.erase(collisionBody);
|
||||
m_bodies.erase(collisionBody);
|
||||
|
||||
// Free the object from the memory allocator
|
||||
mMemoryAllocator.release(collisionBody, sizeof(CollisionBody));
|
||||
m_memoryAllocator.release(collisionBody, sizeof(CollisionBody));
|
||||
}
|
||||
|
||||
// Return the next available body ID
|
||||
@ -86,13 +86,13 @@ bodyindex CollisionWorld::computeNextAvailableBodyID() {
|
||||
|
||||
// Compute the body ID
|
||||
bodyindex bodyID;
|
||||
if (!mFreeBodiesIDs.empty()) {
|
||||
bodyID = mFreeBodiesIDs.back();
|
||||
mFreeBodiesIDs.pop_back();
|
||||
if (!m_freeBodiesIDs.empty()) {
|
||||
bodyID = m_freeBodiesIDs.back();
|
||||
m_freeBodiesIDs.pop_back();
|
||||
}
|
||||
else {
|
||||
bodyID = mCurrentBodyID;
|
||||
mCurrentBodyID++;
|
||||
bodyID = m_currentBodyID;
|
||||
m_currentBodyID++;
|
||||
}
|
||||
|
||||
return bodyID;
|
||||
@ -102,7 +102,7 @@ bodyindex CollisionWorld::computeNextAvailableBodyID() {
|
||||
void CollisionWorld::resetContactManifoldListsOfBodies() {
|
||||
|
||||
// For each rigid body of the world
|
||||
for (std::set<CollisionBody*>::iterator it = mBodies.begin(); it != mBodies.end(); ++it) {
|
||||
for (std::set<CollisionBody*>::iterator it = m_bodies.begin(); it != m_bodies.end(); ++it) {
|
||||
|
||||
// Reset the contact manifold list of the body
|
||||
(*it)->resetContactManifoldsList();
|
||||
@ -143,7 +143,7 @@ void CollisionWorld::testCollision(const ProxyShape* shape,
|
||||
|
||||
// Create the sets of shapes
|
||||
std::set<uint32_t> shapes;
|
||||
shapes.insert(shape->mBroadPhaseID);
|
||||
shapes.insert(shape->m_broadPhaseID);
|
||||
std::set<uint32_t> emptySet;
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
@ -165,9 +165,9 @@ void CollisionWorld::testCollision(const ProxyShape* shape1,
|
||||
|
||||
// Create the sets of shapes
|
||||
std::set<uint32_t> shapes1;
|
||||
shapes1.insert(shape1->mBroadPhaseID);
|
||||
shapes1.insert(shape1->m_broadPhaseID);
|
||||
std::set<uint32_t> shapes2;
|
||||
shapes2.insert(shape2->mBroadPhaseID);
|
||||
shapes2.insert(shape2->m_broadPhaseID);
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
m_collisionDetection.testCollisionBetweenShapes(callback, shapes1, shapes2);
|
||||
@ -191,7 +191,7 @@ void CollisionWorld::testCollision(const CollisionBody* body,
|
||||
// For each shape of the body
|
||||
for (const ProxyShape* shape=body->getProxyShapesList(); shape != NULL;
|
||||
shape = shape->getNext()) {
|
||||
shapes1.insert(shape->mBroadPhaseID);
|
||||
shapes1.insert(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
std::set<uint32_t> emptySet;
|
||||
@ -217,13 +217,13 @@ void CollisionWorld::testCollision(const CollisionBody* body1,
|
||||
std::set<uint32_t> shapes1;
|
||||
for (const ProxyShape* shape=body1->getProxyShapesList(); shape != NULL;
|
||||
shape = shape->getNext()) {
|
||||
shapes1.insert(shape->mBroadPhaseID);
|
||||
shapes1.insert(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
std::set<uint32_t> shapes2;
|
||||
for (const ProxyShape* shape=body2->getProxyShapesList(); shape != NULL;
|
||||
shape = shape->getNext()) {
|
||||
shapes2.insert(shape->mBroadPhaseID);
|
||||
shapes2.insert(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
|
@ -43,19 +43,19 @@ class CollisionWorld {
|
||||
CollisionDetection m_collisionDetection;
|
||||
|
||||
/// All the bodies (rigid and soft) of the world
|
||||
std::set<CollisionBody*> mBodies;
|
||||
std::set<CollisionBody*> m_bodies;
|
||||
|
||||
/// Current body ID
|
||||
bodyindex mCurrentBodyID;
|
||||
bodyindex m_currentBodyID;
|
||||
|
||||
/// List of free ID for rigid bodies
|
||||
std::vector<uint64_t> mFreeBodiesIDs;
|
||||
std::vector<uint64_t> m_freeBodiesIDs;
|
||||
|
||||
/// Memory allocator
|
||||
MemoryAllocator mMemoryAllocator;
|
||||
MemoryAllocator m_memoryAllocator;
|
||||
|
||||
/// Pointer to an event listener object
|
||||
EventListener* mEventListener;
|
||||
EventListener* m_eventListener;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -144,7 +144,7 @@ class CollisionWorld {
|
||||
* @return An starting iterator to the set of bodies of the world
|
||||
*/
|
||||
inline std::set<CollisionBody*>::iterator CollisionWorld::getBodiesBeginIterator() {
|
||||
return mBodies.begin();
|
||||
return m_bodies.begin();
|
||||
}
|
||||
|
||||
// Return an iterator to the end of the bodies of the physics world
|
||||
@ -152,7 +152,7 @@ inline std::set<CollisionBody*>::iterator CollisionWorld::getBodiesBeginIterator
|
||||
* @return An ending iterator to the set of bodies of the world
|
||||
*/
|
||||
inline std::set<CollisionBody*>::iterator CollisionWorld::getBodiesEndIterator() {
|
||||
return mBodies.end();
|
||||
return m_bodies.end();
|
||||
}
|
||||
|
||||
// Set the collision dispatch configuration
|
||||
|
@ -12,8 +12,8 @@ using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
ConstraintSolver::ConstraintSolver(const std::map<RigidBody*, uint32_t>& mapBodyToVelocityIndex)
|
||||
: mMapBodyToConstrainedVelocityIndex(mapBodyToVelocityIndex),
|
||||
mIsWarmStartingActive(true), mConstraintSolverData(mapBodyToVelocityIndex) {
|
||||
: m_mapBodyToConstrainedVelocityIndex(mapBodyToVelocityIndex),
|
||||
mIsWarmStartingActive(true), m_constraintSolverData(mapBodyToVelocityIndex) {
|
||||
|
||||
}
|
||||
|
||||
@ -32,22 +32,22 @@ void ConstraintSolver::initializeForIsland(float dt, Island* island) {
|
||||
assert(island->getNbJoints() > 0);
|
||||
|
||||
// Set the current time step
|
||||
mTimeStep = dt;
|
||||
m_timeStep = dt;
|
||||
|
||||
// Initialize the constraint solver data used to initialize and solve the constraints
|
||||
mConstraintSolverData.timeStep = mTimeStep;
|
||||
mConstraintSolverData.isWarmStartingActive = mIsWarmStartingActive;
|
||||
m_constraintSolverData.timeStep = m_timeStep;
|
||||
m_constraintSolverData.isWarmStartingActive = mIsWarmStartingActive;
|
||||
|
||||
// For each joint of the island
|
||||
Joint** joints = island->getJoints();
|
||||
for (uint32_t i=0; i<island->getNbJoints(); i++) {
|
||||
|
||||
// Initialize the constraint before solving it
|
||||
joints[i]->initBeforeSolve(mConstraintSolverData);
|
||||
joints[i]->initBeforeSolve(m_constraintSolverData);
|
||||
|
||||
// Warm-start the constraint if warm-starting is enabled
|
||||
if (mIsWarmStartingActive) {
|
||||
joints[i]->warmstart(mConstraintSolverData);
|
||||
joints[i]->warmstart(m_constraintSolverData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,7 @@ void ConstraintSolver::solveVelocityConstraints(Island* island) {
|
||||
for (uint32_t i=0; i<island->getNbJoints(); i++) {
|
||||
|
||||
// Solve the constraint
|
||||
joints[i]->solveVelocityConstraint(mConstraintSolverData);
|
||||
joints[i]->solveVelocityConstraint(m_constraintSolverData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +82,6 @@ void ConstraintSolver::solvePositionConstraints(Island* island) {
|
||||
for (uint32_t i=0; i < island->getNbJoints(); i++) {
|
||||
|
||||
// Solve the constraint
|
||||
joints[i]->solvePositionConstraint(mConstraintSolverData);
|
||||
joints[i]->solvePositionConstraint(m_constraintSolverData);
|
||||
}
|
||||
}
|
||||
|
@ -133,16 +133,16 @@ class ConstraintSolver {
|
||||
|
||||
/// Reference to the map that associates rigid body to their index in
|
||||
/// the constrained velocities array
|
||||
const std::map<RigidBody*, uint32_t>& mMapBodyToConstrainedVelocityIndex;
|
||||
const std::map<RigidBody*, uint32_t>& m_mapBodyToConstrainedVelocityIndex;
|
||||
|
||||
/// Current time step
|
||||
float mTimeStep;
|
||||
float m_timeStep;
|
||||
|
||||
/// True if the warm starting of the solver is active
|
||||
bool mIsWarmStartingActive;
|
||||
|
||||
/// Constraint solver data used to initialize and solve the constraints
|
||||
ConstraintSolverData mConstraintSolverData;
|
||||
ConstraintSolverData m_constraintSolverData;
|
||||
|
||||
public :
|
||||
|
||||
@ -183,8 +183,8 @@ inline void ConstraintSolver::setConstrainedVelocitiesArrays(Vector3* constraine
|
||||
Vector3* constrainedAngularVelocities) {
|
||||
assert(constrainedLinearVelocities != NULL);
|
||||
assert(constrainedAngularVelocities != NULL);
|
||||
mConstraintSolverData.linearVelocities = constrainedLinearVelocities;
|
||||
mConstraintSolverData.angularVelocities = constrainedAngularVelocities;
|
||||
m_constraintSolverData.linearVelocities = constrainedLinearVelocities;
|
||||
m_constraintSolverData.angularVelocities = constrainedAngularVelocities;
|
||||
}
|
||||
|
||||
// Set the constrained positions/orientations arrays
|
||||
@ -192,8 +192,8 @@ inline void ConstraintSolver::setConstrainedPositionsArrays(Vector3* constrained
|
||||
Quaternion* constrainedOrientations) {
|
||||
assert(constrainedPositions != NULL);
|
||||
assert(constrainedOrientations != NULL);
|
||||
mConstraintSolverData.positions = constrainedPositions;
|
||||
mConstraintSolverData.orientations = constrainedOrientations;
|
||||
m_constraintSolverData.positions = constrainedPositions;
|
||||
m_constraintSolverData.orientations = constrainedOrientations;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ const float ContactSolver::SLOP= float(0.01);
|
||||
|
||||
// Constructor
|
||||
ContactSolver::ContactSolver(const std::map<RigidBody*, uint32_t>& mapBodyToVelocityIndex)
|
||||
:mSplitLinearVelocities(NULL), mSplitAngularVelocities(NULL),
|
||||
:m_splitLinearVelocities(NULL), m_splitAngularVelocities(NULL),
|
||||
mContactConstraints(NULL), mLinearVelocities(NULL), mAngularVelocities(NULL),
|
||||
mMapBodyToConstrainedVelocityIndex(mapBodyToVelocityIndex),
|
||||
m_mapBodyToConstrainedVelocityIndex(mapBodyToVelocityIndex),
|
||||
mIsWarmStartingActive(true), mIsSplitImpulseActive(true),
|
||||
mIsSolveFrictionAtContactManifoldCenterActive(true) {
|
||||
|
||||
@ -42,20 +42,20 @@ void ContactSolver::initializeForIsland(float dt, Island* island) {
|
||||
assert(island != NULL);
|
||||
assert(island->getNbBodies() > 0);
|
||||
assert(island->getNbContactManifolds() > 0);
|
||||
assert(mSplitLinearVelocities != NULL);
|
||||
assert(mSplitAngularVelocities != NULL);
|
||||
assert(m_splitLinearVelocities != NULL);
|
||||
assert(m_splitAngularVelocities != NULL);
|
||||
|
||||
// Set the current time step
|
||||
mTimeStep = dt;
|
||||
m_timeStep = dt;
|
||||
|
||||
mNbContactManifolds = island->getNbContactManifolds();
|
||||
m_numberContactManifolds = island->getNbContactManifolds();
|
||||
|
||||
mContactConstraints = new ContactManifoldSolver[mNbContactManifolds];
|
||||
mContactConstraints = new ContactManifoldSolver[m_numberContactManifolds];
|
||||
assert(mContactConstraints != NULL);
|
||||
|
||||
// For each contact manifold of the island
|
||||
ContactManifold** contactManifolds = island->getContactManifold();
|
||||
for (uint32_t i=0; i<mNbContactManifolds; i++) {
|
||||
for (uint32_t i=0; i<m_numberContactManifolds; i++) {
|
||||
|
||||
ContactManifold* externalManifold = contactManifolds[i];
|
||||
|
||||
@ -75,12 +75,12 @@ void ContactSolver::initializeForIsland(float dt, Island* island) {
|
||||
|
||||
// Initialize the int32_ternal contact manifold structure using the external
|
||||
// contact manifold
|
||||
int32_ternalManifold.indexBody1 = mMapBodyToConstrainedVelocityIndex.find(body1)->second;
|
||||
int32_ternalManifold.indexBody2 = mMapBodyToConstrainedVelocityIndex.find(body2)->second;
|
||||
int32_ternalManifold.indexBody1 = m_mapBodyToConstrainedVelocityIndex.find(body1)->second;
|
||||
int32_ternalManifold.indexBody2 = m_mapBodyToConstrainedVelocityIndex.find(body2)->second;
|
||||
int32_ternalManifold.inverseInertiaTensorBody1 = body1->getInertiaTensorInverseWorld();
|
||||
int32_ternalManifold.inverseInertiaTensorBody2 = body2->getInertiaTensorInverseWorld();
|
||||
int32_ternalManifold.massInverseBody1 = body1->mMassInverse;
|
||||
int32_ternalManifold.massInverseBody2 = body2->mMassInverse;
|
||||
int32_ternalManifold.massInverseBody1 = body1->m_massInverse;
|
||||
int32_ternalManifold.massInverseBody2 = body2->m_massInverse;
|
||||
int32_ternalManifold.nbContacts = externalManifold->getNbContactPoints();
|
||||
int32_ternalManifold.restitutionFactor = computeMixedRestitutionFactor(body1, body2);
|
||||
int32_ternalManifold.frictionCoefficient = computeMixedFrictionCoefficient(body1, body2);
|
||||
@ -165,7 +165,7 @@ void ContactSolver::initializeForIsland(float dt, Island* island) {
|
||||
void ContactSolver::initializeContactConstraints() {
|
||||
|
||||
// For each contact constraint
|
||||
for (uint32_t c=0; c<mNbContactManifolds; c++) {
|
||||
for (uint32_t c=0; c<m_numberContactManifolds; c++) {
|
||||
|
||||
ContactManifoldSolver& manifold = mContactConstraints[c];
|
||||
|
||||
@ -323,7 +323,7 @@ void ContactSolver::warmStart() {
|
||||
if (!mIsWarmStartingActive) return;
|
||||
|
||||
// For each constraint
|
||||
for (uint32_t c=0; c<mNbContactManifolds; c++) {
|
||||
for (uint32_t c=0; c<m_numberContactManifolds; c++) {
|
||||
|
||||
ContactManifoldSolver& contactManifold = mContactConstraints[c];
|
||||
|
||||
@ -495,7 +495,7 @@ void ContactSolver::solve() {
|
||||
float lambdaTemp;
|
||||
|
||||
// For each contact manifold
|
||||
for (uint32_t c=0; c<mNbContactManifolds; c++) {
|
||||
for (uint32_t c=0; c<m_numberContactManifolds; c++) {
|
||||
|
||||
ContactManifoldSolver& contactManifold = mContactConstraints[c];
|
||||
|
||||
@ -521,7 +521,7 @@ void ContactSolver::solve() {
|
||||
// Compute the bias "b" of the constraint
|
||||
float beta = mIsSplitImpulseActive ? BETA_SPLIT_IMPULSE : BETA;
|
||||
float biasPenetrationDepth = 0.0;
|
||||
if (contactPoint.penetrationDepth > SLOP) biasPenetrationDepth = -(beta/mTimeStep) *
|
||||
if (contactPoint.penetrationDepth > SLOP) biasPenetrationDepth = -(beta/m_timeStep) *
|
||||
max(0.0f, float(contactPoint.penetrationDepth - SLOP));
|
||||
float b = biasPenetrationDepth + contactPoint.restitutionBias;
|
||||
|
||||
@ -551,10 +551,10 @@ void ContactSolver::solve() {
|
||||
if (mIsSplitImpulseActive) {
|
||||
|
||||
// Split impulse (position correction)
|
||||
const Vector3& v1Split = mSplitLinearVelocities[contactManifold.indexBody1];
|
||||
const Vector3& w1Split = mSplitAngularVelocities[contactManifold.indexBody1];
|
||||
const Vector3& v2Split = mSplitLinearVelocities[contactManifold.indexBody2];
|
||||
const Vector3& w2Split = mSplitAngularVelocities[contactManifold.indexBody2];
|
||||
const Vector3& v1Split = m_splitLinearVelocities[contactManifold.indexBody1];
|
||||
const Vector3& w1Split = m_splitAngularVelocities[contactManifold.indexBody1];
|
||||
const Vector3& v2Split = m_splitLinearVelocities[contactManifold.indexBody2];
|
||||
const Vector3& w2Split = m_splitAngularVelocities[contactManifold.indexBody2];
|
||||
Vector3 deltaVSplit = v2Split + w2Split.cross(contactPoint.r2) -
|
||||
v1Split - w1Split.cross(contactPoint.r1);
|
||||
float JvSplit = deltaVSplit.dot(contactPoint.normal);
|
||||
@ -764,7 +764,7 @@ void ContactSolver::solve() {
|
||||
void ContactSolver::storeImpulses() {
|
||||
|
||||
// For each contact manifold
|
||||
for (uint32_t c=0; c<mNbContactManifolds; c++) {
|
||||
for (uint32_t c=0; c<m_numberContactManifolds; c++) {
|
||||
|
||||
ContactManifoldSolver& manifold = mContactConstraints[c];
|
||||
|
||||
@ -812,15 +812,15 @@ void ContactSolver::applySplitImpulse(const Impulse& impulse,
|
||||
const ContactManifoldSolver& manifold) {
|
||||
|
||||
// Update the velocities of the body 1 by applying the impulse P
|
||||
mSplitLinearVelocities[manifold.indexBody1] += manifold.massInverseBody1 *
|
||||
m_splitLinearVelocities[manifold.indexBody1] += manifold.massInverseBody1 *
|
||||
impulse.linearImpulseBody1;
|
||||
mSplitAngularVelocities[manifold.indexBody1] += manifold.inverseInertiaTensorBody1 *
|
||||
m_splitAngularVelocities[manifold.indexBody1] += manifold.inverseInertiaTensorBody1 *
|
||||
impulse.angularImpulseBody1;
|
||||
|
||||
// Update the velocities of the body 1 by applying the impulse P
|
||||
mSplitLinearVelocities[manifold.indexBody2] += manifold.massInverseBody2 *
|
||||
m_splitLinearVelocities[manifold.indexBody2] += manifold.massInverseBody2 *
|
||||
impulse.linearImpulseBody2;
|
||||
mSplitAngularVelocities[manifold.indexBody2] += manifold.inverseInertiaTensorBody2 *
|
||||
m_splitAngularVelocities[manifold.indexBody2] += manifold.inverseInertiaTensorBody2 *
|
||||
impulse.angularImpulseBody2;
|
||||
}
|
||||
|
||||
|
@ -304,19 +304,19 @@ class ContactSolver {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Split linear velocities for the position contact solver (split impulse)
|
||||
Vector3* mSplitLinearVelocities;
|
||||
Vector3* m_splitLinearVelocities;
|
||||
|
||||
/// Split angular velocities for the position contact solver (split impulse)
|
||||
Vector3* mSplitAngularVelocities;
|
||||
Vector3* m_splitAngularVelocities;
|
||||
|
||||
/// Current time step
|
||||
float mTimeStep;
|
||||
float m_timeStep;
|
||||
|
||||
/// Contact constraints
|
||||
ContactManifoldSolver* mContactConstraints;
|
||||
|
||||
/// Number of contact constraints
|
||||
uint32_t mNbContactManifolds;
|
||||
uint32_t m_numberContactManifolds;
|
||||
|
||||
/// Array of linear velocities
|
||||
Vector3* mLinearVelocities;
|
||||
@ -325,7 +325,7 @@ class ContactSolver {
|
||||
Vector3* mAngularVelocities;
|
||||
|
||||
/// Reference to the map of rigid body to their index in the constrained velocities array
|
||||
const std::map<RigidBody*, uint32_t>& mMapBodyToConstrainedVelocityIndex;
|
||||
const std::map<RigidBody*, uint32_t>& m_mapBodyToConstrainedVelocityIndex;
|
||||
|
||||
/// True if the warm starting of the solver is active
|
||||
bool mIsWarmStartingActive;
|
||||
@ -434,8 +434,8 @@ inline void ContactSolver::setSplitVelocitiesArrays(Vector3* splitLinearVelociti
|
||||
Vector3* splitAngularVelocities) {
|
||||
assert(splitLinearVelocities != NULL);
|
||||
assert(splitAngularVelocities != NULL);
|
||||
mSplitLinearVelocities = splitLinearVelocities;
|
||||
mSplitAngularVelocities = splitAngularVelocities;
|
||||
m_splitLinearVelocities = splitLinearVelocities;
|
||||
m_splitAngularVelocities = splitAngularVelocities;
|
||||
}
|
||||
|
||||
// Set the constrained velocities arrays
|
||||
|
@ -21,19 +21,19 @@ using namespace std;
|
||||
*/
|
||||
DynamicsWorld::DynamicsWorld(const Vector3 &gravity)
|
||||
: CollisionWorld(),
|
||||
mContactSolver(mMapBodyToConstrainedVelocityIndex),
|
||||
mConstraintSolver(mMapBodyToConstrainedVelocityIndex),
|
||||
mNbVelocitySolverIterations(DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS),
|
||||
mNbPositionSolverIterations(DEFAULT_POSITION_SOLVER_NB_ITERATIONS),
|
||||
m_isSleepingEnabled(SPLEEPING_ENABLED), mGravity(gravity),
|
||||
mIsGravityEnabled(true), mConstrainedLinearVelocities(NULL),
|
||||
mConstrainedAngularVelocities(NULL), mSplitLinearVelocities(NULL),
|
||||
mSplitAngularVelocities(NULL), mConstrainedPositions(NULL),
|
||||
mConstrainedOrientations(NULL), mNbIslands(0),
|
||||
mNbIslandsCapacity(0), mIslands(NULL), mNbBodiesCapacity(0),
|
||||
mSleepLinearVelocity(DEFAULT_SLEEP_LINEAR_VELOCITY),
|
||||
mSleepAngularVelocity(DEFAULT_SLEEP_ANGULAR_VELOCITY),
|
||||
mTimeBeforeSleep(DEFAULT_TIME_BEFORE_SLEEP) {
|
||||
m_contactSolver(m_mapBodyToConstrainedVelocityIndex),
|
||||
m_constraintSolver(m_mapBodyToConstrainedVelocityIndex),
|
||||
m_nbVelocitySolverIterations(DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS),
|
||||
m_nbPositionSolverIterations(DEFAULT_POSITION_SOLVER_NB_ITERATIONS),
|
||||
m_isSleepingEnabled(SPLEEPING_ENABLED), m_gravity(gravity),
|
||||
m_isGravityEnabled(true), m_constrainedLinearVelocities(NULL),
|
||||
m_constrainedAngularVelocities(NULL), m_splitLinearVelocities(NULL),
|
||||
m_splitAngularVelocities(NULL), m_constrainedPositions(NULL),
|
||||
m_constrainedOrientations(NULL), m_numberIslands(0),
|
||||
m_numberIslandsCapacity(0), m_islands(NULL), m_numberBodiesCapacity(0),
|
||||
m_sleepLinearVelocity(DEFAULT_SLEEP_LINEAR_VELOCITY),
|
||||
m_sleepAngularVelocity(DEFAULT_SLEEP_ANGULAR_VELOCITY),
|
||||
m_timeBeforeSleep(DEFAULT_TIME_BEFORE_SLEEP) {
|
||||
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ DynamicsWorld::~DynamicsWorld() {
|
||||
|
||||
// Destroy all the joints that have not been removed
|
||||
std::set<Joint*>::iterator itJoints;
|
||||
for (itJoints = mJoints.begin(); itJoints != mJoints.end();) {
|
||||
for (itJoints = m_joints.begin(); itJoints != m_joints.end();) {
|
||||
std::set<Joint*>::iterator itToRemove = itJoints;
|
||||
++itJoints;
|
||||
destroyJoint(*itToRemove);
|
||||
@ -50,37 +50,37 @@ DynamicsWorld::~DynamicsWorld() {
|
||||
|
||||
// Destroy all the rigid bodies that have not been removed
|
||||
std::set<RigidBody*>::iterator itRigidBodies;
|
||||
for (itRigidBodies = mRigidBodies.begin(); itRigidBodies != mRigidBodies.end();) {
|
||||
for (itRigidBodies = m_rigidBodies.begin(); itRigidBodies != m_rigidBodies.end();) {
|
||||
std::set<RigidBody*>::iterator itToRemove = itRigidBodies;
|
||||
++itRigidBodies;
|
||||
destroyRigidBody(*itToRemove);
|
||||
}
|
||||
|
||||
// Release the memory allocated for the islands
|
||||
for (uint32_t i=0; i<mNbIslands; i++) {
|
||||
for (uint32_t i=0; i<m_numberIslands; i++) {
|
||||
|
||||
// Call the island destructor
|
||||
mIslands[i]->~Island();
|
||||
m_islands[i]->~Island();
|
||||
|
||||
// Release the allocated memory for the island
|
||||
mMemoryAllocator.release(mIslands[i], sizeof(Island));
|
||||
m_memoryAllocator.release(m_islands[i], sizeof(Island));
|
||||
}
|
||||
if (mNbIslandsCapacity > 0) {
|
||||
mMemoryAllocator.release(mIslands, sizeof(Island*) * mNbIslandsCapacity);
|
||||
if (m_numberIslandsCapacity > 0) {
|
||||
m_memoryAllocator.release(m_islands, sizeof(Island*) * m_numberIslandsCapacity);
|
||||
}
|
||||
|
||||
// Release the memory allocated for the bodies velocity arrays
|
||||
if (mNbBodiesCapacity > 0) {
|
||||
delete[] mSplitLinearVelocities;
|
||||
delete[] mSplitAngularVelocities;
|
||||
delete[] mConstrainedLinearVelocities;
|
||||
delete[] mConstrainedAngularVelocities;
|
||||
delete[] mConstrainedPositions;
|
||||
delete[] mConstrainedOrientations;
|
||||
if (m_numberBodiesCapacity > 0) {
|
||||
delete[] m_splitLinearVelocities;
|
||||
delete[] m_splitAngularVelocities;
|
||||
delete[] m_constrainedLinearVelocities;
|
||||
delete[] m_constrainedAngularVelocities;
|
||||
delete[] m_constrainedPositions;
|
||||
delete[] m_constrainedOrientations;
|
||||
}
|
||||
|
||||
assert(mJoints.size() == 0);
|
||||
assert(mRigidBodies.size() == 0);
|
||||
assert(m_joints.size() == 0);
|
||||
assert(m_rigidBodies.size() == 0);
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
||||
@ -106,17 +106,17 @@ void DynamicsWorld::update(float timeStep) {
|
||||
|
||||
PROFILE("DynamicsWorld::update()");
|
||||
|
||||
mTimeStep = timeStep;
|
||||
m_timeStep = timeStep;
|
||||
|
||||
// Notify the event listener about the beginning of an int32_ternal tick
|
||||
if (mEventListener != NULL) {
|
||||
mEventListener->beginInternalTick();
|
||||
if (m_eventListener != NULL) {
|
||||
m_eventListener->beginInternalTick();
|
||||
}
|
||||
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
if (mRigidBodies.size() == 0) {
|
||||
if (m_rigidBodies.size() == 0) {
|
||||
// no rigid body ==> no process to do ...
|
||||
return;
|
||||
}
|
||||
@ -145,7 +145,7 @@ void DynamicsWorld::update(float timeStep) {
|
||||
if (m_isSleepingEnabled) updateSleepingBodies();
|
||||
|
||||
// Notify the event listener about the end of an int32_ternal tick
|
||||
if (mEventListener != NULL) mEventListener->endInternalTick();
|
||||
if (m_eventListener != NULL) m_eventListener->endInternalTick();
|
||||
|
||||
// Reset the external force and torque applied to the bodies
|
||||
resetBodiesForceAndTorque();
|
||||
@ -159,24 +159,24 @@ void DynamicsWorld::int32_tegrateRigidBodiesPositions() {
|
||||
PROFILE("DynamicsWorld::int32_tegrateRigidBodiesPositions()");
|
||||
|
||||
// For each island of the world
|
||||
for (uint32_t i=0; i < mNbIslands; i++) {
|
||||
for (uint32_t i=0; i < m_numberIslands; i++) {
|
||||
|
||||
RigidBody** bodies = mIslands[i]->getBodies();
|
||||
RigidBody** bodies = m_islands[i]->getBodies();
|
||||
|
||||
// For each body of the island
|
||||
for (uint32_t b=0; b < mIslands[i]->getNbBodies(); b++) {
|
||||
for (uint32_t b=0; b < m_islands[i]->getNbBodies(); b++) {
|
||||
|
||||
// Get the constrained velocity
|
||||
uint32_t indexArray = mMapBodyToConstrainedVelocityIndex.find(bodies[b])->second;
|
||||
Vector3 newLinVelocity = mConstrainedLinearVelocities[indexArray];
|
||||
Vector3 newAngVelocity = mConstrainedAngularVelocities[indexArray];
|
||||
uint32_t indexArray = m_mapBodyToConstrainedVelocityIndex.find(bodies[b])->second;
|
||||
Vector3 newLinVelocity = m_constrainedLinearVelocities[indexArray];
|
||||
Vector3 newAngVelocity = m_constrainedAngularVelocities[indexArray];
|
||||
|
||||
// Add the split impulse velocity from Contact Solver (only used
|
||||
// to update the position)
|
||||
if (mContactSolver.isSplitImpulseActive()) {
|
||||
if (m_contactSolver.isSplitImpulseActive()) {
|
||||
|
||||
newLinVelocity += mSplitLinearVelocities[indexArray];
|
||||
newAngVelocity += mSplitAngularVelocities[indexArray];
|
||||
newLinVelocity += m_splitLinearVelocities[indexArray];
|
||||
newAngVelocity += m_splitAngularVelocities[indexArray];
|
||||
}
|
||||
|
||||
// Get current position and orientation of the body
|
||||
@ -184,10 +184,10 @@ void DynamicsWorld::int32_tegrateRigidBodiesPositions() {
|
||||
const Quaternion& currentOrientation = bodies[b]->getTransform().getOrientation();
|
||||
|
||||
// Update the new constrained position and orientation of the body
|
||||
mConstrainedPositions[indexArray] = currentPosition + newLinVelocity * mTimeStep;
|
||||
mConstrainedOrientations[indexArray] = currentOrientation +
|
||||
m_constrainedPositions[indexArray] = currentPosition + newLinVelocity * m_timeStep;
|
||||
m_constrainedOrientations[indexArray] = currentOrientation +
|
||||
Quaternion(0, newAngVelocity) *
|
||||
currentOrientation * float(0.5) * mTimeStep;
|
||||
currentOrientation * float(0.5) * m_timeStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,24 +198,24 @@ void DynamicsWorld::updateBodiesState() {
|
||||
PROFILE("DynamicsWorld::updateBodiesState()");
|
||||
|
||||
// For each island of the world
|
||||
for (uint32_t islandIndex = 0; islandIndex < mNbIslands; islandIndex++) {
|
||||
for (uint32_t islandIndex = 0; islandIndex < m_numberIslands; islandIndex++) {
|
||||
|
||||
// For each body of the island
|
||||
RigidBody** bodies = mIslands[islandIndex]->getBodies();
|
||||
RigidBody** bodies = m_islands[islandIndex]->getBodies();
|
||||
|
||||
for (uint32_t b=0; b < mIslands[islandIndex]->getNbBodies(); b++) {
|
||||
for (uint32_t b=0; b < m_islands[islandIndex]->getNbBodies(); b++) {
|
||||
|
||||
uint32_t index = mMapBodyToConstrainedVelocityIndex.find(bodies[b])->second;
|
||||
uint32_t index = m_mapBodyToConstrainedVelocityIndex.find(bodies[b])->second;
|
||||
|
||||
// Update the linear and angular velocity of the body
|
||||
bodies[b]->mLinearVelocity = mConstrainedLinearVelocities[index];
|
||||
bodies[b]->mAngularVelocity = mConstrainedAngularVelocities[index];
|
||||
bodies[b]->mLinearVelocity = m_constrainedLinearVelocities[index];
|
||||
bodies[b]->mAngularVelocity = m_constrainedAngularVelocities[index];
|
||||
|
||||
// Update the position of the center of mass of the body
|
||||
bodies[b]->mCenterOfMassWorld = mConstrainedPositions[index];
|
||||
bodies[b]->mCenterOfMassWorld = m_constrainedPositions[index];
|
||||
|
||||
// Update the orientation of the body
|
||||
bodies[b]->mTransform.setOrientation(mConstrainedOrientations[index].getUnit());
|
||||
bodies[b]->m_transform.setOrientation(m_constrainedOrientations[index].getUnit());
|
||||
|
||||
// Update the transform of the body (using the new center of mass and new orientation)
|
||||
bodies[b]->updateTransformWithCenterOfMass();
|
||||
@ -230,42 +230,42 @@ void DynamicsWorld::updateBodiesState() {
|
||||
void DynamicsWorld::initVelocityArrays() {
|
||||
|
||||
// Allocate memory for the bodies velocity arrays
|
||||
uint32_t nbBodies = mRigidBodies.size();
|
||||
if (mNbBodiesCapacity != nbBodies && nbBodies > 0) {
|
||||
if (mNbBodiesCapacity > 0) {
|
||||
delete[] mSplitLinearVelocities;
|
||||
delete[] mSplitAngularVelocities;
|
||||
uint32_t nbBodies = m_rigidBodies.size();
|
||||
if (m_numberBodiesCapacity != nbBodies && nbBodies > 0) {
|
||||
if (m_numberBodiesCapacity > 0) {
|
||||
delete[] m_splitLinearVelocities;
|
||||
delete[] m_splitAngularVelocities;
|
||||
}
|
||||
mNbBodiesCapacity = nbBodies;
|
||||
m_numberBodiesCapacity = nbBodies;
|
||||
// TODO : Use better memory allocation here
|
||||
mSplitLinearVelocities = new Vector3[mNbBodiesCapacity];
|
||||
mSplitAngularVelocities = new Vector3[mNbBodiesCapacity];
|
||||
mConstrainedLinearVelocities = new Vector3[mNbBodiesCapacity];
|
||||
mConstrainedAngularVelocities = new Vector3[mNbBodiesCapacity];
|
||||
mConstrainedPositions = new Vector3[mNbBodiesCapacity];
|
||||
mConstrainedOrientations = new Quaternion[mNbBodiesCapacity];
|
||||
assert(mSplitLinearVelocities != NULL);
|
||||
assert(mSplitAngularVelocities != NULL);
|
||||
assert(mConstrainedLinearVelocities != NULL);
|
||||
assert(mConstrainedAngularVelocities != NULL);
|
||||
assert(mConstrainedPositions != NULL);
|
||||
assert(mConstrainedOrientations != NULL);
|
||||
m_splitLinearVelocities = new Vector3[m_numberBodiesCapacity];
|
||||
m_splitAngularVelocities = new Vector3[m_numberBodiesCapacity];
|
||||
m_constrainedLinearVelocities = new Vector3[m_numberBodiesCapacity];
|
||||
m_constrainedAngularVelocities = new Vector3[m_numberBodiesCapacity];
|
||||
m_constrainedPositions = new Vector3[m_numberBodiesCapacity];
|
||||
m_constrainedOrientations = new Quaternion[m_numberBodiesCapacity];
|
||||
assert(m_splitLinearVelocities != NULL);
|
||||
assert(m_splitAngularVelocities != NULL);
|
||||
assert(m_constrainedLinearVelocities != NULL);
|
||||
assert(m_constrainedAngularVelocities != NULL);
|
||||
assert(m_constrainedPositions != NULL);
|
||||
assert(m_constrainedOrientations != NULL);
|
||||
}
|
||||
|
||||
// Reset the velocities arrays
|
||||
for (uint32_t i=0; i<mNbBodiesCapacity; i++) {
|
||||
mSplitLinearVelocities[i].setToZero();
|
||||
mSplitAngularVelocities[i].setToZero();
|
||||
for (uint32_t i=0; i<m_numberBodiesCapacity; i++) {
|
||||
m_splitLinearVelocities[i].setToZero();
|
||||
m_splitAngularVelocities[i].setToZero();
|
||||
}
|
||||
|
||||
// Initialize the map of body indexes in the velocity arrays
|
||||
mMapBodyToConstrainedVelocityIndex.clear();
|
||||
m_mapBodyToConstrainedVelocityIndex.clear();
|
||||
std::set<RigidBody*>::const_iterator it;
|
||||
uint32_t indexBody = 0;
|
||||
for (it = mRigidBodies.begin(); it != mRigidBodies.end(); ++it) {
|
||||
for (it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) {
|
||||
|
||||
// Add the body int32_to the map
|
||||
mMapBodyToConstrainedVelocityIndex.insert(std::make_pair(*it, indexBody));
|
||||
m_mapBodyToConstrainedVelocityIndex.insert(std::make_pair(*it, indexBody));
|
||||
indexBody++;
|
||||
}
|
||||
}
|
||||
@ -283,32 +283,32 @@ void DynamicsWorld::int32_tegrateRigidBodiesVelocities() {
|
||||
initVelocityArrays();
|
||||
|
||||
// For each island of the world
|
||||
for (uint32_t i=0; i < mNbIslands; i++) {
|
||||
for (uint32_t i=0; i < m_numberIslands; i++) {
|
||||
|
||||
RigidBody** bodies = mIslands[i]->getBodies();
|
||||
RigidBody** bodies = m_islands[i]->getBodies();
|
||||
|
||||
// For each body of the island
|
||||
for (uint32_t b=0; b < mIslands[i]->getNbBodies(); b++) {
|
||||
for (uint32_t b=0; b < m_islands[i]->getNbBodies(); b++) {
|
||||
|
||||
// Insert the body int32_to the map of constrained velocities
|
||||
uint32_t indexBody = mMapBodyToConstrainedVelocityIndex.find(bodies[b])->second;
|
||||
uint32_t indexBody = m_mapBodyToConstrainedVelocityIndex.find(bodies[b])->second;
|
||||
|
||||
assert(mSplitLinearVelocities[indexBody] == Vector3(0, 0, 0));
|
||||
assert(mSplitAngularVelocities[indexBody] == Vector3(0, 0, 0));
|
||||
assert(m_splitLinearVelocities[indexBody] == Vector3(0, 0, 0));
|
||||
assert(m_splitAngularVelocities[indexBody] == Vector3(0, 0, 0));
|
||||
|
||||
// Integrate the external force to get the new velocity of the body
|
||||
mConstrainedLinearVelocities[indexBody] = bodies[b]->getLinearVelocity() +
|
||||
mTimeStep * bodies[b]->mMassInverse * bodies[b]->mExternalForce;
|
||||
mConstrainedAngularVelocities[indexBody] = bodies[b]->getAngularVelocity() +
|
||||
mTimeStep * bodies[b]->getInertiaTensorInverseWorld() *
|
||||
m_constrainedLinearVelocities[indexBody] = bodies[b]->getLinearVelocity() +
|
||||
m_timeStep * bodies[b]->m_massInverse * bodies[b]->mExternalForce;
|
||||
m_constrainedAngularVelocities[indexBody] = bodies[b]->getAngularVelocity() +
|
||||
m_timeStep * bodies[b]->getInertiaTensorInverseWorld() *
|
||||
bodies[b]->mExternalTorque;
|
||||
|
||||
// If the gravity has to be applied to this rigid body
|
||||
if (bodies[b]->isGravityEnabled() && mIsGravityEnabled) {
|
||||
if (bodies[b]->isGravityEnabled() && m_isGravityEnabled) {
|
||||
|
||||
// Integrate the gravity force
|
||||
mConstrainedLinearVelocities[indexBody] += mTimeStep * bodies[b]->mMassInverse *
|
||||
bodies[b]->getMass() * mGravity;
|
||||
m_constrainedLinearVelocities[indexBody] += m_timeStep * bodies[b]->m_massInverse *
|
||||
bodies[b]->getMass() * m_gravity;
|
||||
}
|
||||
|
||||
// Apply the velocity damping
|
||||
@ -326,10 +326,10 @@ void DynamicsWorld::int32_tegrateRigidBodiesVelocities() {
|
||||
// => v2 = v1 * (1 - c * dt)
|
||||
float linDampingFactor = bodies[b]->getLinearDamping();
|
||||
float angDampingFactor = bodies[b]->getAngularDamping();
|
||||
float linearDamping = pow(float(1.0) - linDampingFactor, mTimeStep);
|
||||
float angularDamping = pow(float(1.0) - angDampingFactor, mTimeStep);
|
||||
mConstrainedLinearVelocities[indexBody] *= linearDamping;
|
||||
mConstrainedAngularVelocities[indexBody] *= angularDamping;
|
||||
float linearDamping = pow(float(1.0) - linDampingFactor, m_timeStep);
|
||||
float angularDamping = pow(float(1.0) - angDampingFactor, m_timeStep);
|
||||
m_constrainedLinearVelocities[indexBody] *= linearDamping;
|
||||
m_constrainedAngularVelocities[indexBody] *= angularDamping;
|
||||
|
||||
indexBody++;
|
||||
}
|
||||
@ -342,58 +342,58 @@ void DynamicsWorld::solveContactsAndConstraints() {
|
||||
PROFILE("DynamicsWorld::solveContactsAndConstraints()");
|
||||
|
||||
// Set the velocities arrays
|
||||
mContactSolver.setSplitVelocitiesArrays(mSplitLinearVelocities, mSplitAngularVelocities);
|
||||
mContactSolver.setConstrainedVelocitiesArrays(mConstrainedLinearVelocities,
|
||||
mConstrainedAngularVelocities);
|
||||
mConstraintSolver.setConstrainedVelocitiesArrays(mConstrainedLinearVelocities,
|
||||
mConstrainedAngularVelocities);
|
||||
mConstraintSolver.setConstrainedPositionsArrays(mConstrainedPositions,
|
||||
mConstrainedOrientations);
|
||||
m_contactSolver.setSplitVelocitiesArrays(m_splitLinearVelocities, m_splitAngularVelocities);
|
||||
m_contactSolver.setConstrainedVelocitiesArrays(m_constrainedLinearVelocities,
|
||||
m_constrainedAngularVelocities);
|
||||
m_constraintSolver.setConstrainedVelocitiesArrays(m_constrainedLinearVelocities,
|
||||
m_constrainedAngularVelocities);
|
||||
m_constraintSolver.setConstrainedPositionsArrays(m_constrainedPositions,
|
||||
m_constrainedOrientations);
|
||||
|
||||
// ---------- Solve velocity constraints for joints and contacts ---------- //
|
||||
|
||||
// For each island of the world
|
||||
for (uint32_t islandIndex = 0; islandIndex < mNbIslands; islandIndex++) {
|
||||
for (uint32_t islandIndex = 0; islandIndex < m_numberIslands; islandIndex++) {
|
||||
|
||||
// Check if there are contacts and constraints to solve
|
||||
bool isConstraintsToSolve = mIslands[islandIndex]->getNbJoints() > 0;
|
||||
bool isContactsToSolve = mIslands[islandIndex]->getNbContactManifolds() > 0;
|
||||
bool isConstraintsToSolve = m_islands[islandIndex]->getNbJoints() > 0;
|
||||
bool isContactsToSolve = m_islands[islandIndex]->getNbContactManifolds() > 0;
|
||||
if (!isConstraintsToSolve && !isContactsToSolve) continue;
|
||||
|
||||
// If there are contacts in the current island
|
||||
if (isContactsToSolve) {
|
||||
|
||||
// Initialize the solver
|
||||
mContactSolver.initializeForIsland(mTimeStep, mIslands[islandIndex]);
|
||||
m_contactSolver.initializeForIsland(m_timeStep, m_islands[islandIndex]);
|
||||
|
||||
// Warm start the contact solver
|
||||
mContactSolver.warmStart();
|
||||
m_contactSolver.warmStart();
|
||||
}
|
||||
|
||||
// If there are constraints
|
||||
if (isConstraintsToSolve) {
|
||||
|
||||
// Initialize the constraint solver
|
||||
mConstraintSolver.initializeForIsland(mTimeStep, mIslands[islandIndex]);
|
||||
m_constraintSolver.initializeForIsland(m_timeStep, m_islands[islandIndex]);
|
||||
}
|
||||
|
||||
// For each iteration of the velocity solver
|
||||
for (uint32_t i=0; i<mNbVelocitySolverIterations; i++) {
|
||||
for (uint32_t i=0; i<m_nbVelocitySolverIterations; i++) {
|
||||
|
||||
// Solve the constraints
|
||||
if (isConstraintsToSolve) {
|
||||
mConstraintSolver.solveVelocityConstraints(mIslands[islandIndex]);
|
||||
m_constraintSolver.solveVelocityConstraints(m_islands[islandIndex]);
|
||||
}
|
||||
|
||||
// Solve the contacts
|
||||
if (isContactsToSolve) mContactSolver.solve();
|
||||
if (isContactsToSolve) m_contactSolver.solve();
|
||||
}
|
||||
|
||||
// Cache the lambda values in order to use them in the next
|
||||
// step and cleanup the contact solver
|
||||
if (isContactsToSolve) {
|
||||
mContactSolver.storeImpulses();
|
||||
mContactSolver.cleanup();
|
||||
m_contactSolver.storeImpulses();
|
||||
m_contactSolver.cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -404,18 +404,18 @@ void DynamicsWorld::solvePositionCorrection() {
|
||||
PROFILE("DynamicsWorld::solvePositionCorrection()");
|
||||
|
||||
// Do not continue if there is no constraints
|
||||
if (mJoints.empty()) return;
|
||||
if (m_joints.empty()) return;
|
||||
|
||||
// For each island of the world
|
||||
for (uint32_t islandIndex = 0; islandIndex < mNbIslands; islandIndex++) {
|
||||
for (uint32_t islandIndex = 0; islandIndex < m_numberIslands; islandIndex++) {
|
||||
|
||||
// ---------- Solve the position error correction for the constraints ---------- //
|
||||
|
||||
// For each iteration of the position (error correction) solver
|
||||
for (uint32_t i=0; i<mNbPositionSolverIterations; i++) {
|
||||
for (uint32_t i=0; i<m_nbPositionSolverIterations; i++) {
|
||||
|
||||
// Solve the position constraints
|
||||
mConstraintSolver.solvePositionConstraints(mIslands[islandIndex]);
|
||||
m_constraintSolver.solvePositionConstraints(m_islands[islandIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -434,13 +434,13 @@ RigidBody* DynamicsWorld::createRigidBody(const Transform& transform) {
|
||||
assert(bodyID < std::numeric_limits<reactphysics3d::bodyindex>::max());
|
||||
|
||||
// Create the rigid body
|
||||
RigidBody* rigidBody = new (mMemoryAllocator.allocate(sizeof(RigidBody))) RigidBody(transform,
|
||||
RigidBody* rigidBody = new (m_memoryAllocator.allocate(sizeof(RigidBody))) RigidBody(transform,
|
||||
*this, bodyID);
|
||||
assert(rigidBody != NULL);
|
||||
|
||||
// Add the rigid body to the physics world
|
||||
mBodies.insert(rigidBody);
|
||||
mRigidBodies.insert(rigidBody);
|
||||
m_bodies.insert(rigidBody);
|
||||
m_rigidBodies.insert(rigidBody);
|
||||
|
||||
// Return the pointer to the rigid body
|
||||
return rigidBody;
|
||||
@ -456,11 +456,11 @@ void DynamicsWorld::destroyRigidBody(RigidBody* rigidBody) {
|
||||
rigidBody->removeAllCollisionShapes();
|
||||
|
||||
// Add the body ID to the list of free IDs
|
||||
mFreeBodiesIDs.push_back(rigidBody->getID());
|
||||
m_freeBodiesIDs.push_back(rigidBody->getID());
|
||||
|
||||
// Destroy all the joints in which the rigid body to be destroyed is involved
|
||||
JointListElement* element;
|
||||
for (element = rigidBody->mJointsList; element != NULL; element = element->next) {
|
||||
for (element = rigidBody->m_jointsList; element != NULL; element = element->next) {
|
||||
destroyJoint(element->joint);
|
||||
}
|
||||
|
||||
@ -471,11 +471,11 @@ void DynamicsWorld::destroyRigidBody(RigidBody* rigidBody) {
|
||||
rigidBody->~RigidBody();
|
||||
|
||||
// Remove the rigid body from the list of rigid bodies
|
||||
mBodies.erase(rigidBody);
|
||||
mRigidBodies.erase(rigidBody);
|
||||
m_bodies.erase(rigidBody);
|
||||
m_rigidBodies.erase(rigidBody);
|
||||
|
||||
// Free the object from the memory allocator
|
||||
mMemoryAllocator.release(rigidBody, sizeof(RigidBody));
|
||||
m_memoryAllocator.release(rigidBody, sizeof(RigidBody));
|
||||
}
|
||||
|
||||
// Create a joint between two bodies in the world and return a pointer to the new joint
|
||||
@ -493,7 +493,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) {
|
||||
// Ball-and-Socket joint
|
||||
case BALLSOCKETJOINT:
|
||||
{
|
||||
void* allocatedMemory = mMemoryAllocator.allocate(sizeof(BallAndSocketJoint));
|
||||
void* allocatedMemory = m_memoryAllocator.allocate(sizeof(BallAndSocketJoint));
|
||||
const BallAndSocketJointInfo& info = static_cast<const BallAndSocketJointInfo&>(
|
||||
jointInfo);
|
||||
newJoint = new (allocatedMemory) BallAndSocketJoint(info);
|
||||
@ -503,7 +503,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) {
|
||||
// Slider joint
|
||||
case SLIDERJOINT:
|
||||
{
|
||||
void* allocatedMemory = mMemoryAllocator.allocate(sizeof(SliderJoint));
|
||||
void* allocatedMemory = m_memoryAllocator.allocate(sizeof(SliderJoint));
|
||||
const SliderJointInfo& info = static_cast<const SliderJointInfo&>(jointInfo);
|
||||
newJoint = new (allocatedMemory) SliderJoint(info);
|
||||
break;
|
||||
@ -512,7 +512,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) {
|
||||
// Hinge joint
|
||||
case HINGEJOINT:
|
||||
{
|
||||
void* allocatedMemory = mMemoryAllocator.allocate(sizeof(HingeJoint));
|
||||
void* allocatedMemory = m_memoryAllocator.allocate(sizeof(HingeJoint));
|
||||
const HingeJointInfo& info = static_cast<const HingeJointInfo&>(jointInfo);
|
||||
newJoint = new (allocatedMemory) HingeJoint(info);
|
||||
break;
|
||||
@ -521,7 +521,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) {
|
||||
// Fixed joint
|
||||
case FIXEDJOINT:
|
||||
{
|
||||
void* allocatedMemory = mMemoryAllocator.allocate(sizeof(FixedJoint));
|
||||
void* allocatedMemory = m_memoryAllocator.allocate(sizeof(FixedJoint));
|
||||
const FixedJointInfo& info = static_cast<const FixedJointInfo&>(jointInfo);
|
||||
newJoint = new (allocatedMemory) FixedJoint(info);
|
||||
break;
|
||||
@ -542,7 +542,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) {
|
||||
}
|
||||
|
||||
// Add the joint int32_to the world
|
||||
mJoints.insert(newJoint);
|
||||
m_joints.insert(newJoint);
|
||||
|
||||
// Add the joint int32_to the joint list of the bodies involved in the joint
|
||||
addJointToBody(newJoint);
|
||||
@ -571,11 +571,11 @@ void DynamicsWorld::destroyJoint(Joint* joint) {
|
||||
joint->getBody2()->setIsSleeping(false);
|
||||
|
||||
// Remove the joint from the world
|
||||
mJoints.erase(joint);
|
||||
m_joints.erase(joint);
|
||||
|
||||
// Remove the joint from the joint list of the bodies involved in the joint
|
||||
joint->mBody1->removeJointFromJointsList(mMemoryAllocator, joint);
|
||||
joint->mBody2->removeJointFromJointsList(mMemoryAllocator, joint);
|
||||
joint->m_body1->removeJointFrom_jointsList(m_memoryAllocator, joint);
|
||||
joint->m_body2->removeJointFrom_jointsList(m_memoryAllocator, joint);
|
||||
|
||||
size_t nbBytes = joint->getSizeInBytes();
|
||||
|
||||
@ -583,7 +583,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) {
|
||||
joint->~Joint();
|
||||
|
||||
// Release the allocated memory
|
||||
mMemoryAllocator.release(joint, nbBytes);
|
||||
m_memoryAllocator.release(joint, nbBytes);
|
||||
}
|
||||
|
||||
// Add the joint to the list of joints of the two bodies involved in the joint
|
||||
@ -592,16 +592,16 @@ void DynamicsWorld::addJointToBody(Joint* joint) {
|
||||
assert(joint != NULL);
|
||||
|
||||
// Add the joint at the beginning of the linked list of joints of the first body
|
||||
void* allocatedMemory1 = mMemoryAllocator.allocate(sizeof(JointListElement));
|
||||
void* allocatedMemory1 = m_memoryAllocator.allocate(sizeof(JointListElement));
|
||||
JointListElement* jointListElement1 = new (allocatedMemory1) JointListElement(joint,
|
||||
joint->mBody1->mJointsList);
|
||||
joint->mBody1->mJointsList = jointListElement1;
|
||||
joint->m_body1->m_jointsList);
|
||||
joint->m_body1->m_jointsList = jointListElement1;
|
||||
|
||||
// Add the joint at the beginning of the linked list of joints of the second body
|
||||
void* allocatedMemory2 = mMemoryAllocator.allocate(sizeof(JointListElement));
|
||||
void* allocatedMemory2 = m_memoryAllocator.allocate(sizeof(JointListElement));
|
||||
JointListElement* jointListElement2 = new (allocatedMemory2) JointListElement(joint,
|
||||
joint->mBody2->mJointsList);
|
||||
joint->mBody2->mJointsList = jointListElement2;
|
||||
joint->m_body2->m_jointsList);
|
||||
joint->m_body2->m_jointsList = jointListElement2;
|
||||
}
|
||||
|
||||
// Compute the islands of awake bodies.
|
||||
@ -615,45 +615,45 @@ void DynamicsWorld::computeIslands() {
|
||||
|
||||
PROFILE("DynamicsWorld::computeIslands()");
|
||||
|
||||
uint32_t nbBodies = mRigidBodies.size();
|
||||
uint32_t nbBodies = m_rigidBodies.size();
|
||||
|
||||
// Clear all the islands
|
||||
for (uint32_t i=0; i<mNbIslands; i++) {
|
||||
for (uint32_t i=0; i<m_numberIslands; i++) {
|
||||
|
||||
// Call the island destructor
|
||||
mIslands[i]->~Island();
|
||||
m_islands[i]->~Island();
|
||||
|
||||
// Release the allocated memory for the island
|
||||
mMemoryAllocator.release(mIslands[i], sizeof(Island));
|
||||
m_memoryAllocator.release(m_islands[i], sizeof(Island));
|
||||
}
|
||||
|
||||
// Allocate and create the array of islands
|
||||
if (mNbIslandsCapacity != nbBodies && nbBodies > 0) {
|
||||
if (mNbIslandsCapacity > 0) {
|
||||
mMemoryAllocator.release(mIslands, sizeof(Island*) * mNbIslandsCapacity);
|
||||
if (m_numberIslandsCapacity != nbBodies && nbBodies > 0) {
|
||||
if (m_numberIslandsCapacity > 0) {
|
||||
m_memoryAllocator.release(m_islands, sizeof(Island*) * m_numberIslandsCapacity);
|
||||
}
|
||||
mNbIslandsCapacity = nbBodies;
|
||||
mIslands = (Island**)mMemoryAllocator.allocate(sizeof(Island*) * mNbIslandsCapacity);
|
||||
m_numberIslandsCapacity = nbBodies;
|
||||
m_islands = (Island**)m_memoryAllocator.allocate(sizeof(Island*) * m_numberIslandsCapacity);
|
||||
}
|
||||
mNbIslands = 0;
|
||||
m_numberIslands = 0;
|
||||
|
||||
int32_t nbContactManifolds = 0;
|
||||
|
||||
// Reset all the isAlreadyInIsland variables of bodies, joints and contact manifolds
|
||||
for (std::set<RigidBody*>::iterator it = mRigidBodies.begin(); it != mRigidBodies.end(); ++it) {
|
||||
for (std::set<RigidBody*>::iterator it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) {
|
||||
int32_t nbBodyManifolds = (*it)->resetIsAlreadyInIslandAndCountManifolds();
|
||||
nbContactManifolds += nbBodyManifolds;
|
||||
}
|
||||
for (std::set<Joint*>::iterator it = mJoints.begin(); it != mJoints.end(); ++it) {
|
||||
for (std::set<Joint*>::iterator it = m_joints.begin(); it != m_joints.end(); ++it) {
|
||||
(*it)->m_isAlreadyInIsland = false;
|
||||
}
|
||||
|
||||
// Create a stack (using an array) for the rigid bodies to visit during the Depth First Search
|
||||
size_t nbBytesStack = sizeof(RigidBody*) * nbBodies;
|
||||
RigidBody** stackBodiesToVisit = (RigidBody**)mMemoryAllocator.allocate(nbBytesStack);
|
||||
RigidBody** stackBodiesToVisit = (RigidBody**)m_memoryAllocator.allocate(nbBytesStack);
|
||||
|
||||
// For each rigid body of the world
|
||||
for (std::set<RigidBody*>::iterator it = mRigidBodies.begin(); it != mRigidBodies.end(); ++it) {
|
||||
for (std::set<RigidBody*>::iterator it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) {
|
||||
|
||||
RigidBody* body = *it;
|
||||
|
||||
@ -673,10 +673,10 @@ void DynamicsWorld::computeIslands() {
|
||||
body->m_isAlreadyInIsland = true;
|
||||
|
||||
// Create the new island
|
||||
void* allocatedMemoryIsland = mMemoryAllocator.allocate(sizeof(Island));
|
||||
mIslands[mNbIslands] = new (allocatedMemoryIsland) Island(nbBodies,
|
||||
void* allocatedMemoryIsland = m_memoryAllocator.allocate(sizeof(Island));
|
||||
m_islands[m_numberIslands] = new (allocatedMemoryIsland) Island(nbBodies,
|
||||
nbContactManifolds,
|
||||
mJoints.size(), mMemoryAllocator);
|
||||
m_joints.size(), m_memoryAllocator);
|
||||
|
||||
// While there are still some bodies to visit in the stack
|
||||
while (stackIndex > 0) {
|
||||
@ -690,7 +690,7 @@ void DynamicsWorld::computeIslands() {
|
||||
bodyToVisit->setIsSleeping(false);
|
||||
|
||||
// Add the body int32_to the island
|
||||
mIslands[mNbIslands]->addBody(bodyToVisit);
|
||||
m_islands[m_numberIslands]->addBody(bodyToVisit);
|
||||
|
||||
// If the current body is static, we do not want to perform the DFS
|
||||
// search across that body
|
||||
@ -698,7 +698,7 @@ void DynamicsWorld::computeIslands() {
|
||||
|
||||
// For each contact manifold in which the current body is involded
|
||||
ContactManifoldListElement* contactElement;
|
||||
for (contactElement = bodyToVisit->mContactManifoldsList; contactElement != NULL;
|
||||
for (contactElement = bodyToVisit->m_contactManifoldsList; contactElement != NULL;
|
||||
contactElement = contactElement->next) {
|
||||
|
||||
ContactManifold* contactManifold = contactElement->contactManifold;
|
||||
@ -709,7 +709,7 @@ void DynamicsWorld::computeIslands() {
|
||||
if (contactManifold->isAlreadyInIsland()) continue;
|
||||
|
||||
// Add the contact manifold int32_to the island
|
||||
mIslands[mNbIslands]->addContactManifold(contactManifold);
|
||||
m_islands[m_numberIslands]->addContactManifold(contactManifold);
|
||||
contactManifold->m_isAlreadyInIsland = true;
|
||||
|
||||
// Get the other body of the contact manifold
|
||||
@ -728,7 +728,7 @@ void DynamicsWorld::computeIslands() {
|
||||
|
||||
// For each joint in which the current body is involved
|
||||
JointListElement* jointElement;
|
||||
for (jointElement = bodyToVisit->mJointsList; jointElement != NULL;
|
||||
for (jointElement = bodyToVisit->m_jointsList; jointElement != NULL;
|
||||
jointElement = jointElement->next) {
|
||||
|
||||
Joint* joint = jointElement->joint;
|
||||
@ -737,7 +737,7 @@ void DynamicsWorld::computeIslands() {
|
||||
if (joint->isAlreadyInIsland()) continue;
|
||||
|
||||
// Add the joint int32_to the island
|
||||
mIslands[mNbIslands]->addJoint(joint);
|
||||
m_islands[m_numberIslands]->addJoint(joint);
|
||||
joint->m_isAlreadyInIsland = true;
|
||||
|
||||
// Get the other body of the contact manifold
|
||||
@ -757,18 +757,18 @@ void DynamicsWorld::computeIslands() {
|
||||
|
||||
// Reset the isAlreadyIsland variable of the static bodies so that they
|
||||
// can also be included in the other islands
|
||||
for (uint32_t i=0; i < mIslands[mNbIslands]->mNbBodies; i++) {
|
||||
for (uint32_t i=0; i < m_islands[m_numberIslands]->m_numberBodies; i++) {
|
||||
|
||||
if (mIslands[mNbIslands]->mBodies[i]->getType() == STATIC) {
|
||||
mIslands[mNbIslands]->mBodies[i]->m_isAlreadyInIsland = false;
|
||||
if (m_islands[m_numberIslands]->m_bodies[i]->getType() == STATIC) {
|
||||
m_islands[m_numberIslands]->m_bodies[i]->m_isAlreadyInIsland = false;
|
||||
}
|
||||
}
|
||||
|
||||
mNbIslands++;
|
||||
m_numberIslands++;
|
||||
}
|
||||
|
||||
// Release the allocated memory for the stack of bodies to visit
|
||||
mMemoryAllocator.release(stackBodiesToVisit, nbBytesStack);
|
||||
m_memoryAllocator.release(stackBodiesToVisit, nbBytesStack);
|
||||
}
|
||||
|
||||
// Put bodies to sleep if needed.
|
||||
@ -778,17 +778,17 @@ void DynamicsWorld::updateSleepingBodies() {
|
||||
|
||||
PROFILE("DynamicsWorld::updateSleepingBodies()");
|
||||
|
||||
const float sleepLinearVelocitySquare = mSleepLinearVelocity * mSleepLinearVelocity;
|
||||
const float sleepAngularVelocitySquare = mSleepAngularVelocity * mSleepAngularVelocity;
|
||||
const float sleepLinearVelocitySquare = m_sleepLinearVelocity * m_sleepLinearVelocity;
|
||||
const float sleepAngularVelocitySquare = m_sleepAngularVelocity * m_sleepAngularVelocity;
|
||||
|
||||
// For each island of the world
|
||||
for (uint32_t i=0; i<mNbIslands; i++) {
|
||||
for (uint32_t i=0; i<m_numberIslands; i++) {
|
||||
|
||||
float minSleepTime = DECIMAL_LARGEST;
|
||||
|
||||
// For each body of the island
|
||||
RigidBody** bodies = mIslands[i]->getBodies();
|
||||
for (uint32_t b=0; b < mIslands[i]->getNbBodies(); b++) {
|
||||
RigidBody** bodies = m_islands[i]->getBodies();
|
||||
for (uint32_t b=0; b < m_islands[i]->getNbBodies(); b++) {
|
||||
|
||||
// Skip static bodies
|
||||
if (bodies[b]->getType() == STATIC) continue;
|
||||
@ -805,7 +805,7 @@ void DynamicsWorld::updateSleepingBodies() {
|
||||
else { // If the body velocity is bellow the sleeping velocity threshold
|
||||
|
||||
// Increase the sleep time
|
||||
bodies[b]->m_sleepTime += mTimeStep;
|
||||
bodies[b]->m_sleepTime += m_timeStep;
|
||||
if (bodies[b]->m_sleepTime < minSleepTime) {
|
||||
minSleepTime = bodies[b]->m_sleepTime;
|
||||
}
|
||||
@ -815,10 +815,10 @@ void DynamicsWorld::updateSleepingBodies() {
|
||||
// If the velocity of all the bodies of the island is under the
|
||||
// sleeping velocity threshold for a period of time larger than
|
||||
// the time required to become a sleeping body
|
||||
if (minSleepTime >= mTimeBeforeSleep) {
|
||||
if (minSleepTime >= m_timeBeforeSleep) {
|
||||
|
||||
// Put all the bodies of the island to sleep
|
||||
for (uint32_t b=0; b < mIslands[i]->getNbBodies(); b++) {
|
||||
for (uint32_t b=0; b < m_islands[i]->getNbBodies(); b++) {
|
||||
bodies[b]->setIsSleeping(true);
|
||||
}
|
||||
}
|
||||
@ -839,7 +839,7 @@ void DynamicsWorld::enableSleeping(bool isSleepingEnabled) {
|
||||
|
||||
// For each body of the world
|
||||
std::set<RigidBody*>::iterator it;
|
||||
for (it = mRigidBodies.begin(); it != mRigidBodies.end(); ++it) {
|
||||
for (it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) {
|
||||
|
||||
// Wake up the rigid body
|
||||
(*it)->setIsSleeping(false);
|
||||
@ -860,7 +860,7 @@ void DynamicsWorld::testCollision(const ProxyShape* shape,
|
||||
|
||||
// Create the sets of shapes
|
||||
std::set<uint32_t> shapes;
|
||||
shapes.insert(shape->mBroadPhaseID);
|
||||
shapes.insert(shape->m_broadPhaseID);
|
||||
std::set<uint32_t> emptySet;
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
@ -881,9 +881,9 @@ void DynamicsWorld::testCollision(const ProxyShape* shape1,
|
||||
|
||||
// Create the sets of shapes
|
||||
std::set<uint32_t> shapes1;
|
||||
shapes1.insert(shape1->mBroadPhaseID);
|
||||
shapes1.insert(shape1->m_broadPhaseID);
|
||||
std::set<uint32_t> shapes2;
|
||||
shapes2.insert(shape2->mBroadPhaseID);
|
||||
shapes2.insert(shape2->m_broadPhaseID);
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
m_collisionDetection.reportCollisionBetweenShapes(callback, shapes1, shapes2);
|
||||
@ -906,7 +906,7 @@ void DynamicsWorld::testCollision(const CollisionBody* body,
|
||||
// For each shape of the body
|
||||
for (const ProxyShape* shape=body->getProxyShapesList(); shape != NULL;
|
||||
shape = shape->getNext()) {
|
||||
shapes1.insert(shape->mBroadPhaseID);
|
||||
shapes1.insert(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
std::set<uint32_t> emptySet;
|
||||
@ -931,13 +931,13 @@ void DynamicsWorld::testCollision(const CollisionBody* body1,
|
||||
std::set<uint32_t> shapes1;
|
||||
for (const ProxyShape* shape=body1->getProxyShapesList(); shape != NULL;
|
||||
shape = shape->getNext()) {
|
||||
shapes1.insert(shape->mBroadPhaseID);
|
||||
shapes1.insert(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
std::set<uint32_t> shapes2;
|
||||
for (const ProxyShape* shape=body2->getProxyShapesList(); shape != NULL;
|
||||
shape = shape->getNext()) {
|
||||
shapes2.insert(shape->mBroadPhaseID);
|
||||
shapes2.insert(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
@ -965,8 +965,8 @@ std::vector<const ContactManifold*> DynamicsWorld::getContactsList() const {
|
||||
|
||||
// For each currently overlapping pair of bodies
|
||||
std::map<overlappingpairid, OverlappingPair*>::const_iterator it;
|
||||
for (it = m_collisionDetection.mOverlappingPairs.begin();
|
||||
it != m_collisionDetection.mOverlappingPairs.end(); ++it) {
|
||||
for (it = m_collisionDetection.m_overlappingPairs.begin();
|
||||
it != m_collisionDetection.m_overlappingPairs.end(); ++it) {
|
||||
|
||||
OverlappingPair* pair = it->second;
|
||||
|
||||
|
@ -30,79 +30,79 @@ class DynamicsWorld : public CollisionWorld {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Contact solver
|
||||
ContactSolver mContactSolver;
|
||||
ContactSolver m_contactSolver;
|
||||
|
||||
/// Constraint solver
|
||||
ConstraintSolver mConstraintSolver;
|
||||
ConstraintSolver m_constraintSolver;
|
||||
|
||||
/// Number of iterations for the velocity solver of the Sequential Impulses technique
|
||||
uint32_t mNbVelocitySolverIterations;
|
||||
uint32_t m_nbVelocitySolverIterations;
|
||||
|
||||
/// Number of iterations for the position solver of the Sequential Impulses technique
|
||||
uint32_t mNbPositionSolverIterations;
|
||||
uint32_t m_nbPositionSolverIterations;
|
||||
|
||||
/// True if the spleeping technique for inactive bodies is enabled
|
||||
bool m_isSleepingEnabled;
|
||||
|
||||
/// All the rigid bodies of the physics world
|
||||
std::set<RigidBody*> mRigidBodies;
|
||||
std::set<RigidBody*> m_rigidBodies;
|
||||
|
||||
/// All the joints of the world
|
||||
std::set<Joint*> mJoints;
|
||||
std::set<Joint*> m_joints;
|
||||
|
||||
/// Gravity vector of the world
|
||||
Vector3 mGravity;
|
||||
Vector3 m_gravity;
|
||||
|
||||
/// Current frame time step (in seconds)
|
||||
float mTimeStep;
|
||||
float m_timeStep;
|
||||
|
||||
/// True if the gravity force is on
|
||||
bool mIsGravityEnabled;
|
||||
bool m_isGravityEnabled;
|
||||
|
||||
/// Array of constrained linear velocities (state of the linear velocities
|
||||
/// after solving the constraints)
|
||||
Vector3* mConstrainedLinearVelocities;
|
||||
Vector3* m_constrainedLinearVelocities;
|
||||
|
||||
/// Array of constrained angular velocities (state of the angular velocities
|
||||
/// after solving the constraints)
|
||||
Vector3* mConstrainedAngularVelocities;
|
||||
Vector3* m_constrainedAngularVelocities;
|
||||
|
||||
/// Split linear velocities for the position contact solver (split impulse)
|
||||
Vector3* mSplitLinearVelocities;
|
||||
Vector3* m_splitLinearVelocities;
|
||||
|
||||
/// Split angular velocities for the position contact solver (split impulse)
|
||||
Vector3* mSplitAngularVelocities;
|
||||
Vector3* m_splitAngularVelocities;
|
||||
|
||||
/// Array of constrained rigid bodies position (for position error correction)
|
||||
Vector3* mConstrainedPositions;
|
||||
Vector3* m_constrainedPositions;
|
||||
|
||||
/// Array of constrained rigid bodies orientation (for position error correction)
|
||||
Quaternion* mConstrainedOrientations;
|
||||
Quaternion* m_constrainedOrientations;
|
||||
|
||||
/// Map body to their index in the constrained velocities array
|
||||
std::map<RigidBody*, uint32_t> mMapBodyToConstrainedVelocityIndex;
|
||||
std::map<RigidBody*, uint32_t> m_mapBodyToConstrainedVelocityIndex;
|
||||
|
||||
/// Number of islands in the world
|
||||
uint32_t mNbIslands;
|
||||
uint32_t m_numberIslands;
|
||||
|
||||
/// Current allocated capacity for the islands
|
||||
uint32_t mNbIslandsCapacity;
|
||||
uint32_t m_numberIslandsCapacity;
|
||||
|
||||
/// Array with all the islands of awaken bodies
|
||||
Island** mIslands;
|
||||
Island** m_islands;
|
||||
|
||||
/// Current allocated capacity for the bodies
|
||||
uint32_t mNbBodiesCapacity;
|
||||
uint32_t m_numberBodiesCapacity;
|
||||
|
||||
/// Sleep linear velocity threshold
|
||||
float mSleepLinearVelocity;
|
||||
float m_sleepLinearVelocity;
|
||||
|
||||
/// Sleep angular velocity threshold
|
||||
float mSleepAngularVelocity;
|
||||
float m_sleepAngularVelocity;
|
||||
|
||||
/// Time (in seconds) before a body is put to sleep if its velocity
|
||||
/// becomes smaller than the sleep velocity.
|
||||
float mTimeBeforeSleep;
|
||||
float m_timeBeforeSleep;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -160,7 +160,7 @@ class DynamicsWorld : public CollisionWorld {
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
DynamicsWorld(const Vector3& mGravity);
|
||||
DynamicsWorld(const Vector3& m_gravity);
|
||||
|
||||
/// Destructor
|
||||
virtual ~DynamicsWorld();
|
||||
@ -289,7 +289,7 @@ inline void DynamicsWorld::resetBodiesForceAndTorque() {
|
||||
|
||||
// For each body of the world
|
||||
std::set<RigidBody*>::iterator it;
|
||||
for (it = mRigidBodies.begin(); it != mRigidBodies.end(); ++it) {
|
||||
for (it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) {
|
||||
(*it)->mExternalForce.setToZero();
|
||||
(*it)->mExternalTorque.setToZero();
|
||||
}
|
||||
@ -297,7 +297,7 @@ inline void DynamicsWorld::resetBodiesForceAndTorque() {
|
||||
|
||||
// Get the number of iterations for the velocity constraint solver
|
||||
inline uint32_t DynamicsWorld::getNbIterationsVelocitySolver() const {
|
||||
return mNbVelocitySolverIterations;
|
||||
return m_nbVelocitySolverIterations;
|
||||
}
|
||||
|
||||
// Set the number of iterations for the velocity constraint solver
|
||||
@ -305,12 +305,12 @@ inline uint32_t DynamicsWorld::getNbIterationsVelocitySolver() const {
|
||||
* @param nbIterations Number of iterations for the velocity solver
|
||||
*/
|
||||
inline void DynamicsWorld::setNbIterationsVelocitySolver(uint32_t nbIterations) {
|
||||
mNbVelocitySolverIterations = nbIterations;
|
||||
m_nbVelocitySolverIterations = nbIterations;
|
||||
}
|
||||
|
||||
// Get the number of iterations for the position constraint solver
|
||||
inline uint32_t DynamicsWorld::getNbIterationsPositionSolver() const {
|
||||
return mNbPositionSolverIterations;
|
||||
return m_nbPositionSolverIterations;
|
||||
}
|
||||
|
||||
// Set the number of iterations for the position constraint solver
|
||||
@ -318,7 +318,7 @@ inline uint32_t DynamicsWorld::getNbIterationsPositionSolver() const {
|
||||
* @param nbIterations Number of iterations for the position solver
|
||||
*/
|
||||
inline void DynamicsWorld::setNbIterationsPositionSolver(uint32_t nbIterations) {
|
||||
mNbPositionSolverIterations = nbIterations;
|
||||
m_nbPositionSolverIterations = nbIterations;
|
||||
}
|
||||
|
||||
// Set the position correction technique used for contacts
|
||||
@ -328,10 +328,10 @@ inline void DynamicsWorld::setNbIterationsPositionSolver(uint32_t nbIterations)
|
||||
inline void DynamicsWorld::setContactsPositionCorrectionTechnique(
|
||||
ContactsPositionCorrectionTechnique technique) {
|
||||
if (technique == BAUMGARTE_CONTACTS) {
|
||||
mContactSolver.setIsSplitImpulseActive(false);
|
||||
m_contactSolver.setIsSplitImpulseActive(false);
|
||||
}
|
||||
else {
|
||||
mContactSolver.setIsSplitImpulseActive(true);
|
||||
m_contactSolver.setIsSplitImpulseActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,10 +342,10 @@ inline void DynamicsWorld::setContactsPositionCorrectionTechnique(
|
||||
inline void DynamicsWorld::setJointsPositionCorrectionTechnique(
|
||||
JointsPositionCorrectionTechnique technique) {
|
||||
if (technique == BAUMGARTE_JOINTS) {
|
||||
mConstraintSolver.setIsNonLinearGaussSeidelPositionCorrectionActive(false);
|
||||
m_constraintSolver.setIsNonLinearGaussSeidelPositionCorrectionActive(false);
|
||||
}
|
||||
else {
|
||||
mConstraintSolver.setIsNonLinearGaussSeidelPositionCorrectionActive(true);
|
||||
m_constraintSolver.setIsNonLinearGaussSeidelPositionCorrectionActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ inline void DynamicsWorld::setJointsPositionCorrectionTechnique(
|
||||
* the contact manifold and false otherwise
|
||||
*/
|
||||
inline void DynamicsWorld::setIsSolveFrictionAtContactManifoldCenterActive(bool isActive) {
|
||||
mContactSolver.setIsSolveFrictionAtContactManifoldCenterActive(isActive);
|
||||
m_contactSolver.setIsSolveFrictionAtContactManifoldCenterActive(isActive);
|
||||
}
|
||||
|
||||
// Return the gravity vector of the world
|
||||
@ -364,7 +364,7 @@ inline void DynamicsWorld::setIsSolveFrictionAtContactManifoldCenterActive(bool
|
||||
* @return The current gravity vector (in meter per seconds squared)
|
||||
*/
|
||||
inline Vector3 DynamicsWorld::getGravity() const {
|
||||
return mGravity;
|
||||
return m_gravity;
|
||||
}
|
||||
|
||||
// Set the gravity vector of the world
|
||||
@ -372,7 +372,7 @@ inline Vector3 DynamicsWorld::getGravity() const {
|
||||
* @param gravity The gravity vector (in meter per seconds squared)
|
||||
*/
|
||||
inline void DynamicsWorld::setGravity(Vector3& gravity) {
|
||||
mGravity = gravity;
|
||||
m_gravity = gravity;
|
||||
}
|
||||
|
||||
// Return if the gravity is enaled
|
||||
@ -380,7 +380,7 @@ inline void DynamicsWorld::setGravity(Vector3& gravity) {
|
||||
* @return True if the gravity is enabled in the world
|
||||
*/
|
||||
inline bool DynamicsWorld::isGravityEnabled() const {
|
||||
return mIsGravityEnabled;
|
||||
return m_isGravityEnabled;
|
||||
}
|
||||
|
||||
// Enable/Disable the gravity
|
||||
@ -389,7 +389,7 @@ inline bool DynamicsWorld::isGravityEnabled() const {
|
||||
* and false otherwise
|
||||
*/
|
||||
inline void DynamicsWorld::setIsGratityEnabled(bool isGravityEnabled) {
|
||||
mIsGravityEnabled = isGravityEnabled;
|
||||
m_isGravityEnabled = isGravityEnabled;
|
||||
}
|
||||
|
||||
// Return the number of rigid bodies in the world
|
||||
@ -397,7 +397,7 @@ inline void DynamicsWorld::setIsGratityEnabled(bool isGravityEnabled) {
|
||||
* @return Number of rigid bodies in the world
|
||||
*/
|
||||
inline uint32_t DynamicsWorld::getNbRigidBodies() const {
|
||||
return mRigidBodies.size();
|
||||
return m_rigidBodies.size();
|
||||
}
|
||||
|
||||
/// Return the number of joints in the world
|
||||
@ -405,7 +405,7 @@ inline uint32_t DynamicsWorld::getNbRigidBodies() const {
|
||||
* @return Number of joints in the world
|
||||
*/
|
||||
inline uint32_t DynamicsWorld::getNbJoints() const {
|
||||
return mJoints.size();
|
||||
return m_joints.size();
|
||||
}
|
||||
|
||||
// Return an iterator to the beginning of the bodies of the physics world
|
||||
@ -413,7 +413,7 @@ inline uint32_t DynamicsWorld::getNbJoints() const {
|
||||
* @return Starting iterator of the set of rigid bodies
|
||||
*/
|
||||
inline std::set<RigidBody*>::iterator DynamicsWorld::getRigidBodiesBeginIterator() {
|
||||
return mRigidBodies.begin();
|
||||
return m_rigidBodies.begin();
|
||||
}
|
||||
|
||||
// Return an iterator to the end of the bodies of the physics world
|
||||
@ -421,7 +421,7 @@ inline std::set<RigidBody*>::iterator DynamicsWorld::getRigidBodiesBeginIterator
|
||||
* @return Ending iterator of the set of rigid bodies
|
||||
*/
|
||||
inline std::set<RigidBody*>::iterator DynamicsWorld::getRigidBodiesEndIterator() {
|
||||
return mRigidBodies.end();
|
||||
return m_rigidBodies.end();
|
||||
}
|
||||
|
||||
// Return true if the sleeping technique is enabled
|
||||
@ -437,7 +437,7 @@ inline bool DynamicsWorld::isSleepingEnabled() const {
|
||||
* @return The sleep linear velocity (in meters per second)
|
||||
*/
|
||||
inline float DynamicsWorld::getSleepLinearVelocity() const {
|
||||
return mSleepLinearVelocity;
|
||||
return m_sleepLinearVelocity;
|
||||
}
|
||||
|
||||
// Set the sleep linear velocity.
|
||||
@ -449,7 +449,7 @@ inline float DynamicsWorld::getSleepLinearVelocity() const {
|
||||
*/
|
||||
inline void DynamicsWorld::setSleepLinearVelocity(float sleepLinearVelocity) {
|
||||
assert(sleepLinearVelocity >= float(0.0));
|
||||
mSleepLinearVelocity = sleepLinearVelocity;
|
||||
m_sleepLinearVelocity = sleepLinearVelocity;
|
||||
}
|
||||
|
||||
// Return the current sleep angular velocity
|
||||
@ -457,7 +457,7 @@ inline void DynamicsWorld::setSleepLinearVelocity(float sleepLinearVelocity) {
|
||||
* @return The sleep angular velocity (in radian per second)
|
||||
*/
|
||||
inline float DynamicsWorld::getSleepAngularVelocity() const {
|
||||
return mSleepAngularVelocity;
|
||||
return m_sleepAngularVelocity;
|
||||
}
|
||||
|
||||
// Set the sleep angular velocity.
|
||||
@ -469,7 +469,7 @@ inline float DynamicsWorld::getSleepAngularVelocity() const {
|
||||
*/
|
||||
inline void DynamicsWorld::setSleepAngularVelocity(float sleepAngularVelocity) {
|
||||
assert(sleepAngularVelocity >= float(0.0));
|
||||
mSleepAngularVelocity = sleepAngularVelocity;
|
||||
m_sleepAngularVelocity = sleepAngularVelocity;
|
||||
}
|
||||
|
||||
// Return the time a body is required to stay still before sleeping
|
||||
@ -477,7 +477,7 @@ inline void DynamicsWorld::setSleepAngularVelocity(float sleepAngularVelocity) {
|
||||
* @return Time a body is required to stay still before sleeping (in seconds)
|
||||
*/
|
||||
inline float DynamicsWorld::getTimeBeforeSleep() const {
|
||||
return mTimeBeforeSleep;
|
||||
return m_timeBeforeSleep;
|
||||
}
|
||||
|
||||
|
||||
@ -487,7 +487,7 @@ inline float DynamicsWorld::getTimeBeforeSleep() const {
|
||||
*/
|
||||
inline void DynamicsWorld::setTimeBeforeSleep(float timeBeforeSleep) {
|
||||
assert(timeBeforeSleep >= float(0.0));
|
||||
mTimeBeforeSleep = timeBeforeSleep;
|
||||
m_timeBeforeSleep = timeBeforeSleep;
|
||||
}
|
||||
|
||||
// Set an event listener object to receive events callbacks.
|
||||
@ -497,7 +497,7 @@ inline void DynamicsWorld::setTimeBeforeSleep(float timeBeforeSleep) {
|
||||
* event callbacks during the simulation
|
||||
*/
|
||||
inline void DynamicsWorld::setEventListener(EventListener* eventListener) {
|
||||
mEventListener = eventListener;
|
||||
m_eventListener = eventListener;
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,24 +12,24 @@ using namespace reactphysics3d;
|
||||
// Constructor
|
||||
Island::Island(uint32_t nbMaxBodies, uint32_t nbMaxContactManifolds, uint32_t nbMaxJoints,
|
||||
MemoryAllocator& memoryAllocator)
|
||||
: mBodies(NULL), mContactManifolds(NULL), mJoints(NULL), mNbBodies(0),
|
||||
mNbContactManifolds(0), mNbJoints(0), mMemoryAllocator(memoryAllocator) {
|
||||
: m_bodies(NULL), m_contactManifolds(NULL), m_joints(NULL), m_numberBodies(0),
|
||||
m_numberContactManifolds(0), m_numberJoints(0), m_memoryAllocator(memoryAllocator) {
|
||||
|
||||
// Allocate memory for the arrays
|
||||
mNbAllocatedBytesBodies = sizeof(RigidBody*) * nbMaxBodies;
|
||||
mBodies = (RigidBody**) mMemoryAllocator.allocate(mNbAllocatedBytesBodies);
|
||||
mNbAllocatedBytesContactManifolds = sizeof(ContactManifold*) * nbMaxContactManifolds;
|
||||
mContactManifolds = (ContactManifold**) mMemoryAllocator.allocate(
|
||||
mNbAllocatedBytesContactManifolds);
|
||||
mNbAllocatedBytesJoints = sizeof(Joint*) * nbMaxJoints;
|
||||
mJoints = (Joint**) mMemoryAllocator.allocate(mNbAllocatedBytesJoints);
|
||||
m_numberAllocatedBytesBodies = sizeof(RigidBody*) * nbMaxBodies;
|
||||
m_bodies = (RigidBody**) m_memoryAllocator.allocate(m_numberAllocatedBytesBodies);
|
||||
m_numberAllocatedBytesContactManifolds = sizeof(ContactManifold*) * nbMaxContactManifolds;
|
||||
m_contactManifolds = (ContactManifold**) m_memoryAllocator.allocate(
|
||||
m_numberAllocatedBytesContactManifolds);
|
||||
m_numberAllocatedBytesJoints = sizeof(Joint*) * nbMaxJoints;
|
||||
m_joints = (Joint**) m_memoryAllocator.allocate(m_numberAllocatedBytesJoints);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Island::~Island() {
|
||||
|
||||
// Release the memory of the arrays
|
||||
mMemoryAllocator.release(mBodies, mNbAllocatedBytesBodies);
|
||||
mMemoryAllocator.release(mContactManifolds, mNbAllocatedBytesContactManifolds);
|
||||
mMemoryAllocator.release(mJoints, mNbAllocatedBytesJoints);
|
||||
m_memoryAllocator.release(m_bodies, m_numberAllocatedBytesBodies);
|
||||
m_memoryAllocator.release(m_contactManifolds, m_numberAllocatedBytesContactManifolds);
|
||||
m_memoryAllocator.release(m_joints, m_numberAllocatedBytesJoints);
|
||||
}
|
||||
|
@ -25,34 +25,34 @@ class Island {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Array with all the bodies of the island
|
||||
RigidBody** mBodies;
|
||||
RigidBody** m_bodies;
|
||||
|
||||
/// Array with all the contact manifolds between bodies of the island
|
||||
ContactManifold** mContactManifolds;
|
||||
ContactManifold** m_contactManifolds;
|
||||
|
||||
/// Array with all the joints between bodies of the island
|
||||
Joint** mJoints;
|
||||
Joint** m_joints;
|
||||
|
||||
/// Current number of bodies in the island
|
||||
uint32_t mNbBodies;
|
||||
uint32_t m_numberBodies;
|
||||
|
||||
/// Current number of contact manifold in the island
|
||||
uint32_t mNbContactManifolds;
|
||||
uint32_t m_numberContactManifolds;
|
||||
|
||||
/// Current number of joints in the island
|
||||
uint32_t mNbJoints;
|
||||
uint32_t m_numberJoints;
|
||||
|
||||
/// Reference to the memory allocator
|
||||
MemoryAllocator& mMemoryAllocator;
|
||||
MemoryAllocator& m_memoryAllocator;
|
||||
|
||||
/// Number of bytes allocated for the bodies array
|
||||
size_t mNbAllocatedBytesBodies;
|
||||
size_t m_numberAllocatedBytesBodies;
|
||||
|
||||
/// Number of bytes allocated for the contact manifolds array
|
||||
size_t mNbAllocatedBytesContactManifolds;
|
||||
size_t m_numberAllocatedBytesContactManifolds;
|
||||
|
||||
/// Number of bytes allocated for the joints array
|
||||
size_t mNbAllocatedBytesJoints;
|
||||
size_t m_numberAllocatedBytesJoints;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -108,50 +108,50 @@ class Island {
|
||||
// Add a body int32_to the island
|
||||
inline void Island::addBody(RigidBody* body) {
|
||||
assert(!body->isSleeping());
|
||||
mBodies[mNbBodies] = body;
|
||||
mNbBodies++;
|
||||
m_bodies[m_numberBodies] = body;
|
||||
m_numberBodies++;
|
||||
}
|
||||
|
||||
// Add a contact manifold int32_to the island
|
||||
inline void Island::addContactManifold(ContactManifold* contactManifold) {
|
||||
mContactManifolds[mNbContactManifolds] = contactManifold;
|
||||
mNbContactManifolds++;
|
||||
m_contactManifolds[m_numberContactManifolds] = contactManifold;
|
||||
m_numberContactManifolds++;
|
||||
}
|
||||
|
||||
// Add a joint int32_to the island
|
||||
inline void Island::addJoint(Joint* joint) {
|
||||
mJoints[mNbJoints] = joint;
|
||||
mNbJoints++;
|
||||
m_joints[m_numberJoints] = joint;
|
||||
m_numberJoints++;
|
||||
}
|
||||
|
||||
// Return the number of bodies in the island
|
||||
inline uint32_t Island::getNbBodies() const {
|
||||
return mNbBodies;
|
||||
return m_numberBodies;
|
||||
}
|
||||
|
||||
// Return the number of contact manifolds in the island
|
||||
inline uint32_t Island::getNbContactManifolds() const {
|
||||
return mNbContactManifolds;
|
||||
return m_numberContactManifolds;
|
||||
}
|
||||
|
||||
// Return the number of joints in the island
|
||||
inline uint32_t Island::getNbJoints() const {
|
||||
return mNbJoints;
|
||||
return m_numberJoints;
|
||||
}
|
||||
|
||||
// Return a pointer to the array of bodies
|
||||
inline RigidBody** Island::getBodies() {
|
||||
return mBodies;
|
||||
return m_bodies;
|
||||
}
|
||||
|
||||
// Return a pointer to the array of contact manifolds
|
||||
inline ContactManifold** Island::getContactManifold() {
|
||||
return mContactManifolds;
|
||||
return m_contactManifolds;
|
||||
}
|
||||
|
||||
// Return a pointer to the array of joints
|
||||
inline Joint** Island::getJoints() {
|
||||
return mJoints;
|
||||
return m_joints;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,16 +11,16 @@ using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
Material::Material()
|
||||
: mFrictionCoefficient(DEFAULT_FRICTION_COEFFICIENT),
|
||||
mRollingResistance(DEFAULT_ROLLING_RESISTANCE),
|
||||
mBounciness(DEFAULT_BOUNCINESS) {
|
||||
: m_frictionCoefficient(DEFAULT_FRICTION_COEFFICIENT),
|
||||
m_rollingResistance(DEFAULT_ROLLING_RESISTANCE),
|
||||
m_bounciness(DEFAULT_BOUNCINESS) {
|
||||
|
||||
}
|
||||
|
||||
// Copy-constructor
|
||||
Material::Material(const Material& material)
|
||||
: mFrictionCoefficient(material.mFrictionCoefficient),
|
||||
mRollingResistance(material.mRollingResistance), mBounciness(material.mBounciness) {
|
||||
: m_frictionCoefficient(material.m_frictionCoefficient),
|
||||
m_rollingResistance(material.m_rollingResistance), m_bounciness(material.m_bounciness) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ class Material {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Friction coefficient (positive value)
|
||||
float mFrictionCoefficient;
|
||||
float m_frictionCoefficient;
|
||||
|
||||
/// Rolling resistance factor (positive value)
|
||||
float mRollingResistance;
|
||||
float m_rollingResistance;
|
||||
|
||||
/// Bounciness during collisions (between 0 and 1) where 1 is for a very bouncy body
|
||||
float mBounciness;
|
||||
float m_bounciness;
|
||||
|
||||
public :
|
||||
|
||||
@ -72,7 +72,7 @@ class Material {
|
||||
* @return Bounciness factor (between 0 and 1) where 1 is very bouncy
|
||||
*/
|
||||
inline float Material::getBounciness() const {
|
||||
return mBounciness;
|
||||
return m_bounciness;
|
||||
}
|
||||
|
||||
// Set the bounciness.
|
||||
@ -83,7 +83,7 @@ inline float Material::getBounciness() const {
|
||||
*/
|
||||
inline void Material::setBounciness(float bounciness) {
|
||||
assert(bounciness >= float(0.0) && bounciness <= float(1.0));
|
||||
mBounciness = bounciness;
|
||||
m_bounciness = bounciness;
|
||||
}
|
||||
|
||||
// Return the friction coefficient
|
||||
@ -91,7 +91,7 @@ inline void Material::setBounciness(float bounciness) {
|
||||
* @return Friction coefficient (positive value)
|
||||
*/
|
||||
inline float Material::getFrictionCoefficient() const {
|
||||
return mFrictionCoefficient;
|
||||
return m_frictionCoefficient;
|
||||
}
|
||||
|
||||
// Set the friction coefficient.
|
||||
@ -102,7 +102,7 @@ inline float Material::getFrictionCoefficient() const {
|
||||
*/
|
||||
inline void Material::setFrictionCoefficient(float frictionCoefficient) {
|
||||
assert(frictionCoefficient >= float(0.0));
|
||||
mFrictionCoefficient = frictionCoefficient;
|
||||
m_frictionCoefficient = frictionCoefficient;
|
||||
}
|
||||
|
||||
// Return the rolling resistance factor. If this value is larger than zero,
|
||||
@ -112,7 +112,7 @@ inline void Material::setFrictionCoefficient(float frictionCoefficient) {
|
||||
* @return The rolling resistance factor (positive value)
|
||||
*/
|
||||
inline float Material::getRollingResistance() const {
|
||||
return mRollingResistance;
|
||||
return m_rollingResistance;
|
||||
}
|
||||
|
||||
// Set the rolling resistance factor. If this value is larger than zero,
|
||||
@ -123,7 +123,7 @@ inline float Material::getRollingResistance() const {
|
||||
*/
|
||||
inline void Material::setRollingResistance(float rollingResistance) {
|
||||
assert(rollingResistance >= 0);
|
||||
mRollingResistance = rollingResistance;
|
||||
m_rollingResistance = rollingResistance;
|
||||
}
|
||||
|
||||
// Overloaded assignment operator
|
||||
@ -131,9 +131,9 @@ inline Material& Material::operator=(const Material& material) {
|
||||
|
||||
// Check for self-assignment
|
||||
if (this != &material) {
|
||||
mFrictionCoefficient = material.mFrictionCoefficient;
|
||||
mBounciness = material.mBounciness;
|
||||
mRollingResistance = material.mRollingResistance;
|
||||
m_frictionCoefficient = material.m_frictionCoefficient;
|
||||
m_bounciness = material.m_bounciness;
|
||||
m_rollingResistance = material.m_rollingResistance;
|
||||
}
|
||||
|
||||
// Return this material
|
||||
|
@ -12,8 +12,8 @@ using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
OverlappingPair::OverlappingPair(ProxyShape* shape1, ProxyShape* shape2, int32_t nbMaxContactManifolds, MemoryAllocator& memoryAllocator):
|
||||
mContactManifoldSet(shape1, shape2, memoryAllocator, nbMaxContactManifolds),
|
||||
mCachedSeparatingAxis(1.0, 1.0, 1.0) {
|
||||
m_contactManifoldSet(shape1, shape2, memoryAllocator, nbMaxContactManifolds),
|
||||
m_cachedSeparatingAxis(1.0, 1.0, 1.0) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,10 @@ class OverlappingPair {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Set of persistent contact manifolds
|
||||
ContactManifoldSet mContactManifoldSet;
|
||||
ContactManifoldSet m_contactManifoldSet;
|
||||
|
||||
/// Cached previous separating axis
|
||||
Vector3 mCachedSeparatingAxis;
|
||||
Vector3 m_cachedSeparatingAxis;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -95,53 +95,53 @@ class OverlappingPair {
|
||||
|
||||
// Return the pointer to first body
|
||||
inline ProxyShape* OverlappingPair::getShape1() const {
|
||||
return mContactManifoldSet.getShape1();
|
||||
return m_contactManifoldSet.getShape1();
|
||||
}
|
||||
|
||||
// Return the pointer to second body
|
||||
inline ProxyShape* OverlappingPair::getShape2() const {
|
||||
return mContactManifoldSet.getShape2();
|
||||
return m_contactManifoldSet.getShape2();
|
||||
}
|
||||
|
||||
// Add a contact to the contact manifold
|
||||
inline void OverlappingPair::addContact(ContactPoint* contact) {
|
||||
mContactManifoldSet.addContactPoint(contact);
|
||||
m_contactManifoldSet.addContactPoint(contact);
|
||||
}
|
||||
|
||||
// Update the contact manifold
|
||||
inline void OverlappingPair::update() {
|
||||
mContactManifoldSet.update();
|
||||
m_contactManifoldSet.update();
|
||||
}
|
||||
|
||||
// Return the cached separating axis
|
||||
inline Vector3 OverlappingPair::getCachedSeparatingAxis() const {
|
||||
return mCachedSeparatingAxis;
|
||||
return m_cachedSeparatingAxis;
|
||||
}
|
||||
|
||||
// Set the cached separating axis
|
||||
inline void OverlappingPair::setCachedSeparatingAxis(const Vector3& axis) {
|
||||
mCachedSeparatingAxis = axis;
|
||||
m_cachedSeparatingAxis = axis;
|
||||
}
|
||||
|
||||
|
||||
// Return the number of contact points in the contact manifold
|
||||
inline uint32_t OverlappingPair::getNbContactPoints() const {
|
||||
return mContactManifoldSet.getTotalNbContactPoints();
|
||||
return m_contactManifoldSet.getTotalNbContactPoints();
|
||||
}
|
||||
|
||||
// Return the contact manifold
|
||||
inline const ContactManifoldSet& OverlappingPair::getContactManifoldSet() {
|
||||
return mContactManifoldSet;
|
||||
return m_contactManifoldSet;
|
||||
}
|
||||
|
||||
// Return the pair of bodies index
|
||||
inline overlappingpairid OverlappingPair::computeID(ProxyShape* shape1, ProxyShape* shape2) {
|
||||
assert(shape1->mBroadPhaseID >= 0 && shape2->mBroadPhaseID >= 0);
|
||||
assert(shape1->m_broadPhaseID >= 0 && shape2->m_broadPhaseID >= 0);
|
||||
|
||||
// Construct the pair of body index
|
||||
overlappingpairid pairID = shape1->mBroadPhaseID < shape2->mBroadPhaseID ?
|
||||
std::make_pair(shape1->mBroadPhaseID, shape2->mBroadPhaseID) :
|
||||
std::make_pair(shape2->mBroadPhaseID, shape1->mBroadPhaseID);
|
||||
overlappingpairid pairID = shape1->m_broadPhaseID < shape2->m_broadPhaseID ?
|
||||
std::make_pair(shape1->m_broadPhaseID, shape2->m_broadPhaseID) :
|
||||
std::make_pair(shape2->m_broadPhaseID, shape1->m_broadPhaseID);
|
||||
assert(pairID.first != pairID.second);
|
||||
return pairID;
|
||||
}
|
||||
@ -160,7 +160,7 @@ inline bodyindexpair OverlappingPair::computeBodiesIndexPair(CollisionBody* body
|
||||
|
||||
// Clear the contact points of the contact manifold
|
||||
inline void OverlappingPair::clearContactPoints() {
|
||||
mContactManifoldSet.clear();
|
||||
m_contactManifoldSet.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,130 +12,130 @@
|
||||
using namespace reactphysics3d;
|
||||
|
||||
// Initialization of static variables
|
||||
ProfileNode Profiler::mRootNode("Root", NULL);
|
||||
ProfileNode* Profiler::mCurrentNode = &Profiler::mRootNode;
|
||||
long double Profiler::mProfilingStartTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
uint32_t Profiler::mFrameCounter = 0;
|
||||
ProfileNode Profiler::m_rootNode("Root", NULL);
|
||||
ProfileNode* Profiler::m_currentNode = &Profiler::m_rootNode;
|
||||
long double Profiler::m_profilingStartTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
uint32_t Profiler::m_frameCounter = 0;
|
||||
|
||||
// Constructor
|
||||
ProfileNode::ProfileNode(const char* name, ProfileNode* parentNode)
|
||||
:mName(name), mNbTotalCalls(0), mStartingTime(0), mTotalTime(0),
|
||||
mRecursionCounter(0), mParentNode(parentNode), mChildNode(NULL),
|
||||
mSiblingNode(NULL) {
|
||||
:m_name(name), m_numberTotalCalls(0), m_startTime(0), m_totalTime(0),
|
||||
m_recursionCounter(0), m_parentNode(parentNode), m_childNode(NULL),
|
||||
m_siblingNode(NULL) {
|
||||
reset();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
ProfileNode::~ProfileNode() {
|
||||
|
||||
delete mChildNode;
|
||||
delete mSiblingNode;
|
||||
delete m_childNode;
|
||||
delete m_siblingNode;
|
||||
}
|
||||
|
||||
// Return a pointer to a sub node with a given name
|
||||
ProfileNode* ProfileNode::findSubNode(const char* name) {
|
||||
|
||||
// Try to find the node among the child nodes
|
||||
ProfileNode* child = mChildNode;
|
||||
ProfileNode* child = m_childNode;
|
||||
while (child != NULL) {
|
||||
if (child->mName == name) {
|
||||
if (child->m_name == name) {
|
||||
return child;
|
||||
}
|
||||
child = child->mSiblingNode;
|
||||
child = child->m_siblingNode;
|
||||
}
|
||||
|
||||
// The nose has not been found. Therefore, we create it
|
||||
// and add it to the profiler tree
|
||||
ProfileNode* newNode = new ProfileNode(name, this);
|
||||
newNode->mSiblingNode = mChildNode;
|
||||
mChildNode = newNode;
|
||||
newNode->m_siblingNode = m_childNode;
|
||||
m_childNode = newNode;
|
||||
|
||||
return newNode;
|
||||
}
|
||||
|
||||
// Called when we enter the block of code corresponding to this profile node
|
||||
void ProfileNode::enterBlockOfCode() {
|
||||
mNbTotalCalls++;
|
||||
m_numberTotalCalls++;
|
||||
|
||||
// If the current code is not called recursively
|
||||
if (mRecursionCounter == 0) {
|
||||
if (m_recursionCounter == 0) {
|
||||
|
||||
// Get the current system time to initialize the starting time of
|
||||
// the profiling of the current block of code
|
||||
mStartingTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
m_startTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
}
|
||||
|
||||
mRecursionCounter++;
|
||||
m_recursionCounter++;
|
||||
}
|
||||
|
||||
// Called when we exit the block of code corresponding to this profile node
|
||||
bool ProfileNode::exitBlockOfCode() {
|
||||
mRecursionCounter--;
|
||||
m_recursionCounter--;
|
||||
|
||||
if (mRecursionCounter == 0 && mNbTotalCalls != 0) {
|
||||
if (m_recursionCounter == 0 && m_numberTotalCalls != 0) {
|
||||
|
||||
// Get the current system time
|
||||
long double currentTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
|
||||
// Increase the total elasped time in the current block of code
|
||||
mTotalTime += currentTime - mStartingTime;
|
||||
m_totalTime += currentTime - m_startTime;
|
||||
}
|
||||
|
||||
// Return true if the current code is not recursing
|
||||
return (mRecursionCounter == 0);
|
||||
return (m_recursionCounter == 0);
|
||||
}
|
||||
|
||||
// Reset the profiling of the node
|
||||
void ProfileNode::reset() {
|
||||
mNbTotalCalls = 0;
|
||||
mTotalTime = 0.0;
|
||||
m_numberTotalCalls = 0;
|
||||
m_totalTime = 0.0;
|
||||
|
||||
// Reset the child node
|
||||
if (mChildNode != NULL) {
|
||||
mChildNode->reset();
|
||||
if (m_childNode != NULL) {
|
||||
m_childNode->reset();
|
||||
}
|
||||
|
||||
// Reset the sibling node
|
||||
if (mSiblingNode != NULL) {
|
||||
mSiblingNode->reset();
|
||||
if (m_siblingNode != NULL) {
|
||||
m_siblingNode->reset();
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the node
|
||||
void ProfileNode::destroy() {
|
||||
delete mChildNode;
|
||||
mChildNode = NULL;
|
||||
delete mSiblingNode;
|
||||
mSiblingNode = NULL;
|
||||
delete m_childNode;
|
||||
m_childNode = NULL;
|
||||
delete m_siblingNode;
|
||||
m_siblingNode = NULL;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
ProfileNodeIterator::ProfileNodeIterator(ProfileNode* startingNode)
|
||||
:mCurrentParentNode(startingNode),
|
||||
mCurrentChildNode(mCurrentParentNode->getChildNode()){
|
||||
:m_currentParentNode(startingNode),
|
||||
m_currentChildNode(m_currentParentNode->getChildNode()){
|
||||
|
||||
}
|
||||
|
||||
// Enter a given child node
|
||||
void ProfileNodeIterator::enterChild(int32_t index) {
|
||||
mCurrentChildNode = mCurrentParentNode->getChildNode();
|
||||
while ((mCurrentChildNode != NULL) && (index != 0)) {
|
||||
m_currentChildNode = m_currentParentNode->getChildNode();
|
||||
while ((m_currentChildNode != NULL) && (index != 0)) {
|
||||
index--;
|
||||
mCurrentChildNode = mCurrentChildNode->getSiblingNode();
|
||||
m_currentChildNode = m_currentChildNode->getSiblingNode();
|
||||
}
|
||||
|
||||
if (mCurrentChildNode != NULL) {
|
||||
mCurrentParentNode = mCurrentChildNode;
|
||||
mCurrentChildNode = mCurrentParentNode->getChildNode();
|
||||
if (m_currentChildNode != NULL) {
|
||||
m_currentParentNode = m_currentChildNode;
|
||||
m_currentChildNode = m_currentParentNode->getChildNode();
|
||||
}
|
||||
}
|
||||
|
||||
// Enter a given parent node
|
||||
void ProfileNodeIterator::enterParent() {
|
||||
if (mCurrentParentNode->getParentNode() != NULL) {
|
||||
mCurrentParentNode = mCurrentParentNode->getParentNode();
|
||||
if (m_currentParentNode->getParentNode() != NULL) {
|
||||
m_currentParentNode = m_currentParentNode->getParentNode();
|
||||
}
|
||||
mCurrentChildNode = mCurrentParentNode->getChildNode();
|
||||
m_currentChildNode = m_currentParentNode->getChildNode();
|
||||
}
|
||||
|
||||
// Method called when we want to start profiling a block of code.
|
||||
@ -143,12 +143,12 @@ void Profiler::startProfilingBlock(const char* name) {
|
||||
|
||||
// Look for the node in the tree that corresponds to the block of
|
||||
// code to profile
|
||||
if (name != mCurrentNode->getName()) {
|
||||
mCurrentNode = mCurrentNode->findSubNode(name);
|
||||
if (name != m_currentNode->getName()) {
|
||||
m_currentNode = mCurrentNode->findSubNode(name);
|
||||
}
|
||||
|
||||
// Start profile the node
|
||||
mCurrentNode->enterBlockOfCode();
|
||||
m_currentNode->enterBlockOfCode();
|
||||
}
|
||||
|
||||
// Method called at the end of the scope where the
|
||||
@ -157,17 +157,17 @@ void Profiler::stopProfilingBlock() {
|
||||
|
||||
// Go to the parent node unless if the current block
|
||||
// of code is recursing
|
||||
if (mCurrentNode->exitBlockOfCode()) {
|
||||
mCurrentNode = mCurrentNode->getParentNode();
|
||||
if (m_currentNode->exitBlockOfCode()) {
|
||||
m_currentNode = mCurrentNode->getParentNode();
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the timing data of the profiler (but not the profiler tree structure)
|
||||
void Profiler::reset() {
|
||||
mRootNode.reset();
|
||||
mRootNode.enterBlockOfCode();
|
||||
mFrameCounter = 0;
|
||||
mProfilingStartTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
m_rootNode.reset();
|
||||
m_rootNode.enterBlockOfCode();
|
||||
m_frameCounter = 0;
|
||||
m_profilingStartTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
}
|
||||
|
||||
// Print32_t the report of the profiler in a given output stream
|
||||
|
@ -25,28 +25,28 @@ class ProfileNode {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Name of the node
|
||||
const char* mName;
|
||||
const char* m_name;
|
||||
|
||||
/// Total number of calls of this node
|
||||
uint32_t mNbTotalCalls;
|
||||
uint32_t m_numberTotalCalls;
|
||||
|
||||
/// Starting time of the sampling of corresponding block of code
|
||||
long double mStartingTime;
|
||||
long double m_startTime;
|
||||
|
||||
/// Total time spent in the block of code
|
||||
long double mTotalTime;
|
||||
long double m_totalTime;
|
||||
|
||||
/// Recursion counter
|
||||
int32_t mRecursionCounter;
|
||||
int32_t m_recursionCounter;
|
||||
|
||||
/// Pointer to the parent node
|
||||
ProfileNode* mParentNode;
|
||||
ProfileNode* m_parentNode;
|
||||
|
||||
/// Pointer to a child node
|
||||
ProfileNode* mChildNode;
|
||||
ProfileNode* m_childNode;
|
||||
|
||||
/// Pointer to a sibling node
|
||||
ProfileNode* mSiblingNode;
|
||||
ProfileNode* m_siblingNode;
|
||||
|
||||
public :
|
||||
|
||||
@ -103,10 +103,10 @@ class ProfileNodeIterator {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Current parent node
|
||||
ProfileNode* mCurrentParentNode;
|
||||
ProfileNode* m_currentParentNode;
|
||||
|
||||
/// Current child node
|
||||
ProfileNode* mCurrentChildNode;
|
||||
ProfileNode* m_currentChildNode;
|
||||
|
||||
public :
|
||||
|
||||
@ -164,16 +164,16 @@ class Profiler {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Root node of the profiler tree
|
||||
static ProfileNode mRootNode;
|
||||
static ProfileNode m_rootNode;
|
||||
|
||||
/// Current node in the current execution
|
||||
static ProfileNode* mCurrentNode;
|
||||
static ProfileNode* m_currentNode;
|
||||
|
||||
/// Frame counter
|
||||
static uint32_t mFrameCounter;
|
||||
static uint32_t m_frameCounter;
|
||||
|
||||
/// Starting profiling time
|
||||
static long double mProfilingStartTime;
|
||||
static long double m_profilingStartTime;
|
||||
|
||||
/// Recursively print32_t the report of a given node of the profiler tree
|
||||
static void print32_tRecursiveNodeReport(ProfileNodeIterator* iterator,
|
||||
@ -248,103 +248,103 @@ class ProfileSample {
|
||||
|
||||
// Return true if we are at the root of the profiler tree
|
||||
inline bool ProfileNodeIterator::isRoot() {
|
||||
return (mCurrentParentNode->getParentNode() == NULL);
|
||||
return (m_currentParentNode->getParentNode() == NULL);
|
||||
}
|
||||
|
||||
// Return true if we are at the end of a branch of the profiler tree
|
||||
inline bool ProfileNodeIterator::isEnd() {
|
||||
return (mCurrentChildNode == NULL);
|
||||
return (m_currentChildNode == NULL);
|
||||
}
|
||||
|
||||
// Return the name of the current node
|
||||
inline const char* ProfileNodeIterator::getCurrentName() {
|
||||
return mCurrentChildNode->getName();
|
||||
return m_currentChildNode->getName();
|
||||
}
|
||||
|
||||
// Return the total time of the current node
|
||||
inline long double ProfileNodeIterator::getCurrentTotalTime() {
|
||||
return mCurrentChildNode->getTotalTime();
|
||||
return m_currentChildNode->getTotalTime();
|
||||
}
|
||||
|
||||
// Return the total number of calls of the current node
|
||||
inline uint32_t ProfileNodeIterator::getCurrentNbTotalCalls() {
|
||||
return mCurrentChildNode->getNbTotalCalls();
|
||||
return m_currentChildNode->getNbTotalCalls();
|
||||
}
|
||||
|
||||
// Return the name of the current parent node
|
||||
inline const char* ProfileNodeIterator::getCurrentParentName() {
|
||||
return mCurrentParentNode->getName();
|
||||
return m_currentParentNode->getName();
|
||||
}
|
||||
|
||||
// Return the total time of the current parent node
|
||||
inline long double ProfileNodeIterator::getCurrentParentTotalTime() {
|
||||
return mCurrentParentNode->getTotalTime();
|
||||
return m_currentParentNode->getTotalTime();
|
||||
}
|
||||
|
||||
// Return the total number of calls of the current parent node
|
||||
inline uint32_t ProfileNodeIterator::getCurrentParentNbTotalCalls() {
|
||||
return mCurrentParentNode->getNbTotalCalls();
|
||||
return m_currentParentNode->getNbTotalCalls();
|
||||
}
|
||||
|
||||
// Go to the first node
|
||||
inline void ProfileNodeIterator::first() {
|
||||
mCurrentChildNode = mCurrentParentNode->getChildNode();
|
||||
m_currentChildNode = m_currentParentNode->getChildNode();
|
||||
}
|
||||
|
||||
// Go to the next node
|
||||
inline void ProfileNodeIterator::next() {
|
||||
mCurrentChildNode = mCurrentChildNode->getSiblingNode();
|
||||
m_currentChildNode = m_currentChildNode->getSiblingNode();
|
||||
}
|
||||
|
||||
// Return a pointer to the parent node
|
||||
inline ProfileNode* ProfileNode::getParentNode() {
|
||||
return mParentNode;
|
||||
return m_parentNode;
|
||||
}
|
||||
|
||||
// Return a pointer to a sibling node
|
||||
inline ProfileNode* ProfileNode::getSiblingNode() {
|
||||
return mSiblingNode;
|
||||
return m_siblingNode;
|
||||
}
|
||||
|
||||
// Return a pointer to a child node
|
||||
inline ProfileNode* ProfileNode::getChildNode() {
|
||||
return mChildNode;
|
||||
return m_childNode;
|
||||
}
|
||||
|
||||
// Return the name of the node
|
||||
inline const char* ProfileNode::getName() {
|
||||
return mName;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
// Return the total number of call of the corresponding block of code
|
||||
inline uint32_t ProfileNode::getNbTotalCalls() const {
|
||||
return mNbTotalCalls;
|
||||
return m_numberTotalCalls;
|
||||
}
|
||||
|
||||
// Return the total time spent in the block of code
|
||||
inline long double ProfileNode::getTotalTime() const {
|
||||
return mTotalTime;
|
||||
return m_totalTime;
|
||||
}
|
||||
|
||||
// Return the number of frames
|
||||
inline uint32_t Profiler::getNbFrames() {
|
||||
return mFrameCounter;
|
||||
return m_frameCounter;
|
||||
}
|
||||
|
||||
// Return the elasped time since the start/reset of the profiling
|
||||
inline long double Profiler::getElapsedTimeSinceStart() {
|
||||
long double currentTime = Timer::getCurrentSystemTime() * 1000.0;
|
||||
return currentTime - mProfilingStartTime;
|
||||
return currentTime - m_profilingStartTime;
|
||||
}
|
||||
|
||||
// Increment the frame counter
|
||||
inline void Profiler::incrementFrameCounter() {
|
||||
mFrameCounter++;
|
||||
m_frameCounter++;
|
||||
}
|
||||
|
||||
// Return an iterator over the profiler tree starting at the root
|
||||
inline ProfileNodeIterator* Profiler::getIterator() {
|
||||
return new ProfileNodeIterator(&mRootNode);
|
||||
return new ProfileNodeIterator(&m_rootNode);
|
||||
}
|
||||
|
||||
// Destroy a previously allocated iterator
|
||||
@ -354,7 +354,7 @@ inline void Profiler::destroyIterator(ProfileNodeIterator* iterator) {
|
||||
|
||||
// Destroy the profiler (release the memory)
|
||||
inline void Profiler::destroy() {
|
||||
mRootNode.destroy();
|
||||
m_rootNode.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
Timer::Timer(double timeStep) : mTimeStep(timeStep), mIsRunning(false) {
|
||||
Timer::Timer(double timeStep) : m_timeStep(timeStep), mIsRunning(false) {
|
||||
assert(timeStep > 0.0);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Timer {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Timestep dt of the physics engine (timestep > 0.0)
|
||||
double mTimeStep;
|
||||
double m_timeStep;
|
||||
|
||||
/// Last time the timer has been updated
|
||||
long double mLastUpdateTime;
|
||||
@ -104,13 +104,13 @@ class Timer {
|
||||
|
||||
// Return the timestep of the physics engine
|
||||
inline double Timer::getTimeStep() const {
|
||||
return mTimeStep;
|
||||
return m_timeStep;
|
||||
}
|
||||
|
||||
// Set the timestep of the physics engine
|
||||
inline void Timer::setTimeStep(double timeStep) {
|
||||
assert(timeStep > 0.0f);
|
||||
mTimeStep = timeStep;
|
||||
m_timeStep = timeStep;
|
||||
}
|
||||
|
||||
// Return the current time
|
||||
@ -142,7 +142,7 @@ inline void Timer::stop() {
|
||||
|
||||
// True if it's possible to take a new step
|
||||
inline bool Timer::isPossibleToTakeStep() const {
|
||||
return (mAccumulator >= mTimeStep);
|
||||
return (mAccumulator >= m_timeStep);
|
||||
}
|
||||
|
||||
// Take a new step => update the timer by adding the timeStep value to the current time
|
||||
@ -150,12 +150,12 @@ inline void Timer::nextStep() {
|
||||
assert(mIsRunning);
|
||||
|
||||
// Update the accumulator value
|
||||
mAccumulator -= mTimeStep;
|
||||
mAccumulator -= m_timeStep;
|
||||
}
|
||||
|
||||
// Compute the int32_terpolation factor
|
||||
inline float Timer::computeInterpolationFactor() {
|
||||
return (float(mAccumulator / mTimeStep));
|
||||
return (float(mAccumulator / m_timeStep));
|
||||
}
|
||||
|
||||
// Compute the time since the last update() call and add it to the accumulator
|
||||
|
@ -13,44 +13,44 @@ using namespace reactphysics3d;
|
||||
|
||||
// Initialization of static variables
|
||||
bool MemoryAllocator::isMapSizeToHeadIndexInitialized = false;
|
||||
size_t MemoryAllocator::mUnitSizes[NB_HEAPS];
|
||||
int32_t MemoryAllocator::mMapSizeToHeapIndex[MAX_UNIT_SIZE + 1];
|
||||
size_t MemoryAllocator::m_unitSizes[NB_HEAPS];
|
||||
int32_t MemoryAllocator::m_mapSizeToHeapIndex[MAX_UNIT_SIZE + 1];
|
||||
|
||||
// Constructor
|
||||
MemoryAllocator::MemoryAllocator() {
|
||||
|
||||
// Allocate some memory to manage the blocks
|
||||
mNbAllocatedMemoryBlocks = 64;
|
||||
mNbCurrentMemoryBlocks = 0;
|
||||
const size_t sizeToAllocate = mNbAllocatedMemoryBlocks * sizeof(MemoryBlock);
|
||||
mMemoryBlocks = (MemoryBlock*) malloc(sizeToAllocate);
|
||||
memset(mMemoryBlocks, 0, sizeToAllocate);
|
||||
memset(mFreeMemoryUnits, 0, sizeof(mFreeMemoryUnits));
|
||||
m_numberAllocatedMemoryBlocks = 64;
|
||||
m_numberCurrentMemoryBlocks = 0;
|
||||
const size_t sizeToAllocate = m_numberAllocatedMemoryBlocks * sizeof(MemoryBlock);
|
||||
m_memoryBlocks = (MemoryBlock*) malloc(sizeToAllocate);
|
||||
memset(m_memoryBlocks, 0, sizeToAllocate);
|
||||
memset(m_freeMemoryUnits, 0, sizeof(m_freeMemoryUnits));
|
||||
|
||||
#ifndef NDEBUG
|
||||
mNbTimesAllocateMethodCalled = 0;
|
||||
m_numberTimesAllocateMethodCalled = 0;
|
||||
#endif
|
||||
|
||||
// If the mMapSizeToHeapIndex has not been initialized yet
|
||||
// If the m_mapSizeToHeapIndex has not been initialized yet
|
||||
if (!isMapSizeToHeadIndexInitialized) {
|
||||
|
||||
// Initialize the array that contains the sizes the memory units that will
|
||||
// be allocated in each different heap
|
||||
for (int32_t i=0; i < NB_HEAPS; i++) {
|
||||
mUnitSizes[i] = (i+1) * 8;
|
||||
m_unitSizes[i] = (i+1) * 8;
|
||||
}
|
||||
|
||||
// Initialize the lookup table that maps the size to allocated to the
|
||||
// corresponding heap we will use for the allocation
|
||||
uint32_t j = 0;
|
||||
mMapSizeToHeapIndex[0] = -1; // This element should not be used
|
||||
m_mapSizeToHeapIndex[0] = -1; // This element should not be used
|
||||
for (uint32_t i=1; i <= MAX_UNIT_SIZE; i++) {
|
||||
if (i <= mUnitSizes[j]) {
|
||||
mMapSizeToHeapIndex[i] = j;
|
||||
if (i <= m_unitSizes[j]) {
|
||||
m_mapSizeToHeapIndex[i] = j;
|
||||
}
|
||||
else {
|
||||
j++;
|
||||
mMapSizeToHeapIndex[i] = j;
|
||||
m_mapSizeToHeapIndex[i] = j;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,16 +62,16 @@ MemoryAllocator::MemoryAllocator() {
|
||||
MemoryAllocator::~MemoryAllocator() {
|
||||
|
||||
// Release the memory allocated for each block
|
||||
for (uint32_t i=0; i<mNbCurrentMemoryBlocks; i++) {
|
||||
free(mMemoryBlocks[i].memoryUnits);
|
||||
for (uint32_t i=0; i<m_numberCurrentMemoryBlocks; i++) {
|
||||
free(m_memoryBlocks[i].memoryUnits);
|
||||
}
|
||||
|
||||
free(mMemoryBlocks);
|
||||
free(m_memoryBlocks);
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Check that the allocate() and release() methods have been called the same
|
||||
// number of times to avoid memory leaks.
|
||||
assert(mNbTimesAllocateMethodCalled == 0);
|
||||
assert(m_numberTimesAllocateMethodCalled == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ void* MemoryAllocator::allocate(size_t size) {
|
||||
if (size == 0) return NULL;
|
||||
|
||||
#ifndef NDEBUG
|
||||
mNbTimesAllocateMethodCalled++;
|
||||
m_numberTimesAllocateMethodCalled++;
|
||||
#endif
|
||||
|
||||
// If we need to allocate more than the maximum memory unit size
|
||||
@ -94,37 +94,37 @@ void* MemoryAllocator::allocate(size_t size) {
|
||||
}
|
||||
|
||||
// Get the index of the heap that will take care of the allocation request
|
||||
int32_t indexHeap = mMapSizeToHeapIndex[size];
|
||||
int32_t indexHeap = m_mapSizeToHeapIndex[size];
|
||||
assert(indexHeap >= 0 && indexHeap < NB_HEAPS);
|
||||
|
||||
// If there still are free memory units in the corresponding heap
|
||||
if (mFreeMemoryUnits[indexHeap] != NULL) {
|
||||
if (m_freeMemoryUnits[indexHeap] != NULL) {
|
||||
|
||||
// Return a pointer to the memory unit
|
||||
MemoryUnit* unit = mFreeMemoryUnits[indexHeap];
|
||||
mFreeMemoryUnits[indexHeap] = unit->nextUnit;
|
||||
MemoryUnit* unit = m_freeMemoryUnits[indexHeap];
|
||||
m_freeMemoryUnits[indexHeap] = unit->nextUnit;
|
||||
return unit;
|
||||
}
|
||||
else { // If there is no more free memory units in the corresponding heap
|
||||
|
||||
// If we need to allocate more memory to containsthe blocks
|
||||
if (mNbCurrentMemoryBlocks == mNbAllocatedMemoryBlocks) {
|
||||
if (m_numberCurrentMemoryBlocks == m_numberAllocatedMemoryBlocks) {
|
||||
|
||||
// Allocate more memory to contain the blocks
|
||||
MemoryBlock* currentMemoryBlocks = mMemoryBlocks;
|
||||
mNbAllocatedMemoryBlocks += 64;
|
||||
mMemoryBlocks = (MemoryBlock*) malloc(mNbAllocatedMemoryBlocks * sizeof(MemoryBlock));
|
||||
memcpy(mMemoryBlocks, currentMemoryBlocks,mNbCurrentMemoryBlocks * sizeof(MemoryBlock));
|
||||
memset(mMemoryBlocks + mNbCurrentMemoryBlocks, 0, 64 * sizeof(MemoryBlock));
|
||||
MemoryBlock* currentMemoryBlocks = m_memoryBlocks;
|
||||
m_numberAllocatedMemoryBlocks += 64;
|
||||
m_memoryBlocks = (MemoryBlock*) malloc(m_numberAllocatedMemoryBlocks * sizeof(MemoryBlock));
|
||||
memcpy(m_memoryBlocks, currentMemoryBlocks,m_numberCurrentMemoryBlocks * sizeof(MemoryBlock));
|
||||
memset(m_memoryBlocks + m_numberCurrentMemoryBlocks, 0, 64 * sizeof(MemoryBlock));
|
||||
free(currentMemoryBlocks);
|
||||
}
|
||||
|
||||
// Allocate a new memory blocks for the corresponding heap and divide it in many
|
||||
// memory units
|
||||
MemoryBlock* newBlock = mMemoryBlocks + mNbCurrentMemoryBlocks;
|
||||
MemoryBlock* newBlock = m_memoryBlocks + m_numberCurrentMemoryBlocks;
|
||||
newBlock->memoryUnits = (MemoryUnit*) malloc(BLOCK_SIZE);
|
||||
assert(newBlock->memoryUnits != NULL);
|
||||
size_t unitSize = mUnitSizes[indexHeap];
|
||||
size_t unitSize = m_unitSizes[indexHeap];
|
||||
uint32_t nbUnits = BLOCK_SIZE / unitSize;
|
||||
assert(nbUnits * unitSize <= BLOCK_SIZE);
|
||||
for (size_t i=0; i < nbUnits - 1; i++) {
|
||||
@ -136,8 +136,8 @@ void* MemoryAllocator::allocate(size_t size) {
|
||||
lastUnit->nextUnit = NULL;
|
||||
|
||||
// Add the new allocated block int32_to the list of free memory units in the heap
|
||||
mFreeMemoryUnits[indexHeap] = newBlock->memoryUnits->nextUnit;
|
||||
mNbCurrentMemoryBlocks++;
|
||||
m_freeMemoryUnits[indexHeap] = newBlock->memoryUnits->nextUnit;
|
||||
m_numberCurrentMemoryBlocks++;
|
||||
|
||||
// Return the pointer to the first memory unit of the new allocated block
|
||||
return newBlock->memoryUnits;
|
||||
@ -151,7 +151,7 @@ void MemoryAllocator::release(void* pointer, size_t size) {
|
||||
if (size == 0) return;
|
||||
|
||||
#ifndef NDEBUG
|
||||
mNbTimesAllocateMethodCalled--;
|
||||
m_numberTimesAllocateMethodCalled--;
|
||||
#endif
|
||||
|
||||
// If the size is larger than the maximum memory unit size
|
||||
@ -163,12 +163,12 @@ void MemoryAllocator::release(void* pointer, size_t size) {
|
||||
}
|
||||
|
||||
// Get the index of the heap that has handled the corresponding allocation request
|
||||
int32_t indexHeap = mMapSizeToHeapIndex[size];
|
||||
int32_t indexHeap = m_mapSizeToHeapIndex[size];
|
||||
assert(indexHeap >= 0 && indexHeap < NB_HEAPS);
|
||||
|
||||
// Insert the released memory unit int32_to the list of free memory units of the
|
||||
// corresponding heap
|
||||
MemoryUnit* releasedUnit = (MemoryUnit*) pointer;
|
||||
releasedUnit->nextUnit = mFreeMemoryUnits[indexHeap];
|
||||
mFreeMemoryUnits[indexHeap] = releasedUnit;
|
||||
releasedUnit->nextUnit = m_freeMemoryUnits[indexHeap];
|
||||
m_freeMemoryUnits[indexHeap] = releasedUnit;
|
||||
}
|
||||
|
@ -11,112 +11,77 @@
|
||||
|
||||
/// ReactPhysics3D namespace
|
||||
namespace reactphysics3d {
|
||||
|
||||
// Class MemoryAllocator
|
||||
/**
|
||||
* This class is used to efficiently allocate memory on the heap.
|
||||
* It allows us to allocate small blocks of memory (smaller or equal to 1024 bytes)
|
||||
* efficiently. This implementation is inspired by the small block allocator
|
||||
* described here : http://www.codeproject.com/useritems/Small_Block_Allocator.asp
|
||||
*/
|
||||
class MemoryAllocator {
|
||||
|
||||
private :
|
||||
|
||||
// -------------------- Internal Classes -------------------- //
|
||||
|
||||
// Structure MemoryUnit
|
||||
/**
|
||||
* Represent a memory unit that is used for a single memory allocation
|
||||
* request.
|
||||
*/
|
||||
struct MemoryUnit {
|
||||
|
||||
public :
|
||||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Pointer to the next memory unit inside a memory block
|
||||
MemoryUnit* nextUnit;
|
||||
|
||||
};
|
||||
|
||||
// Structure MemoryBlock
|
||||
/**
|
||||
* A memory block is a large piece of memory that is allocated once and that
|
||||
* will contain multiple memory unity.
|
||||
*/
|
||||
struct MemoryBlock {
|
||||
|
||||
public :
|
||||
|
||||
/// Pointer to the first element of a linked-list of memory unity.
|
||||
MemoryUnit* memoryUnits;
|
||||
};
|
||||
|
||||
// -------------------- Constants -------------------- //
|
||||
|
||||
/// Number of heaps
|
||||
static const int32_t NB_HEAPS = 128;
|
||||
|
||||
/// Maximum memory unit size. An allocation request of a size smaller or equal to
|
||||
/// this size will be handled using the small block allocator. However, for an
|
||||
/// allocation request larger than the maximum block size, the standard malloc()
|
||||
/// will be used.
|
||||
static const size_t MAX_UNIT_SIZE = 1024;
|
||||
|
||||
/// Size a memory chunk
|
||||
static const size_t BLOCK_SIZE = 16 * MAX_UNIT_SIZE;
|
||||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Size of the memory units that each heap is responsible to allocate
|
||||
static size_t mUnitSizes[NB_HEAPS];
|
||||
|
||||
/// Lookup table that mape size to allocate to the index of the
|
||||
/// corresponding heap we will use for the allocation.
|
||||
static int32_t mMapSizeToHeapIndex[MAX_UNIT_SIZE + 1];
|
||||
|
||||
/// True if the mMapSizeToHeapIndex array has already been initialized
|
||||
static bool isMapSizeToHeadIndexInitialized;
|
||||
|
||||
/// Pointers to the first free memory unit for each heap
|
||||
MemoryUnit* mFreeMemoryUnits[NB_HEAPS];
|
||||
|
||||
/// All the allocated memory blocks
|
||||
MemoryBlock* mMemoryBlocks;
|
||||
|
||||
/// Number of allocated memory blocks
|
||||
uint32_t mNbAllocatedMemoryBlocks;
|
||||
|
||||
/// Current number of used memory blocks
|
||||
uint32_t mNbCurrentMemoryBlocks;
|
||||
|
||||
#ifndef NDEBUG
|
||||
/// This variable is incremented by one when the allocate() method has been
|
||||
/// called and decreased by one when the release() method has been called.
|
||||
/// This variable is used in debug mode to check that the allocate() and release()
|
||||
/// methods are called the same number of times
|
||||
int32_t mNbTimesAllocateMethodCalled;
|
||||
#endif
|
||||
|
||||
public :
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
MemoryAllocator();
|
||||
|
||||
/// Destructor
|
||||
~MemoryAllocator();
|
||||
|
||||
/// Allocate memory of a given size (in bytes) and return a pointer to the
|
||||
/// allocated memory.
|
||||
void* allocate(size_t size);
|
||||
|
||||
/// Release previously allocated memory.
|
||||
void release(void* pointer, size_t size);
|
||||
|
||||
};
|
||||
|
||||
// Class MemoryAllocator
|
||||
/**
|
||||
* This class is used to efficiently allocate memory on the heap.
|
||||
* It allows us to allocate small blocks of memory (smaller or equal to 1024 bytes)
|
||||
* efficiently. This implementation is inspired by the small block allocator
|
||||
* described here : http://www.codeproject.com/useritems/Small_Block_Allocator.asp
|
||||
*/
|
||||
class MemoryAllocator {
|
||||
private :
|
||||
// Structure MemoryUnit
|
||||
/**
|
||||
* Represent a memory unit that is used for a single memory allocation
|
||||
* request.
|
||||
*/
|
||||
struct MemoryUnit {
|
||||
public :
|
||||
/// Pointer to the next memory unit inside a memory block
|
||||
MemoryUnit* nextUnit;
|
||||
};
|
||||
// Structure MemoryBlock
|
||||
/**
|
||||
* A memory block is a large piece of memory that is allocated once and that
|
||||
* will contain multiple memory unity.
|
||||
*/
|
||||
struct MemoryBlock {
|
||||
public :
|
||||
/// Pointer to the first element of a linked-list of memory unity.
|
||||
MemoryUnit* memoryUnits;
|
||||
};
|
||||
/// Number of heaps
|
||||
static const int32_t NB_HEAPS = 128;
|
||||
/// Maximum memory unit size. An allocation request of a size smaller or equal to
|
||||
/// this size will be handled using the small block allocator. However, for an
|
||||
/// allocation request larger than the maximum block size, the standard malloc()
|
||||
/// will be used.
|
||||
static const size_t MAX_UNIT_SIZE = 1024;
|
||||
/// Size a memory chunk
|
||||
static const size_t BLOCK_SIZE = 16 * MAX_UNIT_SIZE;
|
||||
// -------------------- Attributes -------------------- //
|
||||
/// Size of the memory units that each heap is responsible to allocate
|
||||
static size_t m_unitSizes[NB_HEAPS];
|
||||
/// Lookup table that mape size to allocate to the index of the
|
||||
/// corresponding heap we will use for the allocation.
|
||||
static int32_t m_mapSizeToHeapIndex[MAX_UNIT_SIZE + 1];
|
||||
/// True if the m_mapSizeToHeapIndex array has already been initialized
|
||||
static bool isMapSizeToHeadIndexInitialized;
|
||||
/// Pointers to the first free memory unit for each heap
|
||||
MemoryUnit* m_freeMemoryUnits[NB_HEAPS];
|
||||
/// All the allocated memory blocks
|
||||
MemoryBlock* m_memoryBlocks;
|
||||
/// Number of allocated memory blocks
|
||||
uint32_t m_numberAllocatedMemoryBlocks;
|
||||
/// Current number of used memory blocks
|
||||
uint32_t m_numberCurrentMemoryBlocks;
|
||||
#ifndef NDEBUG
|
||||
/// This variable is incremented by one when the allocate() method has been
|
||||
/// called and decreased by one when the release() method has been called.
|
||||
/// This variable is used in debug mode to check that the allocate() and release()
|
||||
/// methods are called the same number of times
|
||||
int32_t m_numberTimesAllocateMethodCalled;
|
||||
#endif
|
||||
public :
|
||||
// -------------------- Methods -------------------- //
|
||||
/// Constructor
|
||||
MemoryAllocator();
|
||||
/// Destructor
|
||||
~MemoryAllocator();
|
||||
/// Allocate memory of a given size (in bytes) and return a pointer to the
|
||||
/// allocated memory.
|
||||
void* allocate(size_t size);
|
||||
/// Release previously allocated memory.
|
||||
void release(void* pointer, size_t size);
|
||||
};
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ using namespace reactphysics3d;
|
||||
|
||||
/// Constructor
|
||||
Test::Test(const std::string& name, std::ostream* stream)
|
||||
: mName(name), mNbPassedTests(0), mNbFailedTests(0), mOutputStream(stream) {
|
||||
: m_name(name), mNbPassedTests(0), mNbFailedTests(0), mOutputStream(stream) {
|
||||
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ void Test::applyFail(const std::string& testText, const char* filename, long lin
|
||||
if (mOutputStream) {
|
||||
|
||||
// Display the failure message
|
||||
*mOutputStream << mName << " failure : (" << testText << "), " <<
|
||||
*mOutputStream << m_name << " failure : (" << testText << "), " <<
|
||||
filename << "(line " << lineNumber << ")" << std::endl;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ long Test::report() const {
|
||||
|
||||
if(mOutputStream) {
|
||||
*mOutputStream << std::left << std::setw(30) << std::setfill(' ')
|
||||
<< "Test " + mName + " :" << std::setw(10) << "Passed: "
|
||||
<< "Test " + m_name + " :" << std::setw(10) << "Passed: "
|
||||
<< std::setw(8) << mNbPassedTests
|
||||
<< std::setw(13) << "Failed: "
|
||||
<< std::setw(8) << mNbFailedTests << std::endl;
|
||||
|
@ -51,7 +51,7 @@ class Test {
|
||||
// ---------- Attributes ---------- //
|
||||
|
||||
/// Name of the test
|
||||
std::string mName;
|
||||
std::string m_name;
|
||||
|
||||
/// Number of tests that passed
|
||||
long mNbPassedTests;
|
||||
|
@ -30,7 +30,7 @@ using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
TestSuite::TestSuite(const std::string& name, std::ostream* outputStream)
|
||||
: mName(name), mOutputStream(outputStream) {
|
||||
: m_name(name), mOutputStream(outputStream) {
|
||||
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ long TestSuite::report() const {
|
||||
if (mOutputStream != NULL) {
|
||||
long nbFailedTests = 0;
|
||||
|
||||
*mOutputStream << "Test Suite \"" << mName << "\"\n";
|
||||
*mOutputStream << "Test Suite \"" << m_name << "\"\n";
|
||||
size_t i;
|
||||
for (i=0; i < 70; i++) {
|
||||
*mOutputStream << "=";
|
||||
|
@ -48,7 +48,7 @@ class TestSuite {
|
||||
// ---------- Attributes ---------- //
|
||||
|
||||
/// Name of the test suite
|
||||
std::string mName;
|
||||
std::string m_name;
|
||||
|
||||
/// Output stream
|
||||
std::ostream* mOutputStream;
|
||||
@ -108,7 +108,7 @@ class TestSuite {
|
||||
|
||||
// Return the name of the test suite
|
||||
inline std::string TestSuite::getName() const {
|
||||
return mName;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
// Return the output stream
|
||||
|
@ -106,7 +106,7 @@ class TestCollisionWorld : public Test {
|
||||
// ---------- Atributes ---------- //
|
||||
|
||||
// Physics world
|
||||
CollisionWorld* mWorld;
|
||||
CollisionWorld* m_world;
|
||||
|
||||
// Bodies
|
||||
CollisionBody* mBoxBody;
|
||||
@ -126,7 +126,7 @@ class TestCollisionWorld : public Test {
|
||||
ProxyShape* mCylinderProxyShape;
|
||||
|
||||
// Collision callback class
|
||||
WorldCollisionCallback mCollisionCallback;
|
||||
WorldCollisionCallback m_collisionCallback;
|
||||
|
||||
public :
|
||||
|
||||
@ -136,25 +136,25 @@ class TestCollisionWorld : public Test {
|
||||
TestCollisionWorld(const std::string& name) : Test(name) {
|
||||
|
||||
// Create the world
|
||||
mWorld = new CollisionWorld();
|
||||
m_world = new CollisionWorld();
|
||||
|
||||
// Create the bodies
|
||||
Transform boxTransform(Vector3(10, 0, 0), Quaternion::identity());
|
||||
mBoxBody = mWorld->createCollisionBody(boxTransform);
|
||||
mBoxBody = m_world->createCollisionBody(boxTransform);
|
||||
mBoxShape = new BoxShape(Vector3(3, 3, 3));
|
||||
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, Transform::identity());
|
||||
|
||||
mSphereShape = new SphereShape(3.0);
|
||||
Transform sphere1Transform(Vector3(10,5, 0), Quaternion::identity());
|
||||
mSphere1Body = mWorld->createCollisionBody(sphere1Transform);
|
||||
mSphere1Body = m_world->createCollisionBody(sphere1Transform);
|
||||
mSphere1ProxyShape = mSphere1Body->addCollisionShape(mSphereShape, Transform::identity());
|
||||
|
||||
Transform sphere2Transform(Vector3(30, 10, 10), Quaternion::identity());
|
||||
mSphere2Body = mWorld->createCollisionBody(sphere2Transform);
|
||||
mSphere2Body = m_world->createCollisionBody(sphere2Transform);
|
||||
mSphere2ProxyShape = mSphere2Body->addCollisionShape(mSphereShape, Transform::identity());
|
||||
|
||||
Transform cylinderTransform(Vector3(10, -5, 0), Quaternion::identity());
|
||||
mCylinderBody = mWorld->createCollisionBody(cylinderTransform);
|
||||
mCylinderBody = m_world->createCollisionBody(cylinderTransform);
|
||||
mCylinderShape = new CylinderShape(2, 5);
|
||||
mCylinderProxyShape = mCylinderBody->addCollisionShape(mCylinderShape, Transform::identity());
|
||||
|
||||
@ -164,10 +164,10 @@ class TestCollisionWorld : public Test {
|
||||
mSphere2ProxyShape->setCollisionCategoryBits(CATEGORY_2);
|
||||
mCylinderProxyShape->setCollisionCategoryBits(CATEGORY_3);
|
||||
|
||||
mCollisionCallback.boxBody = mBoxBody;
|
||||
mCollisionCallback.sphere1Body = mSphere1Body;
|
||||
mCollisionCallback.sphere2Body = mSphere2Body;
|
||||
mCollisionCallback.cylinderBody = mCylinderBody;
|
||||
m_collisionCallback.boxBody = mBoxBody;
|
||||
m_collisionCallback.sphere1Body = mSphere1Body;
|
||||
m_collisionCallback.sphere2Body = mSphere2Body;
|
||||
m_collisionCallback.cylinderBody = mCylinderBody;
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
@ -185,107 +185,107 @@ class TestCollisionWorld : public Test {
|
||||
|
||||
void testCollisions() {
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(&mCollisionCallback);
|
||||
test(mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(&m_collisionCallback);
|
||||
test(m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
test(mWorld->testAABBOverlap(mBoxBody, mSphere1Body));
|
||||
test(mWorld->testAABBOverlap(mBoxBody, mCylinderBody));
|
||||
test(!mWorld->testAABBOverlap(mSphere1Body, mCylinderBody));
|
||||
test(!mWorld->testAABBOverlap(mSphere1Body, mSphere2Body));
|
||||
test(m_world->testAABBOverlap(mBoxBody, mSphere1Body));
|
||||
test(m_world->testAABBOverlap(mBoxBody, mCylinderBody));
|
||||
test(!m_world->testAABBOverlap(mSphere1Body, mCylinderBody));
|
||||
test(!m_world->testAABBOverlap(mSphere1Body, mSphere2Body));
|
||||
|
||||
test(mWorld->testAABBOverlap(mBoxProxyShape, mSphere1ProxyShape));
|
||||
test(mWorld->testAABBOverlap(mBoxProxyShape, mCylinderProxyShape));
|
||||
test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mCylinderProxyShape));
|
||||
test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mSphere2ProxyShape));
|
||||
test(m_world->testAABBOverlap(mBoxProxyShape, mSphere1ProxyShape));
|
||||
test(m_world->testAABBOverlap(mBoxProxyShape, mCylinderProxyShape));
|
||||
test(!m_world->testAABBOverlap(mSphere1ProxyShape, mCylinderProxyShape));
|
||||
test(!m_world->testAABBOverlap(mSphere1ProxyShape, mSphere2ProxyShape));
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(mCylinderBody, &mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(mCylinderBody, &m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(mBoxBody, mSphere1Body, &mCollisionCallback);
|
||||
test(mCollisionCallback.boxCollideWithSphere1);
|
||||
test(!mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(mBoxBody, mSphere1Body, &m_collisionCallback);
|
||||
test(m_collisionCallback.boxCollideWithSphere1);
|
||||
test(!m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(mBoxBody, mCylinderBody, &mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(mBoxBody, mCylinderBody, &m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(mCylinderProxyShape, &mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(mCylinderProxyShape, &m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(mBoxProxyShape, mCylinderProxyShape, &mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(mBoxProxyShape, mCylinderProxyShape, &m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
// Move sphere 1 to collide with sphere 2
|
||||
mSphere1Body->setTransform(Transform(Vector3(30, 15, 10), Quaternion::identity()));
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(&mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(&m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(mBoxBody, mSphere1Body, &mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(!mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(mBoxBody, mSphere1Body, &m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(!m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(mBoxBody, mCylinderBody, &mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(mBoxBody, mCylinderBody, &m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
// Move sphere 1 to collide with box
|
||||
mSphere1Body->setTransform(Transform(Vector3(10, 5, 0), Quaternion::identity()));
|
||||
|
||||
// --------- Test collision with inactive bodies --------- //
|
||||
|
||||
mCollisionCallback.reset();
|
||||
m_collisionCallback.reset();
|
||||
mBoxBody->setIsActive(false);
|
||||
mCylinderBody->setIsActive(false);
|
||||
mSphere1Body->setIsActive(false);
|
||||
mSphere2Body->setIsActive(false);
|
||||
mWorld->testCollision(&mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(!mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_world->testCollision(&m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(!m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
test(!mWorld->testAABBOverlap(mBoxBody, mSphere1Body));
|
||||
test(!mWorld->testAABBOverlap(mBoxBody, mCylinderBody));
|
||||
test(!mWorld->testAABBOverlap(mSphere1Body, mCylinderBody));
|
||||
test(!mWorld->testAABBOverlap(mSphere1Body, mSphere2Body));
|
||||
test(!m_world->testAABBOverlap(mBoxBody, mSphere1Body));
|
||||
test(!m_world->testAABBOverlap(mBoxBody, mCylinderBody));
|
||||
test(!m_world->testAABBOverlap(mSphere1Body, mCylinderBody));
|
||||
test(!m_world->testAABBOverlap(mSphere1Body, mSphere2Body));
|
||||
|
||||
test(!mWorld->testAABBOverlap(mBoxProxyShape, mSphere1ProxyShape));
|
||||
test(!mWorld->testAABBOverlap(mBoxProxyShape, mCylinderProxyShape));
|
||||
test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mCylinderProxyShape));
|
||||
test(!mWorld->testAABBOverlap(mSphere1ProxyShape, mSphere2ProxyShape));
|
||||
test(!m_world->testAABBOverlap(mBoxProxyShape, mSphere1ProxyShape));
|
||||
test(!m_world->testAABBOverlap(mBoxProxyShape, mCylinderProxyShape));
|
||||
test(!m_world->testAABBOverlap(mSphere1ProxyShape, mCylinderProxyShape));
|
||||
test(!m_world->testAABBOverlap(mSphere1ProxyShape, mSphere2ProxyShape));
|
||||
|
||||
mBoxBody->setIsActive(true);
|
||||
mCylinderBody->setIsActive(true);
|
||||
@ -299,34 +299,34 @@ class TestCollisionWorld : public Test {
|
||||
mSphere2ProxyShape->setCollideWithMaskBits(CATEGORY_1);
|
||||
mCylinderProxyShape->setCollideWithMaskBits(CATEGORY_1);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(&mCollisionCallback);
|
||||
test(mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(&m_collisionCallback);
|
||||
test(m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
// Move sphere 1 to collide with sphere 2
|
||||
mSphere1Body->setTransform(Transform(Vector3(30, 15, 10), Quaternion::identity()));
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(&mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(&m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
mBoxProxyShape->setCollideWithMaskBits(CATEGORY_2);
|
||||
mSphere1ProxyShape->setCollideWithMaskBits(CATEGORY_2);
|
||||
mSphere2ProxyShape->setCollideWithMaskBits(CATEGORY_3);
|
||||
mCylinderProxyShape->setCollideWithMaskBits(CATEGORY_1);
|
||||
|
||||
mCollisionCallback.reset();
|
||||
mWorld->testCollision(&mCollisionCallback);
|
||||
test(!mCollisionCallback.boxCollideWithSphere1);
|
||||
test(!mCollisionCallback.boxCollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithCylinder);
|
||||
test(!mCollisionCallback.sphere1CollideWithSphere2);
|
||||
m_collisionCallback.reset();
|
||||
m_world->testCollision(&m_collisionCallback);
|
||||
test(!m_collisionCallback.boxCollideWithSphere1);
|
||||
test(!m_collisionCallback.boxCollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithCylinder);
|
||||
test(!m_collisionCallback.sphere1CollideWithSphere2);
|
||||
|
||||
// Move sphere 1 to collide with box
|
||||
mSphere1Body->setTransform(Transform(Vector3(10, 5, 0), Quaternion::identity()));
|
||||
|
@ -49,7 +49,7 @@ class TestPointInside : public Test {
|
||||
// ---------- Atributes ---------- //
|
||||
|
||||
// Physics world
|
||||
CollisionWorld* mWorld;
|
||||
CollisionWorld* m_world;
|
||||
|
||||
// Bodies
|
||||
CollisionBody* mBoxBody;
|
||||
@ -71,8 +71,8 @@ class TestPointInside : public Test {
|
||||
CylinderShape* mCylinderShape;
|
||||
|
||||
// Transform
|
||||
Transform mBodyTransform;
|
||||
Transform mShapeTransform;
|
||||
Transform m_bodyTransform;
|
||||
Transform m_shapeTransform;
|
||||
Transform mLocalShapeToWorld;
|
||||
Transform mLocalShape2ToWorld;
|
||||
|
||||
@ -93,43 +93,43 @@ class TestPointInside : public Test {
|
||||
TestPointInside(const std::string& name) : Test(name) {
|
||||
|
||||
// Create the world
|
||||
mWorld = new CollisionWorld();
|
||||
m_world = new CollisionWorld();
|
||||
|
||||
// Body transform
|
||||
Vector3 position(-3, 2, 7);
|
||||
Quaternion orientation(PI / 5, PI / 6, PI / 7);
|
||||
mBodyTransform = Transform(position, orientation);
|
||||
m_bodyTransform = Transform(position, orientation);
|
||||
|
||||
// Create the bodies
|
||||
mBoxBody = mWorld->createCollisionBody(mBodyTransform);
|
||||
mSphereBody = mWorld->createCollisionBody(mBodyTransform);
|
||||
mCapsuleBody = mWorld->createCollisionBody(mBodyTransform);
|
||||
mConeBody = mWorld->createCollisionBody(mBodyTransform);
|
||||
mConvexMeshBody = mWorld->createCollisionBody(mBodyTransform);
|
||||
mConvexMeshBodyEdgesInfo = mWorld->createCollisionBody(mBodyTransform);
|
||||
mCylinderBody = mWorld->createCollisionBody(mBodyTransform);
|
||||
mCompoundBody = mWorld->createCollisionBody(mBodyTransform);
|
||||
mBoxBody = m_world->createCollisionBody(m_bodyTransform);
|
||||
mSphereBody = m_world->createCollisionBody(m_bodyTransform);
|
||||
mCapsuleBody = m_world->createCollisionBody(m_bodyTransform);
|
||||
mConeBody = m_world->createCollisionBody(m_bodyTransform);
|
||||
mConvexMeshBody = m_world->createCollisionBody(m_bodyTransform);
|
||||
mConvexMeshBodyEdgesInfo = m_world->createCollisionBody(m_bodyTransform);
|
||||
mCylinderBody = m_world->createCollisionBody(m_bodyTransform);
|
||||
mCompoundBody = m_world->createCollisionBody(m_bodyTransform);
|
||||
|
||||
// Collision shape transform
|
||||
Vector3 shapePosition(1, -4, -3);
|
||||
Quaternion shapeOrientation(3 * PI / 6 , -PI / 8, PI / 3);
|
||||
mShapeTransform = Transform(shapePosition, shapeOrientation);
|
||||
m_shapeTransform = Transform(shapePosition, shapeOrientation);
|
||||
|
||||
// Compute the the transform from a local shape point to world-space
|
||||
mLocalShapeToWorld = mBodyTransform * mShapeTransform;
|
||||
mLocalShapeToWorld = m_bodyTransform * m_shapeTransform;
|
||||
|
||||
// Create collision shapes
|
||||
mBoxShape = new BoxShape(Vector3(2, 3, 4), 0);
|
||||
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
|
||||
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, m_shapeTransform);
|
||||
|
||||
mSphereShape = new SphereShape(3);
|
||||
mSphereProxyShape = mSphereBody->addCollisionShape(mSphereShape, mShapeTransform);
|
||||
mSphereProxyShape = mSphereBody->addCollisionShape(mSphereShape, m_shapeTransform);
|
||||
|
||||
mCapsuleShape = new CapsuleShape(2, 10);
|
||||
mCapsuleProxyShape = mCapsuleBody->addCollisionShape(mCapsuleShape, mShapeTransform);
|
||||
mCapsuleProxyShape = mCapsuleBody->addCollisionShape(mCapsuleShape, m_shapeTransform);
|
||||
|
||||
mConeShape = new ConeShape(2, 6, 0);
|
||||
mConeProxyShape = mConeBody->addCollisionShape(mConeShape, mShapeTransform);
|
||||
mConeProxyShape = mConeBody->addCollisionShape(mConeShape, m_shapeTransform);
|
||||
|
||||
mConvexMeshShape = new ConvexMeshShape(0.0); // Box of dimension (2, 3, 4)
|
||||
mConvexMeshShape->addVertex(Vector3(-2, -3, -4));
|
||||
@ -140,7 +140,7 @@ class TestPointInside : public Test {
|
||||
mConvexMeshShape->addVertex(Vector3(2, 3, -4));
|
||||
mConvexMeshShape->addVertex(Vector3(2, 3, 4));
|
||||
mConvexMeshShape->addVertex(Vector3(-2, 3, 4));
|
||||
mConvexMeshProxyShape = mConvexMeshBody->addCollisionShape(mConvexMeshShape, mShapeTransform);
|
||||
mConvexMeshProxyShape = mConvexMeshBody->addCollisionShape(mConvexMeshShape, m_shapeTransform);
|
||||
|
||||
mConvexMeshShapeBodyEdgesInfo = new ConvexMeshShape(0.0);
|
||||
mConvexMeshShapeBodyEdgesInfo->addVertex(Vector3(-2, -3, -4));
|
||||
@ -166,17 +166,17 @@ class TestPointInside : public Test {
|
||||
mConvexMeshShapeBodyEdgesInfo->setIsEdgesInformationUsed(true);
|
||||
mConvexMeshProxyShapeEdgesInfo = mConvexMeshBodyEdgesInfo->addCollisionShape(
|
||||
mConvexMeshShapeBodyEdgesInfo,
|
||||
mShapeTransform);
|
||||
m_shapeTransform);
|
||||
|
||||
mCylinderShape = new CylinderShape(3, 8, 0);
|
||||
mCylinderProxyShape = mCylinderBody->addCollisionShape(mCylinderShape, mShapeTransform);
|
||||
mCylinderProxyShape = mCylinderBody->addCollisionShape(mCylinderShape, m_shapeTransform);
|
||||
|
||||
// Compound shape is a cylinder and a sphere
|
||||
Vector3 positionShape2(Vector3(4, 2, -3));
|
||||
Quaternion orientationShape2(-3 *PI / 8, 1.5 * PI/ 3, PI / 13);
|
||||
Transform shapeTransform2(positionShape2, orientationShape2);
|
||||
mLocalShape2ToWorld = mBodyTransform * shapeTransform2;
|
||||
mCompoundBody->addCollisionShape(mCylinderShape, mShapeTransform);
|
||||
mLocalShape2ToWorld = m_bodyTransform * shapeTransform2;
|
||||
mCompoundBody->addCollisionShape(mCylinderShape, m_shapeTransform);
|
||||
mCompoundBody->addCollisionShape(mSphereShape, shapeTransform2);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -47,10 +47,10 @@ class TestTransform : public Test {
|
||||
Transform mIdentityTransform;
|
||||
|
||||
/// First example transform
|
||||
Transform mTransform1;
|
||||
Transform m_transform1;
|
||||
|
||||
/// Second example transform
|
||||
Transform mTransform2;
|
||||
Transform m_transform2;
|
||||
|
||||
public :
|
||||
|
||||
@ -63,11 +63,11 @@ class TestTransform : public Test {
|
||||
|
||||
float sinA = sin(PI/8.0f);
|
||||
float cosA = cos(PI/8.0f);
|
||||
mTransform1 = Transform(Vector3(4, 5, 6), Quaternion(sinA, sinA, sinA, cosA));
|
||||
m_transform1 = Transform(Vector3(4, 5, 6), Quaternion(sinA, sinA, sinA, cosA));
|
||||
|
||||
float sinB = sin(PI/3.0f);
|
||||
float cosB = cos(PI/3.0f);
|
||||
mTransform2 = Transform(Vector3(8, 45, -6), Quaternion(sinB, sinB, sinB, cosB));
|
||||
m_transform2 = Transform(Vector3(8, 45, -6), Quaternion(sinB, sinB, sinB, cosB));
|
||||
}
|
||||
|
||||
/// Run the tests
|
||||
@ -109,9 +109,9 @@ class TestTransform : public Test {
|
||||
|
||||
/// Test the inverse
|
||||
void testInverse() {
|
||||
Transform inverseTransform = mTransform1.getInverse();
|
||||
Transform inverseTransform = m_transform1.getInverse();
|
||||
Vector3 vector(2, 3, 4);
|
||||
Vector3 tempVector = mTransform1 * vector;
|
||||
Vector3 tempVector = m_transform1 * vector;
|
||||
Vector3 tempVector2 = inverseTransform * tempVector;
|
||||
test(approxEqual(tempVector2.x, vector.x, float(10e-6)));
|
||||
test(approxEqual(tempVector2.y, vector.y, float(10e-6)));
|
||||
@ -121,8 +121,8 @@ class TestTransform : public Test {
|
||||
/// Test methods to set and get transform matrix from and to OpenGL
|
||||
void testGetSetOpenGLMatrix() {
|
||||
Transform transform;
|
||||
Vector3 position = mTransform1.getPosition();
|
||||
Matrix3x3 orientation = mTransform1.getOrientation().getMatrix();
|
||||
Vector3 position = m_transform1.getPosition();
|
||||
Matrix3x3 orientation = m_transform1.getOrientation().getMatrix();
|
||||
float openglMatrix[16] = {orientation[0][0], orientation[1][0],
|
||||
orientation[2][0], 0,
|
||||
orientation[0][1], orientation[1][1],
|
||||
@ -153,10 +153,10 @@ class TestTransform : public Test {
|
||||
|
||||
/// Test the method to int32_terpolate transforms
|
||||
void testInterpolateTransform() {
|
||||
Transform transformStart = Transform::int32_terpolateTransforms(mTransform1, mTransform2,0);
|
||||
Transform transformEnd = Transform::int32_terpolateTransforms(mTransform1, mTransform2,1);
|
||||
test(transformStart == mTransform1);
|
||||
test(transformEnd == mTransform2);
|
||||
Transform transformStart = Transform::int32_terpolateTransforms(m_transform1, m_transform2,0);
|
||||
Transform transformEnd = Transform::int32_terpolateTransforms(m_transform1, m_transform2,1);
|
||||
test(transformStart == m_transform1);
|
||||
test(transformEnd == m_transform2);
|
||||
|
||||
float sinA = sin(PI/3.0f);
|
||||
float cosA = cos(PI/3.0f);
|
||||
@ -192,18 +192,18 @@ class TestTransform : public Test {
|
||||
void testOperators() {
|
||||
|
||||
// Equality, inequality operator
|
||||
test(mTransform1 == mTransform1);
|
||||
test(mTransform1 != mTransform2);
|
||||
test(m_transform1 == m_transform1);
|
||||
test(m_transform1 != m_transform2);
|
||||
|
||||
// Assignment operator
|
||||
Transform transform;
|
||||
transform = mTransform1;
|
||||
test(transform == mTransform1);
|
||||
transform = m_transform1;
|
||||
test(transform == m_transform1);
|
||||
|
||||
// Multiplication
|
||||
Vector3 vector(7, 53, 5);
|
||||
Vector3 vector2 = mTransform2 * (mTransform1 * vector);
|
||||
Vector3 vector3 = (mTransform2 * mTransform1) * vector;
|
||||
Vector3 vector2 = m_transform2 * (m_transform1 * vector);
|
||||
Vector3 vector3 = (m_transform2 * m_transform1) * vector;
|
||||
test(approxEqual(vector2.x, vector3.x, float(10e-6)));
|
||||
test(approxEqual(vector2.y, vector3.y, float(10e-6)));
|
||||
test(approxEqual(vector2.z, vector3.z, float(10e-6)));
|
||||
|
@ -142,10 +142,10 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add the collision shape to the body
|
||||
m_proxyShape = mBody->addCollisionShape(mBoxShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(mBoxShape, rp3d::Transform::identity());
|
||||
|
||||
// If the Vertex Buffer object has not been created yet
|
||||
if (totalNbBoxes == 0) {
|
||||
@ -156,7 +156,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p
|
||||
|
||||
totalNbBoxes++;
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
@ -196,7 +196,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3& p
|
||||
// Add the collision shape to the body
|
||||
m_proxyShape = body->addCollisionShape(mBoxShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
// If the Vertex Buffer object has not been created yet
|
||||
if (totalNbBoxes == 0) {
|
||||
@ -207,7 +207,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3& p
|
||||
|
||||
totalNbBoxes++;
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -237,18 +237,18 @@ void Box::render(openglframework::Shader& shader,
|
||||
mVBOVertices.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -315,12 +315,12 @@ void Box::createVBOAndVAO() {
|
||||
void Box::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -100,7 +100,7 @@ class Box : public openglframework::Object3D, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void Box::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,12 +67,12 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body corresponding in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = mBody->addCollisionShape(mCapsuleShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(mCapsuleShape, rp3d::Transform::identity());
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbCapsules == 0) {
|
||||
@ -119,9 +119,9 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = body->addCollisionShape(mCapsuleShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbCapsules == 0) {
|
||||
@ -158,18 +158,18 @@ void Capsule::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -268,12 +268,12 @@ void Capsule::createVBOAndVAO() {
|
||||
void Capsule::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -109,7 +109,7 @@ class Capsule : public openglframework::Mesh, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void Capsule::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -72,15 +72,15 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position,
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body corresponding to the sphere in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
m_proxyShape = mBody->addCollisionShape(mConcaveShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(mConcaveShape, rp3d::Transform::identity());
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
@ -134,12 +134,12 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, float mass,
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
m_proxyShape = body->addCollisionShape(mConcaveShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -171,18 +171,18 @@ void ConcaveMesh::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -281,12 +281,12 @@ void ConcaveMesh::createVBOAndVAO() {
|
||||
void ConcaveMesh::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -102,7 +102,7 @@ class ConcaveMesh : public openglframework::Mesh, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void ConcaveMesh::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -66,12 +66,12 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body corresponding to the cone in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = mBody->addCollisionShape(mConeShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(mConeShape, rp3d::Transform::identity());
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbCones == 0) {
|
||||
@ -117,9 +117,9 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = body->addCollisionShape(mConeShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbCones == 0) {
|
||||
@ -155,18 +155,18 @@ void Cone::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -265,12 +265,12 @@ void Cone::createVBOAndVAO() {
|
||||
void Cone::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -107,7 +107,7 @@ class Cone : public openglframework::Mesh, public PhysicsObject {
|
||||
};
|
||||
|
||||
inline void Cone::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -66,15 +66,15 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body corresponding to the sphere in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
m_proxyShape = mBody->addCollisionShape(mConvexShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(mConvexShape, rp3d::Transform::identity());
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
@ -119,12 +119,12 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass,
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
m_proxyShape = body->addCollisionShape(mConvexShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -152,18 +152,18 @@ void ConvexMesh::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -262,12 +262,12 @@ void ConvexMesh::createVBOAndVAO() {
|
||||
void ConvexMesh::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -101,7 +101,7 @@ class ConvexMesh : public openglframework::Mesh, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void ConvexMesh::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -66,12 +66,12 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body corresponding to the cylinder in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = mBody->addCollisionShape(mCylinderShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(mCylinderShape, rp3d::Transform::identity());
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbCylinders == 0) {
|
||||
@ -117,9 +117,9 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = body->addCollisionShape(mCylinderShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbCylinders == 0) {
|
||||
@ -156,18 +156,18 @@ void Cylinder::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -266,12 +266,12 @@ void Cylinder::createVBOAndVAO() {
|
||||
void Cylinder::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -108,7 +108,7 @@ class Cylinder : public openglframework::Mesh, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void Cylinder::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -71,9 +71,9 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||
rp3d::Vector3 initPosition(position.x, position.y, position.z);
|
||||
rp3d::float angleAroundX = 0;//rp3d::PI / 2;
|
||||
rp3d::Quaternion initOrientation(angleAroundX, 0, 0);
|
||||
rp3d::Transform transformBody(initPosition, initOrientation);
|
||||
rp3d::Transform transform_body(initPosition, initOrientation);
|
||||
|
||||
mPreviousTransform = transformBody;
|
||||
mPreviousTransform = transform_body;
|
||||
|
||||
// Initial transform of the first sphere collision shape of the dumbbell (in local-space)
|
||||
rp3d::Transform transformSphereShape1(rp3d::Vector3(0, mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
|
||||
@ -85,16 +85,16 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||
rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
|
||||
|
||||
// Create a rigid body corresponding to the dumbbell in the dynamics world
|
||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transformBody);
|
||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform_body);
|
||||
|
||||
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
||||
m_proxyShapeSphere1 = body->addCollisionShape(mSphereShape, transformSphereShape1, massSphere);
|
||||
m_proxyShapeSphere2 = body->addCollisionShape(mSphereShape, transformSphereShape2, massSphere);
|
||||
m_proxyShapeCylinder = body->addCollisionShape(mCylinderShape, transformCylinderShape, massCylinder);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbDumbbells == 0) {
|
||||
@ -140,7 +140,7 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||
rp3d::Vector3 initPosition(position.x, position.y, position.z);
|
||||
rp3d::float angleAroundX = 0;//rp3d::PI / 2;
|
||||
rp3d::Quaternion initOrientation(angleAroundX, 0, 0);
|
||||
rp3d::Transform transformBody(initPosition, initOrientation);
|
||||
rp3d::Transform transform_body(initPosition, initOrientation);
|
||||
|
||||
// Initial transform of the first sphere collision shape of the dumbbell (in local-space)
|
||||
rp3d::Transform transformSphereShape1(rp3d::Vector3(0, mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
|
||||
@ -152,14 +152,14 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
||||
rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
|
||||
|
||||
// Create a rigid body corresponding to the dumbbell in the dynamics world
|
||||
mBody = world->createCollisionBody(transformBody);
|
||||
m_body = world->createCollisionBody(transform_body);
|
||||
|
||||
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
||||
m_proxyShapeSphere1 = mBody->addCollisionShape(mSphereShape, transformSphereShape1);
|
||||
m_proxyShapeSphere2 = mBody->addCollisionShape(mSphereShape, transformSphereShape2);
|
||||
m_proxyShapeCylinder = mBody->addCollisionShape(mCylinderShape, transformCylinderShape);
|
||||
m_proxyShapeSphere1 = m_body->addCollisionShape(mSphereShape, transformSphereShape1);
|
||||
m_proxyShapeSphere2 = m_body->addCollisionShape(mSphereShape, transformSphereShape2);
|
||||
m_proxyShapeCylinder = m_body->addCollisionShape(mCylinderShape, transformCylinderShape);
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbDumbbells == 0) {
|
||||
@ -197,18 +197,18 @@ void Dumbbell::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -307,12 +307,12 @@ void Dumbbell::createVBOAndVAO() {
|
||||
void Dumbbell::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -109,7 +109,7 @@ class Dumbbell : public openglframework::Mesh, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void Dumbbell::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -59,15 +59,15 @@ HeightField::HeightField(const openglframework::Vector3 &position,
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body corresponding to the sphere in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
m_proxyShape = mBody->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity());
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
@ -105,12 +105,12 @@ HeightField::HeightField(const openglframework::Vector3 &position, float mass,
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
m_proxyShape = body->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@ -137,18 +137,18 @@ void HeightField::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -324,12 +324,12 @@ void HeightField::createVBOAndVAO() {
|
||||
void HeightField::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -115,7 +115,7 @@ class HeightField : public openglframework::Mesh, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void HeightField::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -29,7 +29,7 @@
|
||||
// Constructor
|
||||
Line::Line(const openglframework::Vector3& worldPoint1,
|
||||
const openglframework::Vector3& worldPoint2)
|
||||
: mWorldPoint1(worldPoint1), mWorldPoint2(worldPoint2) {
|
||||
: m_worldPoint1(worldPoint1), m_worldPoint2(worldPoint2) {
|
||||
|
||||
}
|
||||
|
||||
@ -56,8 +56,8 @@ void Line::render(openglframework::Shader& shader,
|
||||
|
||||
/*
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(mWorldPoint1.x, mWorldPoint1.y, mWorldPoint1.z);
|
||||
glVertex3f(mWorldPoint2.x, mWorldPoint2.y, mWorldPoint2.z);
|
||||
glVertex3f(m_worldPoint1.x, m_worldPoint1.y, m_worldPoint1.z);
|
||||
glVertex3f(m_worldPoint2.x, m_worldPoint2.y, m_worldPoint2.z);
|
||||
glEnd();
|
||||
*/
|
||||
|
||||
|
@ -37,7 +37,7 @@ class Line : public openglframework::Object3D {
|
||||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
openglframework::Vector3 mWorldPoint1, mWorldPoint2;
|
||||
openglframework::Vector3 m_worldPoint1, m_worldPoint2;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
@ -65,12 +65,12 @@ class Line : public openglframework::Object3D {
|
||||
|
||||
// Return the first point of the line
|
||||
inline openglframework::Vector3 Line::getPoint1() const {
|
||||
return mWorldPoint1;
|
||||
return m_worldPoint1;
|
||||
}
|
||||
|
||||
// Return the second point of the line
|
||||
inline openglframework::Vector3 Line::getPoint2() const {
|
||||
return mWorldPoint2;
|
||||
return m_worldPoint2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -38,7 +38,7 @@ openglframework::Matrix4 PhysicsObject::computeTransform(float int32_terpolation
|
||||
const openglframework::Matrix4& scalingMatrix) {
|
||||
|
||||
// Get the transform of the rigid body
|
||||
rp3d::Transform transform = mBody->getTransform();
|
||||
rp3d::Transform transform = m_body->getTransform();
|
||||
|
||||
// Interpolate the transform between the previous one and the new one
|
||||
rp3d::Transform int32_terpolatedTransform = rp3d::Transform::int32_terpolateTransforms(mPreviousTransform,
|
||||
|
@ -36,7 +36,7 @@ class PhysicsObject {
|
||||
protected:
|
||||
|
||||
/// Body used to simulate the dynamics of the box
|
||||
rp3d::CollisionBody* mBody;
|
||||
rp3d::CollisionBody* m_body;
|
||||
|
||||
/// Previous transform of the body (for int32_terpolation)
|
||||
rp3d::Transform mPreviousTransform;
|
||||
@ -87,12 +87,12 @@ inline void PhysicsObject::setSleepingColor(const openglframework::Color& color)
|
||||
|
||||
// Return a pointer to the collision body of the box
|
||||
inline rp3d::CollisionBody* PhysicsObject::getCollisionBody() {
|
||||
return mBody;
|
||||
return m_body;
|
||||
}
|
||||
|
||||
// Return a pointer to the rigid body of the box (NULL if it's not a rigid body)
|
||||
inline rp3d::RigidBody* PhysicsObject::getRigidBody() {
|
||||
return dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
return dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -57,7 +57,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
|
||||
// Create the collision shape for the rigid body (sphere shape)
|
||||
// ReactPhysics3D will clone this object to create an int32_ternal one. Therefore,
|
||||
// it is OK if this object is destroyed right after calling RigidBody::addCollisionShape()
|
||||
mCollisionShape = new rp3d::SphereShape(mRadius);
|
||||
m_collisionShape = new rp3d::SphereShape(mRadius);
|
||||
|
||||
// Initial position and orientation of the rigid body
|
||||
rp3d::Vector3 initPosition(position.x, position.y, position.z);
|
||||
@ -67,12 +67,12 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
|
||||
mPreviousTransform = transform;
|
||||
|
||||
// Create a rigid body corresponding to the sphere in the dynamics world
|
||||
mBody = world->createCollisionBody(transform);
|
||||
m_body = world->createCollisionBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity());
|
||||
m_proxyShape = m_body->addCollisionShape(m_collisionShape, rp3d::Transform::identity());
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbSpheres == 0) {
|
||||
@ -106,7 +106,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
|
||||
// Create the collision shape for the rigid body (sphere shape)
|
||||
// ReactPhysics3D will clone this object to create an int32_ternal one. Therefore,
|
||||
// it is OK if this object is destroyed right after calling RigidBody::addCollisionShape()
|
||||
mCollisionShape = new rp3d::SphereShape(mRadius);
|
||||
m_collisionShape = new rp3d::SphereShape(mRadius);
|
||||
|
||||
// Initial position and orientation of the rigid body
|
||||
rp3d::Vector3 initPosition(position.x, position.y, position.z);
|
||||
@ -117,11 +117,11 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
|
||||
rp3d::RigidBody* body = world->createRigidBody(transform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
m_proxyShape = body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass);
|
||||
m_proxyShape = body->addCollisionShape(m_collisionShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
m_body = body;
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
m_transformMatrix = m_transformMatrix * mScalingMatrix;
|
||||
|
||||
// Create the VBOs and VAO
|
||||
if (totalNbSpheres == 0) {
|
||||
@ -145,7 +145,7 @@ Sphere::~Sphere() {
|
||||
mVBOTextureCoords.destroy();
|
||||
mVAO.destroy();
|
||||
}
|
||||
delete mCollisionShape;
|
||||
delete m_collisionShape;
|
||||
totalNbSpheres--;
|
||||
}
|
||||
|
||||
@ -157,18 +157,18 @@ void Sphere::render(openglframework::Shader& shader,
|
||||
shader.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
||||
// Set the vertex color
|
||||
openglframework::Color currentColor = mBody->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Color currentColor = m_body->isSleeping() ? mSleepingColor : mColor;
|
||||
openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a);
|
||||
shader.setVector4Uniform("vertexColor", color, false);
|
||||
|
||||
@ -267,12 +267,12 @@ void Sphere::createVBOAndVAO() {
|
||||
void Sphere::resetTransform(const rp3d::Transform& transform) {
|
||||
|
||||
// Reset the transform
|
||||
mBody->setTransform(transform);
|
||||
m_body->setTransform(transform);
|
||||
|
||||
mBody->setIsSleeping(false);
|
||||
m_body->setIsSleeping(false);
|
||||
|
||||
// Reset the velocity of the rigid body
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody);
|
||||
rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(m_body);
|
||||
if (rigidBody != NULL) {
|
||||
rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0));
|
||||
rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0));
|
||||
|
@ -42,7 +42,7 @@ class Sphere : public openglframework::Mesh, public PhysicsObject {
|
||||
float mRadius;
|
||||
|
||||
/// Collision shape
|
||||
rp3d::SphereShape* mCollisionShape;
|
||||
rp3d::SphereShape* m_collisionShape;
|
||||
rp3d::ProxyShape* m_proxyShape;
|
||||
|
||||
/// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions)
|
||||
@ -105,7 +105,7 @@ class Sphere : public openglframework::Mesh, public PhysicsObject {
|
||||
|
||||
// Update the transform matrix of the object
|
||||
inline void Sphere::updateTransform(float int32_terpolationFactor) {
|
||||
mTransformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
m_transformMatrix = computeTransform(int32_terpolationFactor, mScalingMatrix);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -96,12 +96,12 @@ void VisualContactPoint::render(openglframework::Shader& shader,
|
||||
mVBOVertices.bind();
|
||||
|
||||
// Set the model to camera matrix
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||
shader.setMatrix4x4Uniform("localToWorldMatrix", m_transformMatrix);
|
||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||
|
||||
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
|
||||
// model-view matrix)
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
|
||||
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * m_transformMatrix;
|
||||
const openglframework::Matrix3 normalMatrix =
|
||||
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
|
||||
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
|
||||
|
@ -79,7 +79,7 @@ void Camera::updateProjectionMatrix() {
|
||||
void Camera::translateCamera(float dx, float dy, const Vector3& worldPoint) {
|
||||
|
||||
// Transform the world point int32_to camera coordinates
|
||||
Vector3 pointCamera = mTransformMatrix.getInverse() * worldPoint;
|
||||
Vector3 pointCamera = m_transformMatrix.getInverse() * worldPoint;
|
||||
|
||||
// Get the depth
|
||||
float z = -pointCamera.z;
|
||||
|
@ -42,7 +42,7 @@ class Object3D {
|
||||
|
||||
// Transformation matrix that convert local-space
|
||||
// coordinates to world-space coordinates
|
||||
Matrix4 mTransformMatrix;
|
||||
Matrix4 m_transformMatrix;
|
||||
|
||||
public:
|
||||
|
||||
@ -87,49 +87,49 @@ class Object3D {
|
||||
|
||||
// Return the transform matrix
|
||||
inline const Matrix4& Object3D::getTransformMatrix() const {
|
||||
return mTransformMatrix;
|
||||
return m_transformMatrix;
|
||||
}
|
||||
|
||||
// Set the transform matrix
|
||||
inline void Object3D::setTransformMatrix(const Matrix4& matrix) {
|
||||
mTransformMatrix = matrix;
|
||||
m_transformMatrix = matrix;
|
||||
}
|
||||
|
||||
// Set to the identity transform
|
||||
inline void Object3D::setToIdentity() {
|
||||
mTransformMatrix.setToIdentity();
|
||||
m_transformMatrix.setToIdentity();
|
||||
}
|
||||
|
||||
// Return the origin of object in world-space
|
||||
inline Vector3 Object3D::getOrigin() const {
|
||||
return mTransformMatrix * Vector3(0.0, 0.0, 0.0);
|
||||
return m_transformMatrix * Vector3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
// Translate the object in world-space
|
||||
inline void Object3D::translateWorld(const Vector3& v) {
|
||||
mTransformMatrix = Matrix4::translationMatrix(v) * mTransformMatrix;
|
||||
m_transformMatrix = Matrix4::translationMatrix(v) * m_transformMatrix;
|
||||
}
|
||||
|
||||
// Translate the object in local-space
|
||||
inline void Object3D::translateLocal(const Vector3& v) {
|
||||
mTransformMatrix = mTransformMatrix * Matrix4::translationMatrix(v);
|
||||
m_transformMatrix = m_transformMatrix * Matrix4::translationMatrix(v);
|
||||
}
|
||||
|
||||
// Rotate the object in world-space
|
||||
inline void Object3D::rotateWorld(const Vector3& axis, float angle) {
|
||||
mTransformMatrix = Matrix4::rotationMatrix(axis, angle) * mTransformMatrix;
|
||||
m_transformMatrix = Matrix4::rotationMatrix(axis, angle) * m_transformMatrix;
|
||||
}
|
||||
|
||||
// Rotate the object in local-space
|
||||
inline void Object3D::rotateLocal(const Vector3& axis, float angle) {
|
||||
mTransformMatrix = mTransformMatrix * Matrix4::rotationMatrix(axis, angle);
|
||||
m_transformMatrix = m_transformMatrix * Matrix4::rotationMatrix(axis, angle);
|
||||
}
|
||||
|
||||
// Rotate the object around a world-space point
|
||||
inline void Object3D::rotateAroundWorldPoint(const Vector3& axis, float angle,
|
||||
const Vector3& worldPoint) {
|
||||
mTransformMatrix = Matrix4::translationMatrix(worldPoint) * Matrix4::rotationMatrix(axis, angle)
|
||||
* Matrix4::translationMatrix(-worldPoint) * mTransformMatrix;
|
||||
m_transformMatrix = Matrix4::translationMatrix(worldPoint) * Matrix4::rotationMatrix(axis, angle)
|
||||
* Matrix4::translationMatrix(-worldPoint) * m_transformMatrix;
|
||||
}
|
||||
|
||||
// Rotate the object around a local-space point
|
||||
@ -137,9 +137,9 @@ inline void Object3D::rotateAroundLocalPoint(const Vector3& axis, float angle,
|
||||
const Vector3& worldPoint) {
|
||||
|
||||
// Convert the world point int32_to the local coordinate system
|
||||
Vector3 localPoint = mTransformMatrix.getInverse() * worldPoint;
|
||||
Vector3 localPoint = m_transformMatrix.getInverse() * worldPoint;
|
||||
|
||||
mTransformMatrix = mTransformMatrix * Matrix4::translationMatrix(localPoint)
|
||||
m_transformMatrix = m_transformMatrix * Matrix4::translationMatrix(localPoint)
|
||||
* Matrix4::rotationMatrix(axis, angle)
|
||||
* Matrix4::translationMatrix(-localPoint);
|
||||
}
|
||||
|
@ -296,8 +296,8 @@ void JointsScene::createBallAndSocketJoints() {
|
||||
rp3d::RigidBody* body2 = mBallAndSocketJointChainBoxes[i+1]->getRigidBody();
|
||||
rp3d::Vector3 body1Position = body1->getTransform().getPosition();
|
||||
rp3d::Vector3 body2Position = body2->getTransform().getPosition();
|
||||
const rp3d::Vector3 m_m_m_m_anchorPointWorldSpace = 0.5 * (body1Position + body2Position);
|
||||
rp3d::BallAndSocketJointInfo jointInfo(body1, body2, m_m_m_m_anchorPointWorldSpace);
|
||||
const rp3d::Vector3 m_anchorPointWorldSpace = 0.5 * (body1Position + body2Position);
|
||||
rp3d::BallAndSocketJointInfo jointInfo(body1, body2, m_anchorPointWorldSpace);
|
||||
|
||||
// Create the joint in the dynamics world
|
||||
mBallAndSocketJoints[i] = dynamic_cast<rp3d::BallAndSocketJoint*>(
|
||||
@ -352,9 +352,9 @@ void JointsScene::createSliderJoint() {
|
||||
rp3d::RigidBody* body2 = mSliderJointTopBox->getRigidBody();
|
||||
const rp3d::Vector3& body1Position = body1->getTransform().getPosition();
|
||||
const rp3d::Vector3& body2Position = body2->getTransform().getPosition();
|
||||
const rp3d::Vector3 m_m_m_m_anchorPointWorldSpace = rp3d::float(0.5) * (body2Position + body1Position);
|
||||
const rp3d::Vector3 m_anchorPointWorldSpace = rp3d::float(0.5) * (body2Position + body1Position);
|
||||
const rp3d::Vector3 sliderAxisWorldSpace = (body2Position - body1Position);
|
||||
rp3d::SliderJointInfo jointInfo(body1, body2, m_m_m_m_anchorPointWorldSpace, sliderAxisWorldSpace,
|
||||
rp3d::SliderJointInfo jointInfo(body1, body2, m_anchorPointWorldSpace, sliderAxisWorldSpace,
|
||||
rp3d::float(-1.7), rp3d::float(1.7));
|
||||
jointInfo.isMotorEnabled = true;
|
||||
jointInfo.motorSpeed = 0.0;
|
||||
@ -392,9 +392,9 @@ void JointsScene::createPropellerHingeJoint() {
|
||||
rp3d::RigidBody* body2 = mSliderJointTopBox->getRigidBody();
|
||||
const rp3d::Vector3& body1Position = body1->getTransform().getPosition();
|
||||
const rp3d::Vector3& body2Position = body2->getTransform().getPosition();
|
||||
const rp3d::Vector3 m_m_m_m_anchorPointWorldSpace = 0.5 * (body2Position + body1Position);
|
||||
const rp3d::Vector3 m_anchorPointWorldSpace = 0.5 * (body2Position + body1Position);
|
||||
const rp3d::Vector3 hingeAxisWorldSpace(0, 1, 0);
|
||||
rp3d::HingeJointInfo jointInfo(body1, body2, m_m_m_m_anchorPointWorldSpace, hingeAxisWorldSpace);
|
||||
rp3d::HingeJointInfo jointInfo(body1, body2, m_anchorPointWorldSpace, hingeAxisWorldSpace);
|
||||
jointInfo.isMotorEnabled = true;
|
||||
jointInfo.motorSpeed = - rp3d::float(0.5) * PI;
|
||||
jointInfo.maxMotorTorque = rp3d::float(60.0);
|
||||
@ -445,8 +445,8 @@ void JointsScene::createFixedJoints() {
|
||||
// Create the joint info object
|
||||
rp3d::RigidBody* body1 = mFixedJointBox1->getRigidBody();
|
||||
rp3d::RigidBody* propellerBody = mPropellerBox->getRigidBody();
|
||||
const rp3d::Vector3 m_m_m_m_anchorPointWorldSpace1(5, 7, 0);
|
||||
rp3d::FixedJointInfo jointInfo1(body1, propellerBody, m_m_m_m_anchorPointWorldSpace1);
|
||||
const rp3d::Vector3 m_anchorPointWorldSpace1(5, 7, 0);
|
||||
rp3d::FixedJointInfo jointInfo1(body1, propellerBody, m_anchorPointWorldSpace1);
|
||||
jointInfo1.isCollisionEnabled = false;
|
||||
|
||||
// Create the joint in the dynamics world
|
||||
@ -456,8 +456,8 @@ void JointsScene::createFixedJoints() {
|
||||
|
||||
// Create the joint info object
|
||||
rp3d::RigidBody* body2 = mFixedJointBox2->getRigidBody();
|
||||
const rp3d::Vector3 m_m_m_m_anchorPointWorldSpace2(-5, 7, 0);
|
||||
rp3d::FixedJointInfo jointInfo2(body2, propellerBody, m_m_m_m_anchorPointWorldSpace2);
|
||||
const rp3d::Vector3 m_anchorPointWorldSpace2(-5, 7, 0);
|
||||
rp3d::FixedJointInfo jointInfo2(body2, propellerBody, m_anchorPointWorldSpace2);
|
||||
jointInfo2.isCollisionEnabled = false;
|
||||
|
||||
// Create the joint in the dynamics world
|
||||
|
@ -31,7 +31,7 @@ using namespace openglframework;
|
||||
|
||||
// Constructor
|
||||
Scene::Scene(const std::string& name, bool isShadowMappingEnabled)
|
||||
: mName(name), mInterpolationFactor(0.0f), mViewportX(0), mViewportY(0),
|
||||
: m_name(name), mInterpolationFactor(0.0f), mViewportX(0), mViewportY(0),
|
||||
mViewportWidth(0), mViewportHeight(0), mIsShadowMappingEnabled(isShadowMappingEnabled),
|
||||
mIsContactPointsDisplayed(true) {
|
||||
|
||||
|
@ -73,7 +73,7 @@ class Scene {
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Scene name
|
||||
std::string mName;
|
||||
std::string m_name;
|
||||
|
||||
/// Physics engine settings
|
||||
EngineSettings mEngineSettings;
|
||||
@ -249,7 +249,7 @@ inline void Scene::setInterpolationFactor(float int32_terpolationFactor) {
|
||||
|
||||
// Return the name of the scene
|
||||
inline std::string Scene::getName() const {
|
||||
return mName;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
// Return true if the shadow mapping is enabled
|
||||
|
@ -290,7 +290,7 @@ void SceneDemo::updateContactPoints() {
|
||||
|
||||
// Create a visual contact point for rendering
|
||||
VisualContactPoint* point = new VisualContactPoint(it->point, mMeshFolderPath);
|
||||
mContactPoints.push_back(point);
|
||||
m_contactPoints.push_back(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -300,8 +300,8 @@ void SceneDemo::renderContactPoints(openglframework::Shader& shader,
|
||||
const openglframework::Matrix4& worldToCameraMatrix) {
|
||||
|
||||
// Render all the raycast hit points
|
||||
for (std::vector<VisualContactPoint*>::iterator it = mContactPoints.begin();
|
||||
it != mContactPoints.end(); ++it) {
|
||||
for (std::vector<VisualContactPoint*>::iterator it = m_contactPoints.begin();
|
||||
it != m_contactPoints.end(); ++it) {
|
||||
(*it)->render(shader, worldToCameraMatrix);
|
||||
}
|
||||
}
|
||||
@ -309,11 +309,11 @@ void SceneDemo::renderContactPoints(openglframework::Shader& shader,
|
||||
void SceneDemo::removeAllContactPoints() {
|
||||
|
||||
// Destroy all the visual contact points
|
||||
for (std::vector<VisualContactPoint*>::iterator it = mContactPoints.begin();
|
||||
it != mContactPoints.end(); ++it) {
|
||||
for (std::vector<VisualContactPoint*>::iterator it = m_contactPoints.begin();
|
||||
it != m_contactPoints.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
mContactPoints.clear();
|
||||
m_contactPoints.clear();
|
||||
}
|
||||
|
||||
// Return all the contact points of the scene
|
||||
|
@ -59,7 +59,7 @@ class SceneDemo : public Scene {
|
||||
static int32_t shadowMapTextureLevel;
|
||||
|
||||
/// All the visual contact points
|
||||
std::vector<VisualContactPoint*> mContactPoints;
|
||||
std::vector<VisualContactPoint*> m_contactPoints;
|
||||
|
||||
/// Shadow map bias matrix
|
||||
openglframework::Matrix4 mShadowMapBiasMatrix;
|
||||
|
Loading…
x
Reference in New Issue
Block a user