diff options
author | Joseph Eagar <joeedh@gmail.com> | 2011-04-15 05:19:13 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2011-04-15 05:19:13 +0400 |
commit | c98148a963d37fc2f25e125afeb4cf21df6fbf14 (patch) | |
tree | 691a051e27f08e35bf09d35b6fb9c88e4c37b8d2 /source/gameengine/Physics/Bullet | |
parent | 0bba684d08952d0be822f3906ffb2a03b2674cc2 (diff) | |
parent | fa63c297753636c149fbb1a3877d9b3d93601357 (diff) |
=bmesh= merge from trunk at r36153
Diffstat (limited to 'source/gameengine/Physics/Bullet')
4 files changed, 130 insertions, 12 deletions
diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt index c677685de49..cc469c3772a 100644 --- a/source/gameengine/Physics/Bullet/CMakeLists.txt +++ b/source/gameengine/Physics/Bullet/CMakeLists.txt @@ -31,7 +31,6 @@ set(INC . ../common ../../../../extern/bullet2/src - ../../../../extern/glew/include ../../../../intern/moto/include ../../../../intern/guardedalloc ../../../kernel/gen_system @@ -44,6 +43,7 @@ set(INC ../../../../source/blender/makesdna ../../../../source/blender/blenlib ../../../../source/blender/blenkernel + ${GLEW_INCLUDE_PATH} ${PYTHON_INCLUDE_DIRS} ) diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index dc7a88e8db1..00ecc64c41e 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -577,6 +577,10 @@ protected: return m_parentCtrl; } + virtual const char* getName() + { + return 0; + } #ifdef WITH_CXX_GUARDEDALLOC public: diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 93f1d0962d7..c87157ee993 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -470,8 +470,12 @@ void CcdPhysicsEnvironment::updateCcdPhysicsController(CcdPhysicsController* ctr if (newMass) body->getCollisionShape()->calculateLocalInertia(newMass, inertia); body->setMassProps(newMass, inertia); + m_dynamicsWorld->addRigidBody(body, newCollisionGroup, newCollisionMask); + } + else + { + m_dynamicsWorld->addCollisionObject(obj, newCollisionGroup, newCollisionMask); } - m_dynamicsWorld->addCollisionObject(obj, newCollisionGroup, newCollisionMask); } // to avoid nasty interaction, we must update the property of the controller as well ctrl->m_cci.m_mass = newMass; @@ -1457,7 +1461,7 @@ struct OcclusionBuffer const float face, const btScalar minarea) { - const btScalar a2=cross(b-a,c-a)[2]; + const btScalar a2=btCross(b-a,c-a)[2]; if((face*a2)<0.f || btFabs(a2)<minarea) return false; // further down we are normally going to write to the Zbuffer, mark it so @@ -1990,6 +1994,44 @@ void CcdPhysicsEnvironment::setConstraintParam(int constraintId,int param,float default: { } + }; + break; + }; + case PHY_CONE_TWIST_CONSTRAINT: + { + switch (param) + { + case 3: case 4: case 5: + { + //param = 3,4,5 are constraint limits, high limit values + btConeTwistConstraint* coneTwist = (btConeTwistConstraint*)typedConstraint; + if(value1<0.0f) + coneTwist->setLimit(param,btScalar(BT_LARGE_FLOAT)); + else + coneTwist->setLimit(param,value1); + break; + } + default: + { + } + }; + break; + }; + case PHY_ANGULAR_CONSTRAINT: + case PHY_LINEHINGE_CONSTRAINT: + { + switch (param) + { + case 3: + { + //param = 3 is a constraint limit, with low/high limit value + btHingeConstraint* hingeCons = (btHingeConstraint*)typedConstraint; + hingeCons->setLimit(value0,value1); + break; + } + default: + { + } } break; }; @@ -2623,20 +2665,54 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl if (rb1) { - btVector3 axisInB = rb1 ? - (rb1->getCenterOfMassTransform().getBasis().inverse()*(rb0->getCenterOfMassTransform().getBasis() * axisInA)) : - rb0->getCenterOfMassTransform().getBasis() * axisInA; + // We know the orientations so we should use them instead of + // having btHingeConstraint fill in the blanks any way it wants to. + btTransform frameInA; + btTransform frameInB; + + btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z); + if (axis1.length() == 0.0) + { + btPlaneSpace1( axisInA, axis1, axis2 ); + } + + // Internally btHingeConstraint's hinge-axis is z + frameInA.getBasis().setValue( axis1.x(), axis2.x(), axisInA.x(), + axis1.y(), axis2.y(), axisInA.y(), + axis1.z(), axis2.z(), axisInA.z() ); + + frameInA.setOrigin( pivotInA ); - hinge = new btHingeConstraint( - *rb0, - *rb1,pivotInA,pivotInB,axisInA,axisInB); + btTransform inv = rb1->getCenterOfMassTransform().inverse(); + + btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA; + + frameInB = inv * globalFrameA; + + hinge = new btHingeConstraint(*rb0,*rb1,frameInA,frameInB); } else { - hinge = new btHingeConstraint(*rb0, - pivotInA,axisInA); + static btRigidBody s_fixedObject2( 0,0,0); + + btTransform frameInA; + btTransform frameInB; + + btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z); + if (axis1.length() == 0.0) + { + btPlaneSpace1( axisInA, axis1, axis2 ); + } + + // Internally btHingeConstraint's hinge-axis is z + frameInA.getBasis().setValue( axis1.x(), axis2.x(), axisInA.x(), + axis1.y(), axis2.y(), axisInA.y(), + axis1.z(), axis2.z(), axisInA.z() ); + frameInA.setOrigin( pivotInA ); + frameInB = rb0->getCenterOfMassTransform() * frameInA; + hinge = new btHingeConstraint(*rb0, s_fixedObject2, frameInA, frameInB); } hinge->setAngularOnly(angularOnly); @@ -2721,3 +2797,35 @@ float CcdPhysicsEnvironment::getAppliedImpulse(int constraintid) return 0.f; } + +void CcdPhysicsEnvironment::exportFile(const char* filename) +{ + btDefaultSerializer* serializer = new btDefaultSerializer(); + + + for (int i=0;i<m_dynamicsWorld->getNumCollisionObjects();i++) + { + + btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i]; + + CcdPhysicsController* controller = static_cast<CcdPhysicsController*>(colObj->getUserPointer()); + if (controller) + { + const char* name = controller->getName(); + if (name) + { + serializer->registerNameForPointer(colObj,name); + } + } + } + + m_dynamicsWorld->serialize(serializer); + + FILE* file = fopen(filename,"wb"); + if (file) + { + fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file); + fclose(file); + } +} + diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 4b97dc95179..51e00b9111f 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -125,7 +125,11 @@ protected: virtual void debugDrawWorld(); // virtual bool proceedDeltaTimeOneStep(float timeStep); - virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){}; + virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep) + { + //based on DEFAULT_PHYSICS_TIC_RATE of 60 hertz + setNumTimeSubSteps(fixedTimeStep/60.f); + } //returns 0.f if no fixed timestep is used virtual float getFixedTimeStep(){ return 0.f;}; @@ -280,6 +284,8 @@ protected: bool m_scalingPropagated; + virtual void exportFile(const char* filename); + #ifdef WITH_CXX_GUARDEDALLOC public: |