Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2006-12-01 04:04:27 +0300
committerErwin Coumans <blender@erwincoumans.com>2006-12-01 04:04:27 +0300
commit4941107f927c3717a113b82463193caae0022d8c (patch)
tree2f4de94b1bb53233e54f49a732a0f4d90df14bf8 /source/gameengine/Ketsji
parent51ce503cb24de6fa928555359acce77beed8995e (diff)
- enabled compound collision objects, requires 'clear parent inverse'
- fixed some issues with kinematic objects, introduced during Bullet 2.x upgrade
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/KX_BulletPhysicsController.cpp28
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObject.h5
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp92
3 files changed, 104 insertions, 21 deletions
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
index d28a8f40d6f..6785cb957bc 100644
--- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
+++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
@@ -195,6 +195,34 @@ SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
void KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly)
{
+ GetRigidBody()->activate(true);
+
+ if (!m_bDyna)
+ {
+ GetRigidBody()->setCollisionFlags(GetRigidBody()->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ } else
+ {
+ if (!nondynaonly)
+ {
+ btTransform worldTrans;
+ GetRigidBody()->getMotionState()->getWorldTransform(worldTrans);
+ GetRigidBody()->setCenterOfMassTransform(worldTrans);
+
+ /*
+ scaling?
+ if (m_bDyna)
+ {
+ m_sumoObj->setScaling(MT_Vector3(1,1,1));
+ } else
+ {
+ MT_Vector3 scale;
+ GetWorldScaling(scale);
+ m_sumoObj->setScaling(scale);
+ }
+ */
+
+ }
+ }
}
// todo: remove next line !
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
index a976a6b13b1..684e052323d 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
@@ -57,7 +57,8 @@ typedef enum {
KX_BOUNDCYLINDER,
KX_BOUNDCONE,
KX_BOUNDMESH,
- KX_BOUNDPOLYTOPE
+ KX_BOUNDPOLYTOPE,
+ KX_BOUND_DYN_MESH
} KX_BoundBoxClass;
struct KX_BoxBounds
@@ -86,6 +87,8 @@ struct KX_ObjectProperties
bool m_concave;
bool m_isdeformable;
bool m_disableSleeping;
+ bool m_hasCompoundChildren;
+ bool m_isCompoundChild;
KX_BoundBoxClass m_boundclass;
union {
KX_BoxBounds box;
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
index ca75b77dfec..e7a33fafffb 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
@@ -884,29 +884,11 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment();
assert(env);
-
- bool isbulletdyna = false;
+ bool isbulletdyna = objprop->m_dyna;
CcdConstructionInfo ci;
- class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
-
-
-
- if (!objprop->m_dyna)
- {
- ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT;
- }
-
- ci.m_MotionState = motionstate;
- ci.m_gravity = btVector3(0,0,0);
ci.m_localInertiaTensor =btVector3(0,0,0);
ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f;
- isbulletdyna = objprop->m_dyna;
-
- ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
-
- btTransform trans;
- trans.setIdentity();
-
+
btCollisionShape* bm = 0;
switch (objprop->m_boundclass)
@@ -1022,6 +1004,59 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
bm->setMargin(0.06);
+ if (objprop->m_isCompoundChild)
+ {
+ //find parent, compound shape and add to it
+ //take relative transform into account!
+ KX_BulletPhysicsController* parentCtrl = (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController();
+ assert(parentCtrl);
+ btRigidBody* rigidbody = parentCtrl->GetRigidBody();
+ btCollisionShape* colShape = rigidbody->getCollisionShape();
+ assert(colShape->isCompound());
+ btCompoundShape* compoundShape = (btCompoundShape*)colShape;
+ btTransform childTrans;
+ childTrans.setIdentity();
+ NodeList& children = objprop->m_dynamic_parent->GetSGNode()->GetSGChildren();
+
+ MT_Point3 childPos = gameobj->GetSGNode()->GetLocalPosition();
+ MT_Matrix3x3 childRot = gameobj->GetSGNode()->GetLocalOrientation();
+ MT_Vector3 childScale = gameobj->GetSGNode()->GetLocalScale();
+
+ bm->setLocalScaling(btVector3(childScale.x(),childScale.y(),childScale.z()));
+ childTrans.setOrigin(btVector3(childPos.x(),childPos.y(),childPos.z()));
+ float rotval[12];
+ childRot.getValue(rotval);
+ btMatrix3x3 newRot;
+ newRot.setValue(rotval[0],rotval[1],rotval[2],rotval[4],rotval[5],rotval[6],rotval[8],rotval[9],rotval[10]);
+ newRot = newRot.transpose();
+
+ childTrans.setBasis(newRot);
+
+
+ compoundShape->addChildShape(childTrans,bm);
+ //do some recalc?
+ //recalc inertia for rigidbody
+ if (!rigidbody->isStaticOrKinematicObject())
+ {
+ btVector3 localInertia;
+ float mass = 1.f/rigidbody->getInvMass();
+ compoundShape->calculateLocalInertia(mass,localInertia);
+ rigidbody->setMassProps(mass,localInertia);
+ }
+ return;
+ }
+
+ if (objprop->m_hasCompoundChildren)
+ {
+ //replace shape by compoundShape
+ btCompoundShape* compoundShape = new btCompoundShape();
+ btTransform identTrans;
+ identTrans.setIdentity();
+ compoundShape->addChildShape(identTrans,bm);
+ bm = compoundShape;
+ }
+
+
#ifdef TEST_SIMD_HULL
if (bm->IsPolyhedral())
{
@@ -1052,6 +1087,23 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_collisionShape = bm;
+ class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
+
+ if (!objprop->m_dyna)
+ {
+ ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT;
+ }
+
+
+ ci.m_MotionState = motionstate;
+ ci.m_gravity = btVector3(0,0,0);
+
+ ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
+
+ btTransform trans;
+ trans.setIdentity();
+
+
ci.m_friction = smmaterial->m_friction;//tweak the friction a bit, so the default 0.5 works nice
ci.m_restitution = smmaterial->m_restitution;