Blender V2.61 - r43446

btContactConstraint.cpp

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 
00017 #include "btContactConstraint.h"
00018 #include "BulletDynamics/Dynamics/btRigidBody.h"
00019 #include "LinearMath/btVector3.h"
00020 #include "btJacobianEntry.h"
00021 #include "btContactSolverInfo.h"
00022 #include "LinearMath/btMinMax.h"
00023 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
00024 
00025 
00026 
00027 btContactConstraint::btContactConstraint(btPersistentManifold* contactManifold,btRigidBody& rbA,btRigidBody& rbB)
00028 :btTypedConstraint(CONTACT_CONSTRAINT_TYPE,rbA,rbB),
00029     m_contactManifold(*contactManifold)
00030 {
00031 
00032 }
00033 
00034 btContactConstraint::~btContactConstraint()
00035 {
00036 
00037 }
00038 
00039 void    btContactConstraint::setContactManifold(btPersistentManifold* contactManifold)
00040 {
00041     m_contactManifold = *contactManifold;
00042 }
00043 
00044 void btContactConstraint::getInfo1 (btConstraintInfo1* info)
00045 {
00046 
00047 }
00048 
00049 void btContactConstraint::getInfo2 (btConstraintInfo2* info)
00050 {
00051 
00052 }
00053 
00054 void    btContactConstraint::buildJacobian()
00055 {
00056 
00057 }
00058 
00059 
00060 
00061 
00062 
00063 #include "btContactConstraint.h"
00064 #include "BulletDynamics/Dynamics/btRigidBody.h"
00065 #include "LinearMath/btVector3.h"
00066 #include "btJacobianEntry.h"
00067 #include "btContactSolverInfo.h"
00068 #include "LinearMath/btMinMax.h"
00069 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
00070 
00071 #define ASSERT2 btAssert
00072 
00073 #define USE_INTERNAL_APPLY_IMPULSE 1
00074 
00075 
00076 //bilateral constraint between two dynamic objects
00077 void resolveSingleBilateral(btRigidBody& body1, const btVector3& pos1,
00078                       btRigidBody& body2, const btVector3& pos2,
00079                       btScalar distance, const btVector3& normal,btScalar& impulse ,btScalar timeStep)
00080 {
00081     (void)timeStep;
00082     (void)distance;
00083 
00084 
00085     btScalar normalLenSqr = normal.length2();
00086     ASSERT2(btFabs(normalLenSqr) < btScalar(1.1));
00087     if (normalLenSqr > btScalar(1.1))
00088     {
00089         impulse = btScalar(0.);
00090         return;
00091     }
00092     btVector3 rel_pos1 = pos1 - body1.getCenterOfMassPosition(); 
00093     btVector3 rel_pos2 = pos2 - body2.getCenterOfMassPosition();
00094     //this jacobian entry could be re-used for all iterations
00095     
00096     btVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1);
00097     btVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2);
00098     btVector3 vel = vel1 - vel2;
00099     
00100 
00101        btJacobianEntry jac(body1.getCenterOfMassTransform().getBasis().transpose(),
00102         body2.getCenterOfMassTransform().getBasis().transpose(),
00103         rel_pos1,rel_pos2,normal,body1.getInvInertiaDiagLocal(),body1.getInvMass(),
00104         body2.getInvInertiaDiagLocal(),body2.getInvMass());
00105 
00106     btScalar jacDiagAB = jac.getDiagonal();
00107     btScalar jacDiagABInv = btScalar(1.) / jacDiagAB;
00108     
00109       btScalar rel_vel = jac.getRelativeVelocity(
00110         body1.getLinearVelocity(),
00111         body1.getCenterOfMassTransform().getBasis().transpose() * body1.getAngularVelocity(),
00112         body2.getLinearVelocity(),
00113         body2.getCenterOfMassTransform().getBasis().transpose() * body2.getAngularVelocity()); 
00114     btScalar a;
00115     a=jacDiagABInv;
00116 
00117 
00118     rel_vel = normal.dot(vel);
00119     
00120     //todo: move this into proper structure
00121     btScalar contactDamping = btScalar(0.2);
00122 
00123 #ifdef ONLY_USE_LINEAR_MASS
00124     btScalar massTerm = btScalar(1.) / (body1.getInvMass() + body2.getInvMass());
00125     impulse = - contactDamping * rel_vel * massTerm;
00126 #else   
00127     btScalar velocityImpulse = -contactDamping * rel_vel * jacDiagABInv;
00128     impulse = velocityImpulse;
00129 #endif
00130 }
00131 
00132 
00133 
00134