more game engine bug-fixes, hooked up 'formfactor' as inertia tensor tweaker, frictio...
authorErwin Coumans <blender@erwincoumans.com>
Sat, 31 Dec 2005 21:59:56 +0000 (21:59 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Sat, 31 Dec 2005 21:59:56 +0000 (21:59 +0000)
extern/bullet/BulletDynamics/ConstraintSolver/ContactConstraint.cpp
extern/bullet/BulletDynamics/Dynamics/ContactJoint.cpp
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h

index be6793dc19221aa9c478a4e3b1cda80da1f183a9..0c400a84dca2bc62304b4d62638c9008abaaac68 100644 (file)
@@ -27,8 +27,8 @@ SimdScalar contactTau = .02f;//0.02f;//*0.02f;
 
 SimdScalar restitutionCurve(SimdScalar rel_vel, SimdScalar restitution)
 {
-       return 0.f;
-//     return restitution * GEN_min(1.0f, rel_vel / ContactThreshold);
+//     return 0.f;
+       return restitution * GEN_min(1.0f, rel_vel / ContactThreshold);
 }
 
 
index b60b4eefe3468c88f3dd60c774b6de294d124808..0a988adcc7599d6a9c4e0d57033e26e9c5570869 100644 (file)
@@ -165,7 +165,7 @@ void ContactJoint::GetInfo2(Info2 *info)
        c2[2] = ccc2[2];
        
        
-       float friction = 10.1f;//FRICTION_CONSTANT*m_body0->getFriction() * m_body1->getFriction();
+       float friction = FRICTION_CONSTANT*m_body0->getFriction() * m_body1->getFriction();
        
        // first friction direction
        if (m_numRows >= 2) 
index 646fc93dadbe976db9fbbd75bf81b2fd3073aa7e..71a80e01f3ba133025e575bf336a6b03649830b7 100644 (file)
@@ -1014,14 +1014,14 @@ void    KX_ConvertBulletObject( class   KX_GameObject* gameobj,
 
        ci.m_collisionShape = bm;
        ci.m_broadphaseHandle = 0;
-       ci.m_friction = smmaterial->m_friction;
+       ci.m_friction = 5.f* smmaterial->m_friction;//tweak the friction a bit, so the default 0.5 works nice
        ci.m_restitution = smmaterial->m_restitution;
        ci.m_physicsEnv = env;
        // drag / damping is inverted
        ci.m_linearDamping = 1.f - shapeprops->m_lin_drag;
        ci.m_angularDamping = 1.f - shapeprops->m_ang_drag;
        //need a bit of damping, else system doesn't behave well
-       
+       ci.m_inertiaFactor = shapeprops->m_inertia/0.4f;//defaults to 0.4, don't want to change behaviour
 
        KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna);
 
index e82ecd83fee26beb840cca09c520536685a755c1..bd7ce6cc36d5bdabfd0f37c64403d97ef1852b3e 100644 (file)
@@ -364,10 +364,14 @@ void KX_KetsjiEngine::NextFrame()
                                        scene->setSuspendedDelta(scene->getSuspendedDelta()+curtime-scene->getSuspendedTime());
                                m_suspendeddelta = scene->getSuspendedDelta();
 
-                               m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
+                               
                                m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true);
                                scene->GetNetworkScene()->proceed(localtime);
        
+                               m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
+                               scene->UpdateParents(localtime);
+                               
+                               m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
                                // set Python hooks for each scene
                                PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
                                PHY_SetActiveScene(scene);
@@ -399,11 +403,11 @@ void KX_KetsjiEngine::NextFrame()
                                m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
                                scene->UpdateParents(localtime);
                                
+                               m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
                                scene->GetPhysicsEnvironment()->beginFrame();
                
                                // Perform physics calculations on the scene. This can involve 
                                // many iterations of the physics solver.
-                               m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
                                scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime);
                                m_previoustime = curtime;
 
@@ -462,6 +466,9 @@ void KX_KetsjiEngine::NextFrame()
                        PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
                        PHY_SetActiveScene(scene);
                        
+                       m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
+                       scene->UpdateParents(curtime);
+
                        // Perform physics calculations on the scene. This can involve 
                        // many iterations of the physics solver.
                        m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
index bb4f1465b2d14c16a5ef0230b6a8317798010c85..ee3b0ffb528221f6f1dee4d46dd4c420e2b54303 100644 (file)
@@ -63,7 +63,7 @@ void CcdPhysicsController::CreateRigidbody()
        // init the rigidbody properly
        //
        
-       m_body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor);
+       m_body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
        m_body->setGravity( m_cci.m_gravity);
        m_body->setDamping(m_cci.m_linearDamping, m_cci.m_angularDamping);
        m_body->setCenterOfMassTransform( trans );
@@ -237,15 +237,26 @@ void              CcdPhysicsController::resolveCombinedVelocities(float linvelX,float linvel
 
 void           CcdPhysicsController::getPosition(PHY__Vector3& pos) const
 {
-       assert(0);
+       const SimdTransform& xform = m_body->getCenterOfMassTransform();
+       pos[0] = xform.getOrigin().x();
+       pos[1] = xform.getOrigin().y();
+       pos[2] = xform.getOrigin().z();
 }
 
 void           CcdPhysicsController::setScaling(float scaleX,float scaleY,float scaleZ)
 {
-       if (m_body && m_body->GetCollisionShape())
+       if (!SimdFuzzyZero(m_cci.m_scaling.x()-scaleX) ||
+               !SimdFuzzyZero(m_cci.m_scaling.y()-scaleY) ||
+               !SimdFuzzyZero(m_cci.m_scaling.z()-scaleZ))
        {
-               SimdVector3 scaling(scaleX,scaleY,scaleZ);
-               m_body->GetCollisionShape()->setLocalScaling(scaling);
+               m_cci.m_scaling = SimdVector3(scaleX,scaleY,scaleZ);
+
+               if (m_body && m_body->GetCollisionShape())
+               {
+                       m_body->GetCollisionShape()->setLocalScaling(m_cci.m_scaling);
+                       m_body->GetCollisionShape()->CalculateLocalInertia(m_cci.m_mass, m_cci.m_localInertiaTensor);
+                       m_body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
+               }
        }
 }
                
index 87290f65fb4b52415de10dbabde50ec6ac9e4ab2..3becd14028a472a178124118eafb7dc341c3186b 100644 (file)
@@ -29,12 +29,15 @@ struct CcdConstructionInfo
                m_angularDamping(0.1f),
                m_MotionState(0),
                m_collisionShape(0),
-               m_physicsEnv(0)
-
+               m_physicsEnv(0),
+               m_inertiaFactor(1.f),
+               m_scaling(1.f,1.f,1.f)
        {
        }
+
        SimdVector3     m_localInertiaTensor;
        SimdVector3     m_gravity;
+       SimdVector3     m_scaling;
        SimdScalar      m_mass;
        SimdScalar      m_restitution;
        SimdScalar      m_friction;
@@ -45,6 +48,7 @@ struct CcdConstructionInfo
 
        CollisionShape*                 m_collisionShape;
        CcdPhysicsEnvironment*  m_physicsEnv; //needed for self-replication
+       float   m_inertiaFactor;//tweak the inertia (hooked up to Blender 'formfactor'
 };