diff options
Diffstat (limited to 'source/gameengine')
4 files changed, 33 insertions, 11 deletions
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 646fc93dadb..71a80e01f3b 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -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); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index e82ecd83fee..bd7ce6cc36d 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -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); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index bb4f1465b2d..ee3b0ffb528 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -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); + } } } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 87290f65fb4..3becd14028a 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -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' }; |