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>2005-12-31 10:20:08 +0300
committerErwin Coumans <blender@erwincoumans.com>2005-12-31 10:20:08 +0300
commit9119b6e8a547303ce9a7ccd3a00636153b53cb0e (patch)
tree1816973e2baf4888d571e87cfb548cafafe46d41 /source/gameengine/Ketsji
parent625c553e2077ec0a252ddd934d4267c61011d61f (diff)
Fixed several bugs: python refcounting related and Bullet related (basic add/remove object support, bounding volume hierarchy). Added a few files, updated the Bullet scons. Vc6/7 Bullet projectfiles need to add a couple of files: 'Bullet/CollisionShapes/BvhTriangleMeshShape.cpp',
'Bullet/CollisionShapes/ConvexTriangleCallback.cpp', 'Bullet/CollisionShapes/EmptyShape.cpp', 'Bullet/CollisionShapes/OptimizedBvh.cpp', 'Bullet/CollisionShapes/TriangleCallback.cpp', 'Bullet/CollisionShapes/TriangleIndexVertexArray.cpp', 'Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp'. Sorry, no armatures fix yet.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/KX_BulletPhysicsController.cpp79
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp26
-rw-r--r--source/gameengine/Ketsji/KX_EmptyObject.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_EmptyObject.h2
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp4
5 files changed, 99 insertions, 16 deletions
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
index 5857c614e2d..7806b77257a 100644
--- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
+++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
@@ -7,6 +7,14 @@
#include "Dynamics/RigidBody.h"
+#include "SG_Spatial.h"
+
+#include "KX_GameObject.h"
+#include "KX_MotionState.h"
+#include "KX_ClientObjectInfo.h"
+
+#include "PHY_IPhysicsEnvironment.h"
+
KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna)
: KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this),
CcdPhysicsController(ci)
@@ -38,6 +46,16 @@ void KX_BulletPhysicsController::applyImpulse(const MT_Point3& attach, const MT_
void KX_BulletPhysicsController::SetObject (SG_IObject* object)
{
+ SG_Controller::SetObject(object);
+
+ // cheating here...
+ //should not be necessary, is it for duplicates ?
+
+ KX_GameObject* gameobj = (KX_GameObject*) object->GetSGClientObject();
+ gameobj->SetPhysicsController(this,gameobj->IsDynamic());
+ //GetSumoObject()->setClientObject(gameobj->getClientInfo());
+
+
}
void KX_BulletPhysicsController::RelativeTranslate(const MT_Vector3& dloc,bool local)
@@ -55,22 +73,25 @@ void KX_BulletPhysicsController::RelativeRotate(const MT_Matrix3x3& drot,bool lo
void KX_BulletPhysicsController::ApplyTorque(const MT_Vector3& torque,bool local)
{
+ CcdPhysicsController::ApplyTorque(torque.x(),torque.y(),torque.z(),local);
}
void KX_BulletPhysicsController::ApplyForce(const MT_Vector3& force,bool local)
{
+ CcdPhysicsController::ApplyForce(force.x(),force.y(),force.z(),local);
}
MT_Vector3 KX_BulletPhysicsController::GetLinearVelocity()
{
- assert(0);
- return MT_Vector3(0.f,0.f,0.f);
-
+ float angVel[3];
+ CcdPhysicsController::GetAngularVelocity(angVel[0],angVel[1],angVel[2]);
+ return MT_Vector3(angVel[0],angVel[1],angVel[2]);
}
MT_Vector3 KX_BulletPhysicsController::GetVelocity(const MT_Point3& pos)
{
- assert(0);
- return MT_Vector3(0.f,0.f,0.f);
-
+ float linVel[3];
+ CcdPhysicsController::GetLinearVelocity(linVel[0],linVel[1],linVel[2]);
+ return MT_Vector3(linVel[0],linVel[1],linVel[2]);
}
+
void KX_BulletPhysicsController::SetAngularVelocity(const MT_Vector3& ang_vel,bool local)
{
CcdPhysicsController::SetAngularVelocity(ang_vel.x(),ang_vel.y(),ang_vel.z(),local);
@@ -82,16 +103,21 @@ void KX_BulletPhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,boo
}
void KX_BulletPhysicsController::getOrientation(MT_Quaternion& orn)
{
+ float myorn[4];
+ CcdPhysicsController::getOrientation(myorn[0],myorn[1],myorn[2],myorn[3]);
+ orn = MT_Quaternion(myorn[0],myorn[1],myorn[2],myorn[3]);
}
void KX_BulletPhysicsController::setOrientation(const MT_Quaternion& orn)
{
+ CcdPhysicsController::setOrientation(orn.x(),orn.y(),orn.z(),orn.w());
}
void KX_BulletPhysicsController::setPosition(const MT_Point3& pos)
{
-
+ CcdPhysicsController::setPosition(pos.x(),pos.y(),pos.z());
}
void KX_BulletPhysicsController::setScaling(const MT_Vector3& scaling)
{
+ CcdPhysicsController::setScaling(scaling.x(),scaling.y(),scaling.z());
}
MT_Scalar KX_BulletPhysicsController::GetMass()
{
@@ -113,6 +139,7 @@ void KX_BulletPhysicsController::setRigidBody(bool rigid)
void KX_BulletPhysicsController::SuspendDynamics()
{
+
}
void KX_BulletPhysicsController::RestoreDynamics()
{
@@ -120,8 +147,42 @@ void KX_BulletPhysicsController::RestoreDynamics()
SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
{
- assert(0);
- return 0;
+ PHY_IMotionState* motionstate = new KX_MotionState(destnode);
+
+ KX_BulletPhysicsController* physicsreplica = new KX_BulletPhysicsController(*this);
+
+ //parentcontroller is here be able to avoid collisions between parent/child
+
+ PHY_IPhysicsController* parentctrl = NULL;
+
+ if (destnode != destnode->GetRootSGParent())
+ {
+ KX_GameObject* clientgameobj = (KX_GameObject*) destnode->GetRootSGParent()->GetSGClientObject();
+ if (clientgameobj)
+ {
+ parentctrl = (KX_BulletPhysicsController*)clientgameobj->GetPhysicsController();
+ } else
+ {
+ // it could be a false node, try the children
+ NodeList::const_iterator childit;
+ for (
+ childit = destnode->GetSGChildren().begin();
+ childit!= destnode->GetSGChildren().end();
+ ++childit
+ ) {
+ KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
+ if (clientgameobj)
+ {
+ parentctrl = (KX_BulletPhysicsController*)clientgameobj->GetPhysicsController();
+ }
+ }
+ }
+ }
+
+ physicsreplica->PostProcessReplica(motionstate,parentctrl);
+
+ return physicsreplica;
+
}
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
index e9a6c2442b0..646fc93dadb 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
@@ -673,6 +673,7 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj,
#include "CollisionShapes/ConvexHullShape.h"
#include "CollisionShapes/TriangleMesh.h"
#include "CollisionShapes/TriangleMeshShape.h"
+#include "CollisionShapes/BvhTriangleMeshShape.h"
static GEN_Map<GEN_HashedPtr,CollisionShape*> map_gamemesh_to_bulletshape;
@@ -770,8 +771,8 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p
} else
{
collisionMeshData = new TriangleMesh();
- concaveShape = new TriangleMeshShape(collisionMeshData);
- collisionMeshShape = concaveShape;
+// concaveShape = new TriangleMeshShape(collisionMeshData);
+ //collisionMeshShape = concaveShape;
}
@@ -843,7 +844,20 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p
if (numvalidpolys > 0)
{
+
//map_gamemesh_to_bulletshape.insert(GEN_HashedPtr(meshobj),collisionMeshShape);
+ if (!polytope)
+ {
+ concaveShape = new BvhTriangleMeshShape( collisionMeshData );
+ //concaveShape = new TriangleMeshShape( collisionMeshData );
+
+ concaveShape->RecalcLocalAabb();
+ collisionMeshShape = concaveShape;
+
+ }
+
+
+
return collisionMeshShape;
}
@@ -1002,7 +1016,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_broadphaseHandle = 0;
ci.m_friction = smmaterial->m_friction;
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;
@@ -1010,7 +1024,11 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna);
- env->addCcdPhysicsController( physicscontroller);
+
+ if (objprop->m_in_active_layer)
+ {
+ env->addCcdPhysicsController( physicscontroller);
+ }
gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
diff --git a/source/gameengine/Ketsji/KX_EmptyObject.cpp b/source/gameengine/Ketsji/KX_EmptyObject.cpp
index 8a72ba62f51..4636f2f0a3e 100644
--- a/source/gameengine/Ketsji/KX_EmptyObject.cpp
+++ b/source/gameengine/Ketsji/KX_EmptyObject.cpp
@@ -35,3 +35,7 @@
#include <config.h>
#endif
+KX_EmptyObject::~KX_EmptyObject()
+{
+
+}
diff --git a/source/gameengine/Ketsji/KX_EmptyObject.h b/source/gameengine/Ketsji/KX_EmptyObject.h
index b2038eb4816..46858b5c46d 100644
--- a/source/gameengine/Ketsji/KX_EmptyObject.h
+++ b/source/gameengine/Ketsji/KX_EmptyObject.h
@@ -39,7 +39,7 @@ public:
KX_EmptyObject(void* sgReplicationInfo,SG_Callbacks callbacks) :
KX_GameObject(sgReplicationInfo,callbacks)
{};
- virtual ~KX_EmptyObject() {};
+ virtual ~KX_EmptyObject();
};
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index 6ad420375e6..f13df6bfa44 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -732,7 +732,7 @@ void KX_Scene::ReplaceMesh(class CValue* gameobj,void* meshobj)
Object* blendobj = (struct Object*)m_logicmgr->FindBlendObjByGameObj(newobj);
Object* oldblendobj = (struct Object*)m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName());
if (blendobj->parent && blendobj->parent->type == OB_ARMATURE && blendobj->partype==PARSKEL && ((Mesh*)blendobj->data)->dvert) {
- BL_SkinDeformer* skindeformer = new BL_SkinDeformer(oldblendobj, blendobj, (BL_SkinMeshObject*)mesh);
+ BL_SkinDeformer* skindeformer = new BL_SkinDeformer(oldblendobj, blendobj, (BL_SkinMeshObject*)mesh,blendobj->parent);
skindeformer->SetArmature((BL_ArmatureObject*) newobj->GetParent());
// FIXME: should the old m_pDeformer be deleted?
@@ -741,7 +741,7 @@ void KX_Scene::ReplaceMesh(class CValue* gameobj,void* meshobj)
((BL_DeformableGameObject*)newobj)->m_pDeformer = skindeformer;
}
else if (((Mesh*)blendobj->data)->dvert) {
- BL_MeshDeformer* meshdeformer = new BL_MeshDeformer(oldblendobj, (BL_SkinMeshObject*)mesh);
+ BL_MeshDeformer* meshdeformer = new BL_MeshDeformer(oldblendobj, (BL_SkinMeshObject*)mesh,oldblendobj->parent);
// FIXME: should the old m_pDeformer be deleted?
// delete ((BL_DeformableGameObject*)newobj)->m_pDeformer