more game engine bug-fixes, hooked up 'formfactor' as inertia tensor tweaker, friction/restitution, more scaling related fixes.

This commit is contained in:
Erwin Coumans 2005-12-31 21:59:56 +00:00
parent 9119b6e8a5
commit bab1b90edc
6 changed files with 36 additions and 14 deletions

@ -27,8 +27,8 @@ SimdScalar contactTau = .02f;//0.02f;//*0.02f;
SimdScalar restitutionCurve(SimdScalar rel_vel, SimdScalar restitution) SimdScalar restitutionCurve(SimdScalar rel_vel, SimdScalar restitution)
{ {
return 0.f; // return 0.f;
// return restitution * GEN_min(1.0f, rel_vel / ContactThreshold); return restitution * GEN_min(1.0f, rel_vel / ContactThreshold);
} }

@ -165,7 +165,7 @@ void ContactJoint::GetInfo2(Info2 *info)
c2[2] = ccc2[2]; 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 // first friction direction
if (m_numRows >= 2) if (m_numRows >= 2)

@ -1014,14 +1014,14 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_collisionShape = bm; ci.m_collisionShape = bm;
ci.m_broadphaseHandle = 0; 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_restitution = smmaterial->m_restitution;
ci.m_physicsEnv = env; ci.m_physicsEnv = env;
// drag / damping is inverted // drag / damping is inverted
ci.m_linearDamping = 1.f - shapeprops->m_lin_drag; ci.m_linearDamping = 1.f - shapeprops->m_lin_drag;
ci.m_angularDamping = 1.f - shapeprops->m_ang_drag; ci.m_angularDamping = 1.f - shapeprops->m_ang_drag;
//need a bit of damping, else system doesn't behave well //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); KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna);

@ -364,10 +364,14 @@ void KX_KetsjiEngine::NextFrame()
scene->setSuspendedDelta(scene->getSuspendedDelta()+curtime-scene->getSuspendedTime()); scene->setSuspendedDelta(scene->getSuspendedDelta()+curtime-scene->getSuspendedTime());
m_suspendeddelta = scene->getSuspendedDelta(); m_suspendeddelta = scene->getSuspendedDelta();
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true); m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true);
scene->GetNetworkScene()->proceed(localtime); 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 // set Python hooks for each scene
PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
PHY_SetActiveScene(scene); PHY_SetActiveScene(scene);
@ -399,11 +403,11 @@ void KX_KetsjiEngine::NextFrame()
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
scene->UpdateParents(localtime); scene->UpdateParents(localtime);
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
scene->GetPhysicsEnvironment()->beginFrame(); scene->GetPhysicsEnvironment()->beginFrame();
// Perform physics calculations on the scene. This can involve // Perform physics calculations on the scene. This can involve
// many iterations of the physics solver. // many iterations of the physics solver.
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime); scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime);
m_previoustime = curtime; m_previoustime = curtime;
@ -462,6 +466,9 @@ void KX_KetsjiEngine::NextFrame()
PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
PHY_SetActiveScene(scene); PHY_SetActiveScene(scene);
m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
scene->UpdateParents(curtime);
// Perform physics calculations on the scene. This can involve // Perform physics calculations on the scene. This can involve
// many iterations of the physics solver. // many iterations of the physics solver.
m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);

@ -63,7 +63,7 @@ void CcdPhysicsController::CreateRigidbody()
// init the rigidbody properly // 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->setGravity( m_cci.m_gravity);
m_body->setDamping(m_cci.m_linearDamping, m_cci.m_angularDamping); m_body->setDamping(m_cci.m_linearDamping, m_cci.m_angularDamping);
m_body->setCenterOfMassTransform( trans ); m_body->setCenterOfMassTransform( trans );
@ -237,15 +237,26 @@ void CcdPhysicsController::resolveCombinedVelocities(float linvelX,float linvel
void CcdPhysicsController::getPosition(PHY__Vector3& pos) const 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) 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_cci.m_scaling = SimdVector3(scaleX,scaleY,scaleZ);
m_body->GetCollisionShape()->setLocalScaling(scaling);
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);
}
} }
} }

@ -29,12 +29,15 @@ struct CcdConstructionInfo
m_angularDamping(0.1f), m_angularDamping(0.1f),
m_MotionState(0), m_MotionState(0),
m_collisionShape(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_localInertiaTensor;
SimdVector3 m_gravity; SimdVector3 m_gravity;
SimdVector3 m_scaling;
SimdScalar m_mass; SimdScalar m_mass;
SimdScalar m_restitution; SimdScalar m_restitution;
SimdScalar m_friction; SimdScalar m_friction;
@ -45,6 +48,7 @@ struct CcdConstructionInfo
CollisionShape* m_collisionShape; CollisionShape* m_collisionShape;
CcdPhysicsEnvironment* m_physicsEnv; //needed for self-replication CcdPhysicsEnvironment* m_physicsEnv; //needed for self-replication
float m_inertiaFactor;//tweak the inertia (hooked up to Blender 'formfactor'
}; };