more Bullet 2.x upgrading. fair amount of functionality is now restored, not all...
authorErwin Coumans <blender@erwincoumans.com>
Tue, 21 Nov 2006 12:26:05 +0000 (12:26 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Tue, 21 Nov 2006 12:26:05 +0000 (12:26 +0000)
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h

index d637df95756d122d70382cfda9bf1578e25f1001..ca75b77dfecdf2bf9432ffb85a3c33dd46891f08 100644 (file)
@@ -889,12 +889,7 @@ void       KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        CcdConstructionInfo ci;
        class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
 
-       if (objprop->m_ghost)
-       {
-               
-               ci.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE;
        
-       }
 
        if (!objprop->m_dyna)
        {
@@ -973,7 +968,7 @@ void        KX_ConvertBulletObject( class   KX_GameObject* gameobj,
 
                                halfExtents /= 2.f;
 
-                               bm = new btConeShape(objprop->m_boundobject.c.m_radius,objprop->m_boundobject.c.m_height);
+                               bm = new btConeShapeZ(objprop->m_boundobject.c.m_radius,objprop->m_boundobject.c.m_height);
                                bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
 
                        break;
@@ -1078,10 +1073,15 @@ void    KX_ConvertBulletObject( class   KX_GameObject* gameobj,
 
        gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
        physicscontroller->setNewClientInfo(gameobj->getClientInfo());          
+       btRigidBody* rbody = physicscontroller->GetRigidBody();
 
        if (objprop->m_disableSleeping)
-               physicscontroller->GetRigidBody()->setActivationState(DISABLE_DEACTIVATION);
+               rbody->setActivationState(DISABLE_DEACTIVATION);
        
+       if (objprop->m_ghost)
+       {
+               rbody->setCollisionFlags(rbody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
+       }
        if (objprop->m_dyna && !objprop->m_angular_rigidbody)
        {
                /*
index e542c3365591baddd8fe331b7280f5b6d69a9c91..31cea0be9e1cc31bd5dfa37757a276b89a9ff26b 100644 (file)
@@ -165,7 +165,7 @@ bool                CcdPhysicsController::SynchronizeMotionStates(float time)
                btVector3 worldPos;
                btQuaternion worldquat;
 
-               m_MotionState->getWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
+/*             m_MotionState->getWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
                m_MotionState->getWorldOrientation(worldquat[0],worldquat[1],worldquat[2],worldquat[3]);
                btTransform oldTrans = m_body->getCenterOfMassTransform();
                btTransform newTrans(worldquat,worldPos);
@@ -174,7 +174,7 @@ bool                CcdPhysicsController::SynchronizeMotionStates(float time)
                //need to keep track of previous position for friction effects...
                
                m_MotionState->calculateWorldTransformations();
-
+*/
                float scale[3];
                m_MotionState->getWorldScaling(scale[0],scale[1],scale[2]);
                btVector3 scaling(scale[0],scale[1],scale[2]);
@@ -245,7 +245,12 @@ void               CcdPhysicsController::RelativeTranslate(float dlocX,float dlocY,float dloc
 {
        if (m_body)
        {
-               m_body->activate();
+               m_body->activate(true);
+               if (m_body->isStaticObject())
+               {
+                       m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+               }
+
 
                btVector3 dloc(dlocX,dlocY,dlocZ);
                btTransform xform = m_body->getCenterOfMassTransform();
@@ -265,7 +270,11 @@ void               CcdPhysicsController::RelativeRotate(const float rotval[9],bool local)
 {
        if (m_body )
        {
-               m_body->activate();
+               m_body->activate(true);
+               if (m_body->isStaticObject())
+               {
+                       m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+               }
 
                btMatrix3x3 drotmat(    rotval[0],rotval[1],rotval[2],
                                                                rotval[4],rotval[5],rotval[6],
@@ -303,7 +312,12 @@ void               CcdPhysicsController::getOrientation(float &quatImag0,float &quatImag1,flo
 }
 void           CcdPhysicsController::setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal)
 {
-       m_body->activate();
+       m_body->activate(true);
+       if (m_body->isStaticObject())
+       {
+               m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+       }
+
        m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal);
        btTransform xform  = m_body->getCenterOfMassTransform();
        xform.setRotation(btQuaternion(quatImag0,quatImag1,quatImag2,quatReal));
@@ -313,7 +327,11 @@ void               CcdPhysicsController::setOrientation(float quatImag0,float quatImag1,float
 
 void           CcdPhysicsController::setPosition(float posX,float posY,float posZ)
 {
-       m_body->activate();
+       m_body->activate(true);
+       if (m_body->isStaticObject())
+       {
+               m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+       }
        m_MotionState->setWorldPosition(posX,posY,posZ);
        btTransform xform  = m_body->getCenterOfMassTransform();
        xform.setOrigin(btVector3(posX,posY,posZ));
@@ -376,7 +394,7 @@ void                CcdPhysicsController::SetAngularVelocity(float ang_velX,float ang_velY,flo
        btVector3 angvel(ang_velX,ang_velY,ang_velZ);
        if (angvel.length2() > (SIMD_EPSILON*SIMD_EPSILON))
        {
-               m_body->activate();
+               m_body->activate(true);
        }
 
        {
@@ -396,7 +414,7 @@ void                CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa
        btVector3 linVel(lin_velX,lin_velY,lin_velZ);
        if (linVel.length2() > (SIMD_EPSILON*SIMD_EPSILON))
        {
-               m_body->activate();
+               m_body->activate(true);
        }
        
        {
index 9533adfa3d56e0a38edc72a490b7d0fa7094150e..c9cd66bda8bc3d2a855f800e9a811bf2589aea5d 100644 (file)
@@ -251,6 +251,12 @@ public:
 #endif //NEW_BULLET_VEHICLE_SUPPORT
 
 
+void CcdPhysicsEnvironment::setDebugDrawer(btIDebugDraw* debugDrawer)
+{
+       if (debugDrawer && m_dynamicsWorld)
+               m_dynamicsWorld->setDebugDrawer(debugDrawer);
+       m_debugDrawer = debugDrawer;
+}
 
 static void DrawAabb(btIDebugDraw* debugDrawer,const btVector3& from,const btVector3& to,const btVector3& color)
 {
@@ -321,7 +327,7 @@ m_enableSatCollisionDetection(false)
 
        setSolverType(1);//issues with quickstep and memory allocations
 
-       m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,pairCache);
+       m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,pairCache,new btSequentialImpulseConstraintSolver2());
        m_debugDrawer = 0;
        m_gravity = btVector3(0.f,-10.f,0.f);
        m_dynamicsWorld->setGravity(m_gravity);
@@ -340,6 +346,12 @@ void       CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl)
        m_controllers.push_back(ctrl);
 
        m_dynamicsWorld->addRigidBody(body);
+       if (body->isStaticOrKinematicObject())
+       {
+               body->setActivationState(ISLAND_SLEEPING);
+       }
+
+
        //CollisionObject(body,ctrl->GetCollisionFilterGroup(),ctrl->GetCollisionFilterMask());
 
        assert(body->getBroadphaseHandle());
@@ -438,15 +450,28 @@ void      CcdPhysicsEnvironment::beginFrame()
 bool   CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
 {
 
-       int numCtrl = GetNumControllers();
-       for (int i=0;i<numCtrl;i++)
+       int i,numCtrl = GetNumControllers();
+       for (i=0;i<numCtrl;i++)
        {
                CcdPhysicsController* ctrl = GetPhysicsController(i);
                ctrl->SynchronizeMotionStates(timeStep);
        }
 
-       m_dynamicsWorld->stepSimulation(timeStep);
+       m_dynamicsWorld->stepSimulation(timeStep,5);//5);
        
+       numCtrl = GetNumControllers();
+       for (i=0;i<numCtrl;i++)
+       {
+               CcdPhysicsController* ctrl = GetPhysicsController(i);
+               ctrl->SynchronizeMotionStates(timeStep);
+       }
+
+       for (i=0;i<m_wrapperVehicles.size();i++)
+       {
+               WrapperVehicle* veh = m_wrapperVehicles[i];
+               veh->SyncWheels();
+       }
+
        return true;
 }
 
index 7911c3d1ed991105fee0a81e9cfb9eee8e039bae..05c9e2a6b03b81863bd241b440517d490d1f0e1c 100644 (file)
@@ -81,10 +81,7 @@ protected:
 
                /// Perform an integration step of duration 'timeStep'.
 
-               virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
-               {
-                       m_debugDrawer = debugDrawer;
-               }
+               virtual void setDebugDrawer(btIDebugDraw* debugDrawer);
 
                virtual void            setNumIterations(int numIter);
                virtual void            setNumTimeSubSteps(int numTimeSubSteps)