diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2005-12-31 10:20:08 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2005-12-31 10:20:08 +0300 |
commit | 9119b6e8a547303ce9a7ccd3a00636153b53cb0e (patch) | |
tree | 1816973e2baf4888d571e87cfb548cafafe46d41 /source/gameengine/Ketsji/KX_BulletPhysicsController.cpp | |
parent | 625c553e2077ec0a252ddd934d4267c61011d61f (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/KX_BulletPhysicsController.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_BulletPhysicsController.cpp | 79 |
1 files changed, 70 insertions, 9 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; + } |