diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2007-07-16 09:56:51 +0400 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2007-07-16 09:56:51 +0400 |
commit | 3792ae1560790f2d464197f5f86983ad970b9c9c (patch) | |
tree | 99025fbb39c7560d3ac87e86d0d084e4e65ef705 /source/gameengine | |
parent | 044b3544584039e5618ee95ee6751e0620ae3033 (diff) |
bugfixes for generic (experimental) Bullet rigidbody constraint: use cone-twist instead (needs a few more minor fixes)
Note: Visual Studio projectfiles and other buildsystems need to add extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp to the project!
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 68 | ||||
-rw-r--r-- | source/gameengine/Physics/common/PHY_DynamicTypes.h | 1 |
2 files changed, 69 insertions, 0 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index bc69fe85eff..99c3e5f77c7 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -1137,6 +1137,74 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl break; } + case PHY_CONE_TWIST_CONSTRAINT: + { + btConeTwistConstraint* coneTwistContraint = 0; + + + if (rb1) + { + btTransform frameInA; + btTransform frameInB; + + btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z); + if (axis1.length() == 0.0) + { + btPlaneSpace1( axisInA, axis1, axis2 ); + } + + frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(), + axisInA.y(), axis1.y(), axis2.y(), + axisInA.z(), axis1.z(), axis2.z() ); + frameInA.setOrigin( pivotInA ); + + btTransform inv = rb1->getCenterOfMassTransform().inverse(); + + btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA; + + frameInB = inv * globalFrameA; + + coneTwistContraint = new btConeTwistConstraint( *rb0,*rb1, + frameInA,frameInB); + + + } else + { + static btRigidBody s_fixedObject2( 0,0,0); + btTransform frameInA; + btTransform frameInB; + + btVector3 axis1, axis2; + btPlaneSpace1( axisInA, axis1, axis2 ); + + frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(), + axisInA.y(), axis1.y(), axis2.y(), + axisInA.z(), axis1.z(), axis2.z() ); + + frameInA.setOrigin( pivotInA ); + + ///frameInB in worldspace + frameInB = rb0->getCenterOfMassTransform() * frameInA; + + coneTwistContraint = new btConeTwistConstraint( + *rb0,s_fixedObject2, + frameInA,frameInB); + } + + if (coneTwistContraint) + { + //m_constraints.push_back(genericConstraint); + m_dynamicsWorld->addConstraint(coneTwistContraint); + coneTwistContraint->setUserConstraintId(gConstraintUid++); + coneTwistContraint->setUserConstraintType(type); + //64 bit systems can't cast pointer to int. could use size_t instead. + return coneTwistContraint->getUserConstraintId(); + } + + + + break; + } case PHY_ANGULAR_CONSTRAINT: angularOnly = true; diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index 3952377181a..68b60192fbc 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -81,6 +81,7 @@ typedef enum PHY_ConstraintType { PHY_POINT2POINT_CONSTRAINT=1, PHY_LINEHINGE_CONSTRAINT=2, PHY_ANGULAR_CONSTRAINT = 3,//hinge without ball socket + PHY_CONE_TWIST_CONSTRAINT = 4, PHY_VEHICLE_CONSTRAINT=11,//complex 'constraint' that turns a rigidbody into a vehicle PHY_GENERIC_6DOF_CONSTRAINT=12,//can leave any of the 6 degree of freedom 'free' or 'locked' |