preparation for bullet physics
authorErwin Coumans <blender@erwincoumans.com>
Sat, 16 Jul 2005 21:47:54 +0000 (21:47 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Sat, 16 Jul 2005 21:47:54 +0000 (21:47 +0000)
15 files changed:
source/blender/blenlib/intern/storage.c
source/blender/render/intern/include/zblur.h
source/blender/src/buttons_shading.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Ketsji/KX_BulletPhysicsController.cpp [new file with mode: 0644]
source/gameengine/Ketsji/KX_BulletPhysicsController.h [new file with mode: 0644]
source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_PhysicsEngineEnums.h
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Physics/BlOde/OdePhysicsController.cpp
source/gameengine/Physics/BlOde/OdePhysicsEnvironment.cpp
source/gameengine/Physics/common/PHY_DynamicTypes.h

index 25327c4943e759732ec22c4905da2e4e3ea53307..64cf2888b5012cbd199047b0f88d13a51a8264fd 100644 (file)
@@ -394,6 +394,7 @@ void BLI_adddirstrings()
                else sprintf(files[num].size, "0");
 
                strftime(datum, 32, "%d-%b-%y %R", tm);
+               //for visual studio 8, strftime(datum, 32, "%d-%b-%y ", tm);
 
                if (st_size < 1000) {
                        sprintf(size, "%10d", (int) st_size);
index a0e1c6a39ce208276ba70a259b64df08f198baad..016cb237ba4cc4e9d360bcd732b71cb26bad9d85 100644 (file)
@@ -1,48 +1,96 @@
 /*
+
  * $Id$
+
  *
+
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+
  *
+
  * This program is free software; you can redistribute it and/or
+
  * modify it under the terms of the GNU General Public License
+
  * as published by the Free Software Foundation; either version 2
+
  * of the License, or (at your option) any later version. The Blender
+
  * Foundation also sells licenses for use in proprietary software under
+
  * the Blender License.  See http://www.blender.org/BL/ for information
+
  * about this.
+
  *
+
  * This program is distributed in the hope that it will be useful,
+
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+
  * GNU General Public License for more details.
+
  *
+
  * You should have received a copy of the GNU General Public License
+
  * along with this program; if not, write to the Free Software Foundation,
+
  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
  *
+
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
+
  */
 
+
+
 #ifndef ZBLUR_H
+
 #define ZBLUR_H
 
+
+
 #ifdef __cplusplus
+
 extern "C" { 
+
 #endif
 
+
+
 /*-----------------------------------------------------------*/ 
+
 /* Includes                                                  */
+
 /*-----------------------------------------------------------*/ 
 
+
+
 /*-----------------------------------------------------------*/ 
+
 /* Function                                                  */
+
 /*-----------------------------------------------------------*/ 
 
+
+
 void add_zblur(void);
 
+
+
 #ifdef __cplusplus
+
 }
+
 #endif
 
+
+
 #endif
 
+
+
index 7fc420c34fab4403ed0bf85e18fe011e0bb9ede8..dfcc2bad78f308f60e12dae44d355957d95781f7 100644 (file)
@@ -1858,7 +1858,7 @@ static void world_panel_mistaph(World *wrld)
 
 #if GAMEBLENDER == 1
        uiDefButI(block, MENU, 1, 
-                         "Physics %t|None %x0|Sumo %x2|Ode %x4",       
+                         "Physics %t|None %x0|Sumo %x2|Ode %x4 |Bullet %x5",   
                          10,180,140,19, &wrld->physicsEngine, 0, 0, 0, 0, 
                          "Physics Engine");
        
@@ -3112,7 +3112,6 @@ static void material_panel_material(Object *ob, Material *ma)
        uiDefIconBut(block, BUT, B_MATCOPY, ICON_COPYUP,        262,200,XIC,YIC, 0, 0, 0, 0, 0, "Copies Material to the buffer");
        uiSetButLock(id && id->lib, "Can't edit library data");
        uiDefIconBut(block, BUT, B_MATPASTE, ICON_PASTEUP,      283,200,XIC,YIC, 0, 0, 0, 0, 0, "Pastes Material from the buffer");
-       uiClearButLock();
        
        if(ob->actcol==0) ob->actcol= 1;        /* because of TOG|BIT button */
        
@@ -3144,10 +3143,10 @@ static void material_panel_material(Object *ob, Material *ma)
        uiBlockEndAlign(block);
        
        if(ob->totcol==0) return;
+       uiSetButLock(id->lib!=0, "Can't edit library data");
 
        ma= give_current_material(ob, ob->actcol);      
-       if(ma==NULL) return;    
-       uiSetButLock(ma->id.lib!=NULL, "Can't edit library data");
+       if(ma==0) return;       
        
        if(ma->dynamode & MA_DRAW_DYNABUTS) {
                uiBlockBeginAlign(block);
@@ -3265,8 +3264,6 @@ void material_panels()
                material_panel_material(ob, ma);
                
                if(ma) {
-                       uiSetButLock(ma->id.lib!=NULL, "Can't edit library data");
-
                        material_panel_ramps(ma);
                        material_panel_shading(ma);
                        if (G.scene->r.renderer==R_INTERN)
index 825e70ac240b0bae52ae248cd3c8239b60e57d40..3edd9ea581853e35608fc277e36583e2c31e0dd2 100644 (file)
@@ -816,6 +816,12 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
        
        switch (physics_engine)
        {
+#ifdef USE_BULLET
+               case UseBullet:
+                       KX_ConvertBulletObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
+                       break;
+
+#endif
 #ifdef USE_SUMO_SOLID
                case UseSumo:
                        KX_ConvertSumoObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
@@ -1330,7 +1336,9 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        KX_WorldInfo* worldinfo = new BlenderWorldInfo(blenderscene->world);
        converter->RegisterWorldInfo(worldinfo);
        kxscene->SetWorldInfo(worldinfo);
-       
+
+#define CONVERT_LOGIC
+#ifdef CONVERT_LOGIC
        // convert logic bricks, sensors, controllers and actuators
        for (i=0;i<logicbrick_conversionlist->GetCount();i++)
        {
@@ -1353,6 +1361,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                bool isInActiveLayer = (blenderobj->lay & activeLayerBitInfo)!=0;
                BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,keydev,executePriority,activeLayerBitInfo,isInActiveLayer,canvas,converter);
        }
+#endif //CONVERT_LOGIC
+
        logicbrick_conversionlist->Release();
        
        // Calculate the scene btree -
index 283710a5d5b434db7542849583aa56ada31ebcad..f8a628bd0c7ecc579e0882b21de02b17b2426df4 100644 (file)
 //to decide to use sumo/ode or dummy physics - defines USE_ODE
 #include "KX_ConvertPhysicsObject.h"
 
+#ifdef USE_BULLET
+#include "CcdPhysicsEnvironment.h"
+#endif
+
 #ifdef USE_ODE
 #include "OdePhysicsEnvironment.h"
 #endif //USE_ODE
@@ -117,6 +121,11 @@ KX_BlenderSceneConverter::~KX_BlenderSceneConverter()
 #ifdef USE_SUMO_SOLID
        KX_ClearSumoSharedShapes();
 #endif
+
+#ifdef USE_BULLET
+       KX_ClearBulletSharedShapes();
+#endif
+
 }
 
 
@@ -182,6 +191,11 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
                {
                        switch (blenderscene->world->physicsEngine)
                        {
+                       case WOPHY_BULLET:
+                               {
+                                       physics_engine = UseBullet;
+                                       break;
+                               }
                                 
                                case WOPHY_ODE:
                                {
@@ -209,7 +223,14 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
 
        switch (physics_engine)
        {
-       
+#ifdef USE_BULLET
+               case UseBullet:
+                       {
+                               destinationscene->SetPhysicsEnvironment(new CcdPhysicsEnvironment());
+                               break;
+                       }
+#endif
+
 #ifdef USE_SUMO_SOLID
                case UseSumo:
                        destinationscene ->SetPhysicsEnvironment(new SumoPhysicsEnvironment());
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
new file mode 100644 (file)
index 0000000..c916862
--- /dev/null
@@ -0,0 +1,138 @@
+#include "KX_BulletPhysicsController.h"
+
+#include "Dynamics/RigidBody.h"
+
+KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna)
+: KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this),
+CcdPhysicsController(ci)
+{
+
+}
+       
+KX_BulletPhysicsController::~KX_BulletPhysicsController ()
+{
+
+}
+
+void   KX_BulletPhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
+{
+       CcdPhysicsController::resolveCombinedVelocities(linvelX,linvelY,linvelZ,angVelX,angVelY,angVelZ);
+
+}
+
+
+       ///////////////////////////////////
+       //      KX_IPhysicsController interface
+       ////////////////////////////////////
+
+void   KX_BulletPhysicsController::applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse)
+{
+}
+
+void   KX_BulletPhysicsController::SetObject (SG_IObject* object)
+{
+}
+
+void   KX_BulletPhysicsController::RelativeTranslate(const MT_Vector3& dloc,bool local)
+{
+       CcdPhysicsController::RelativeTranslate(dloc[0],dloc[1],dloc[2],local);
+
+}
+void   KX_BulletPhysicsController::RelativeRotate(const MT_Matrix3x3& drot,bool local)
+{
+}
+void   KX_BulletPhysicsController::ApplyTorque(const MT_Vector3& torque,bool local)
+{
+}
+void   KX_BulletPhysicsController::ApplyForce(const MT_Vector3& force,bool local)
+{
+}
+MT_Vector3 KX_BulletPhysicsController::GetLinearVelocity()
+{
+       assert(0);
+       return MT_Vector3(0.f,0.f,0.f);
+
+}
+MT_Vector3 KX_BulletPhysicsController::GetVelocity(const MT_Point3& pos)
+{
+               assert(0);
+       return MT_Vector3(0.f,0.f,0.f);
+
+}
+void   KX_BulletPhysicsController::SetAngularVelocity(const MT_Vector3& ang_vel,bool local)
+{
+       CcdPhysicsController::SetAngularVelocity(ang_vel.x(),ang_vel.y(),ang_vel.z(),local);
+
+}
+void   KX_BulletPhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,bool local)
+{
+       CcdPhysicsController::SetLinearVelocity(lin_vel.x(),lin_vel.y(),lin_vel.z(),local);
+}
+void   KX_BulletPhysicsController::getOrientation(MT_Quaternion& orn)
+{
+}
+void KX_BulletPhysicsController::setOrientation(const MT_Quaternion& orn)
+{
+}
+void KX_BulletPhysicsController::setPosition(const MT_Point3& pos)
+{
+
+}
+void KX_BulletPhysicsController::setScaling(const MT_Vector3& scaling)
+{
+}
+MT_Scalar      KX_BulletPhysicsController::GetMass()
+{
+
+       MT_Scalar invmass = GetRigidBody()->getInvMass();
+       if (invmass)
+               return 1.f/invmass;
+       return 0.f;
+
+}
+MT_Vector3     KX_BulletPhysicsController::getReactionForce()
+{
+       assert(0);
+       return MT_Vector3(0.f,0.f,0.f);
+}
+void   KX_BulletPhysicsController::setRigidBody(bool rigid)
+{
+}
+
+void   KX_BulletPhysicsController::SuspendDynamics()
+{
+}
+void   KX_BulletPhysicsController::RestoreDynamics()
+{
+}
+
+SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
+{
+       assert(0);
+       return 0;
+}
+
+
+
+void   KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly)
+{
+}
+
+// todo: remove next line !
+void   KX_BulletPhysicsController::SetSimulatedTime(double time)
+{
+}
+       
+// call from scene graph to update
+bool KX_BulletPhysicsController::Update(double time)
+{
+       return false;
+
+       // todo: check this code
+       //if (GetMass())
+       //{
+       //      return false;//true;
+//     }
+//     return false;
+}
+
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h
new file mode 100644 (file)
index 0000000..9e9b081
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef KX_BULLET2PHYSICS_CONTROLLER
+#define KX_BULLET2PHYSICS_CONTROLLER
+
+
+#include "KX_IPhysicsController.h"
+#include "CcdPhysicsController.h"
+
+class KX_BulletPhysicsController : public KX_IPhysicsController ,public CcdPhysicsController
+{
+
+public:
+
+       KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna);
+       virtual ~KX_BulletPhysicsController ();
+
+       ///////////////////////////////////
+       //      KX_IPhysicsController interface
+       ////////////////////////////////////
+
+       virtual void    applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse);
+       virtual void    SetObject (SG_IObject* object);
+
+       virtual void    RelativeTranslate(const MT_Vector3& dloc,bool local);
+       virtual void    RelativeRotate(const MT_Matrix3x3& drot,bool local);
+       virtual void    ApplyTorque(const MT_Vector3& torque,bool local);
+       virtual void    ApplyForce(const MT_Vector3& force,bool local);
+       virtual MT_Vector3 GetLinearVelocity();
+       virtual MT_Vector3 GetVelocity(const MT_Point3& pos);
+       virtual void    SetAngularVelocity(const MT_Vector3& ang_vel,bool local);
+       virtual void    SetLinearVelocity(const MT_Vector3& lin_vel,bool local);
+       virtual void    getOrientation(MT_Quaternion& orn);
+       virtual void setOrientation(const MT_Quaternion& orn);
+       virtual void setPosition(const MT_Point3& pos);
+       virtual void setScaling(const MT_Vector3& scaling);
+       virtual MT_Scalar       GetMass();
+       virtual MT_Vector3      getReactionForce();
+       virtual void    setRigidBody(bool rigid);
+
+       virtual void    resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
+
+       virtual void    SuspendDynamics();
+       virtual void    RestoreDynamics();
+
+       virtual SG_Controller*  GetReplica(class SG_Node* destnode);
+
+       void    SetDyna(bool isDynamic) {
+               m_bDyna = isDynamic;
+       }
+
+
+       virtual void    SetSumoTransform(bool nondynaonly);
+       // todo: remove next line !
+       virtual void    SetSimulatedTime(double time);
+       
+       // call from scene graph to update
+       virtual bool Update(double time);
+       void*   GetUserData() { return m_userdata;}
+       
+       void
+       SetOption(
+               int option,
+               int value
+       ){
+               // intentionally empty
+       };
+
+};
+
+#endif //KX_BULLET2PHYSICS_CONTROLLER
\ No newline at end of file
index 8631048dc4a7e448c72e0095d281f64ef6eceada..60a9d560a0617e2faa2baa8ccf0133be8077910a 100644 (file)
@@ -35,6 +35,7 @@
 /* These are defined by the build system... */
 //#define USE_SUMO_SOLID
 //#define USE_ODE
+//#define USE_BULLET
 
 class RAS_MeshObject;
 class KX_Scene;
@@ -115,5 +116,18 @@ bool KX_ReInstanceShapeFromMesh(RAS_MeshObject* meshobj);
 
 #endif
 
+#ifdef USE_BULLET
+
+void   KX_ConvertBulletObject( class   KX_GameObject* gameobj,
+       class   RAS_MeshObject* meshobj,
+       class   KX_Scene* kxscene,
+       struct  PHY_ShapeProps* shapeprops,
+       struct  PHY_MaterialProps*      smmaterial,
+       struct  KX_ObjectProperties*    objprop);
+       
+void   KX_ClearBulletSharedShapes();
+//bool KX_ReInstanceShapeFromMesh(RAS_MeshObject* meshobj);
+
+#endif
 #endif //KX_CONVERTPHYSICSOBJECTS
 
index c877b699860efdbbbd6e29ef55aa7e7433a0378d..bb33d0aab31d6bb6f16fd89c8f24b7e19d80e524 100644 (file)
@@ -63,6 +63,7 @@
 // USE_SUMO_SOLID is defined in headerfile KX_ConvertPhysicsObject.h
 #ifdef USE_SUMO_SOLID
 
+
 #include "SumoPhysicsEnvironment.h"
 #include "KX_SumoPhysicsController.h"
 
@@ -577,6 +578,10 @@ void       KX_ClearSumoSharedShapes()
        map_gamemesh_to_instance.clear();
 }
 
+
+
+
+
 #endif //USE_SUMO_SOLID
 
 
@@ -651,3 +656,390 @@ void      KX_ConvertODEEngineObject(KX_GameObject* gameobj,
 
 
 #endif // USE_ODE
+
+
+#ifdef USE_BULLET
+
+#include "CcdPhysicsEnvironment.h"
+#include "CcdPhysicsController.h"
+
+#include "KX_BulletPhysicsController.h"
+#include "CollisionShapes/BoxShape.h"
+#include "CollisionShapes/SphereShape.h"
+#include "CollisionShapes/TriangleMeshInterface.h"
+#include "CollisionShapes/ConeShape.h"
+#include "CollisionShapes/ConvexShape.h"
+#include "CollisionShapes/CylinderShape.h"
+#include "CollisionShapes/MultiSphereShape.h"
+#include "CollisionShapes/ConvexHullShape.h"
+#include "CollisionShapes/TriangleMesh.h"
+#include "CollisionShapes/TriangleMeshShape.h"
+
+
+static GEN_Map<GEN_HashedPtr,CollisionShape*>  map_gamemesh_to_bulletshape;
+
+// forward declarations
+static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool polytope)
+{
+       if (!meshobj)
+               return 0;
+
+       CollisionShape* collisionMeshShape = 0;
+       ConvexHullShape* convexHullShape = 0;
+       TriangleMeshShape* concaveShape = 0;
+
+       TriangleMesh* collisionMeshData = 0;
+
+       //see if there is any polygons, if not, bail out.
+
+       int numUsedPolygons = 0;
+       int numPoints = 0;
+       SimdVector3* points = 0;
+
+       CollisionShape** shapeptr = map_gamemesh_to_bulletshape[GEN_HashedPtr(meshobj)];
+
+       // Mesh has already been converted: reuse
+       if (shapeptr)
+       {
+               //return *shapeptr;
+       }
+
+       // Mesh has no polygons!
+       int numpolys = meshobj->NumPolygons();
+       if (!numpolys)
+       {
+               return NULL;
+       }
+
+       // Count the number of collision polygons and check they all come from the same 
+       // vertex array
+       int numvalidpolys = 0;
+       int vtxarray = -1;
+       RAS_IPolyMaterial *poly_material = NULL;
+       bool reinstance = true;
+
+       for (int p=0; p<numpolys; p++)
+       {
+               RAS_Polygon* poly = meshobj->GetPolygon(p);
+
+               // only add polygons that have the collisionflag set
+               if (poly->IsCollider())
+               {
+                       // check polygon is from the same vertex array
+                       if (poly->GetVertexIndexBase().m_vtxarray != vtxarray)
+                       {
+                               if (vtxarray < 0)
+                                       vtxarray = poly->GetVertexIndexBase().m_vtxarray;
+                               else
+                               {
+                                       reinstance = false;
+                                       vtxarray = -1;
+                               }
+                       }
+
+                       // check poly is from the same material
+                       if (poly->GetMaterial()->GetPolyMaterial() != poly_material)
+                       {
+                               if (poly_material)
+                               {
+                                       reinstance = false;
+                                       poly_material = NULL;
+                               }
+                               else
+                                       poly_material = poly->GetMaterial()->GetPolyMaterial();
+                       }
+
+                       // count the number of collision polys
+                       numvalidpolys++;
+
+                       // We have one collision poly, and we can't reinstance, so we
+                       // might as well break here.
+                       if (!reinstance)
+                               break;
+               }
+       }
+
+       // No collision polygons
+       if (numvalidpolys < 1)
+               return NULL;
+
+
+       if (polytope)
+       {
+               convexHullShape = new ConvexHullShape(points,numPoints);
+               collisionMeshShape = convexHullShape;
+       } else
+       {
+               collisionMeshData = new TriangleMesh();
+               concaveShape = new TriangleMeshShape(collisionMeshData);
+               collisionMeshShape = concaveShape;
+
+       }
+
+
+       numvalidpolys = 0;
+
+       for (int p2=0; p2<numpolys; p2++)
+       {
+               RAS_Polygon* poly = meshobj->GetPolygon(p2);
+
+               // only add polygons that have the collisionflag set
+               if (poly->IsCollider())
+               {   
+                       //Bullet can raycast any shape, so
+                       if (polytope)
+                       {
+                               for (int i=0;i<poly->VertexCount();i++)
+                               {
+                                       const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
+                                               poly->GetVertexIndexBase().m_indexarray[i],
+                                               poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+                                       SimdPoint3 point(vtx[0],vtx[1],vtx[2]);
+                                       convexHullShape->AddPoint(point);
+                               }
+                               if (poly->VertexCount())
+                                       numvalidpolys++;
+
+                       } else
+                       {
+                               {
+                                       const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
+                                               poly->GetVertexIndexBase().m_indexarray[2],
+                                               poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+                                       SimdPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
+                                       vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
+                                               poly->GetVertexIndexBase().m_indexarray[1],
+                                               poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+                                       SimdPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
+                                       vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
+                                               poly->GetVertexIndexBase().m_indexarray[0],
+                                               poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+                                       SimdPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
+                                       collisionMeshData->AddTriangle(vertex0,vertex1,vertex2);
+                                       numvalidpolys++;
+                               }
+                               if (poly->VertexCount() == 4)
+                               {
+                                       const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
+                                               poly->GetVertexIndexBase().m_indexarray[3],
+                                               poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+                                       SimdPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
+                                       vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
+                                               poly->GetVertexIndexBase().m_indexarray[2],
+                                               poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+                                       SimdPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
+                                       vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, 
+                                               poly->GetVertexIndexBase().m_indexarray[0],
+                                               poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+                                       SimdPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
+                                       collisionMeshData->AddTriangle(vertex0,vertex1,vertex2);
+                                       numvalidpolys++;
+                               }
+
+                       }               
+               }
+       }
+
+
+
+       if (numvalidpolys > 0)
+       {
+               //map_gamemesh_to_bulletshape.insert(GEN_HashedPtr(meshobj),collisionMeshShape);
+               return collisionMeshShape;
+       }
+
+       delete collisionMeshShape;
+       return NULL;
+
+}
+
+
+
+void   KX_ConvertBulletObject( class   KX_GameObject* gameobj,
+       class   RAS_MeshObject* meshobj,
+       class   KX_Scene* kxscene,
+       struct  PHY_ShapeProps* shapeprops,
+       struct  PHY_MaterialProps*      smmaterial,
+       struct  KX_ObjectProperties*    objprop)
+{
+
+               CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment();
+       assert(env);
+       
+
+       bool dyna = false;
+       CcdConstructionInfo ci;
+       class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
+
+       ci.m_MotionState = motionstate;
+       ci.m_gravity = SimdVector3(0,0,0);
+       ci.m_localInertiaTensor =SimdVector3(0,0,0);
+       ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f;
+       
+       ci.m_localInertiaTensor = SimdVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
+       
+       SimdTransform trans;
+       trans.setIdentity();
+       
+       CollisionShape* bm = 0;
+
+       switch (objprop->m_boundclass)
+       {
+       case KX_BOUNDSPHERE:
+               {
+                       float radius = objprop->m_radius;
+                       SimdVector3 inertiaHalfExtents (
+                               radius,
+                               radius,
+                               radius);
+                       
+                       //blender doesn't support multisphere, but for testing:
+
+                       //bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1);
+                       bm = new SphereShape(objprop->m_radius);
+                       bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+                       break;
+               };
+       case KX_BOUNDBOX:
+               {
+                       MT_Vector3 halfExtents (
+                               objprop->m_boundobject.box.m_extends[0],
+                       objprop->m_boundobject.box.m_extends[1],
+                       objprop->m_boundobject.box.m_extends[2]);
+
+                       halfExtents /= 2.f;
+
+                       SimdVector3 he (halfExtents[0]-CONVEX_DISTANCE_MARGIN ,halfExtents[1]-CONVEX_DISTANCE_MARGIN ,halfExtents[2]-CONVEX_DISTANCE_MARGIN );
+                       he = he.absolute();
+
+
+                       bm = new BoxShape(he);
+                       bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+
+                       break;
+               };
+       case KX_BOUNDCYLINDER:
+               {
+                       SimdVector3 halfExtents (
+                               objprop->m_boundobject.c.m_radius,
+                               objprop->m_boundobject.c.m_radius,
+                               objprop->m_boundobject.c.m_height * 0.5f
+                       );
+                       bm = new CylinderShapeZ(halfExtents);
+                       bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+
+                       break;
+               }
+
+               case KX_BOUNDCONE:
+               {
+                               SimdVector3 halfExtents (objprop->m_boundobject.box.m_extends[0],
+                               objprop->m_boundobject.box.m_extends[1],
+                               objprop->m_boundobject.box.m_extends[2]);
+
+
+                               halfExtents /= 2.f;
+                               SimdVector3&    he  = halfExtents;
+                               SimdTransform& tr = trans;
+
+                               bm = new ConeShape(objprop->m_boundobject.c.m_radius,objprop->m_boundobject.c.m_height);
+                               bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+
+
+
+                       break;
+               }
+               case KX_BOUNDPOLYTOPE:
+                       {
+                               bm = CreateBulletShapeFromMesh(meshobj,true);
+                               if (bm)
+                               {
+                                       bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+                               }
+                               break;
+                       }
+               case KX_BOUNDMESH:
+                       {
+                               if (!ci.m_mass)
+                               {                               
+                                       bm = CreateBulletShapeFromMesh(meshobj,false);
+                                       ci.m_localInertiaTensor.setValue(0.f,0.f,0.f);
+                                       //no moving concave meshes, so don't bother calculating inertia
+                                       //bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+                               }
+
+                               break;
+                       }
+
+       default:
+               //interpret the shape as a concave triangle-mesh
+               {
+                       if (meshobj)
+                       {
+                       //      assert(0);
+
+                                       /*
+                               meshobj->ScheduleCollisionPolygons();
+
+                               KX_DeformableMesh* gfxmesh = new KX_DeformableMesh(meshobj);
+                               gfxmesh->sendFixedMapping();
+                               //trianglemesh
+                               bm = new TriangleMeshInterface(gfxmesh,trans);
+                               */
+                       }
+               }
+       }
+
+
+//     ci.m_localInertiaTensor.setValue(0.1f,0.1f,0.1f);
+
+       if (!bm)
+               return;
+
+       ci.m_collisionShape = bm;
+       ci.m_broadphaseHandle = 0;
+       ci.m_friction = smmaterial->m_friction;
+       ci.m_restitution = smmaterial->m_restitution;
+
+
+       ci.m_linearDamping = shapeprops->m_lin_drag;
+       ci.m_angularDamping = shapeprops->m_ang_drag;
+
+       KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,dyna);
+       env->addCcdPhysicsController( physicscontroller);
+
+       
+       gameobj->SetPhysicsController(physicscontroller);
+       physicscontroller->setNewClientInfo(gameobj);                                           
+       gameobj->GetSGNode()->AddSGController(physicscontroller);
+
+       bool isActor = objprop->m_isactor;
+       STR_String materialname;
+       if (meshobj)
+               materialname = meshobj->GetMaterialName(0);
+
+       const char* matname = materialname.ReadPtr();
+
+
+       physicscontroller->SetObject(gameobj->GetSGNode());
+                               
+
+}
+       
+void   KX_ClearBulletSharedShapes()
+{
+       int numshapes = map_gamemesh_to_bulletshape.size();
+       int i;
+       CollisionShape*shape=0;
+       for (i=0;i<numshapes ;i++)
+       {
+               shape = *map_gamemesh_to_bulletshape.at(i);
+               //delete shape;
+       }
+       
+       map_gamemesh_to_bulletshape.clear();
+       
+}
+
+
+#endif
index 2e76103ac13990d568792e3534494c28da3453eb..10bf70849bf5f63d7954dee46d889e783e3a6048 100644 (file)
@@ -321,7 +321,7 @@ void KX_KetsjiEngine::NextFrame()
        m_deltatime += curtime - m_previoustime;
        float   realDeltaTime = curtime - m_previoustime;
 
-       m_previoustime = curtime;
+       
        double localtime = curtime - m_deltatime;
 
        // Compute the number of logic frames to do each update (fixed tic bricks)
@@ -332,6 +332,7 @@ void KX_KetsjiEngine::NextFrame()
        
        while (frames)
        {
+
                localtime += 1.0/m_ticrate;
                for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
                // for each scene, call the proceed functions
@@ -388,6 +389,7 @@ void KX_KetsjiEngine::NextFrame()
                                // many iterations of the physics solver.
                                m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
                                scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime);
+                               m_previoustime = curtime;
                        } // suspended
        
                        DoSound(scene);
index 9c1267ff34c8346d9c81e89a782b75ac329fafd8..bafc8620dfd550f737751a09cd7fdd763ffcdfc6 100644 (file)
@@ -39,7 +39,8 @@ enum  e_PhysicsEngine
                UseEnji     =  1,
                UseSumo     =  2,
                UseDynamo   =  3,
-               UseODE      =  4
+               UseODE      =  4,
+               UseBullet       =       5,
 };
 
 #endif //__KX_PHYSICSENGINEENUMS
index de2850864f1e6542f2f07616030df0ac45e39b2a..cabba5cacb0857a9a3c104369dbf373a303cd1f8 100644 (file)
@@ -207,7 +207,7 @@ KX_Scene::~KX_Scene()
        {
                delete m_bucketmanager;
        }
-       Py_DECREF(m_attrlist);
+       //Py_DECREF(m_attrlist);
 }
 
 
index d403d5100fc1a85f0d730e38efd9b8fab753d73e..a0fe068ab5ce23c30b2ee26b08409c1c427917c4 100644 (file)
@@ -20,6 +20,7 @@
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
  
+#define USE_ODE
 #ifdef USE_ODE
 
 #include "OdePhysicsController.h"
index 54d94351815e493e99015b0a22db232ac5eb8b60..9a489a3855385a9a03dd93ed5f8e8f5f5028e866 100644 (file)
@@ -24,7 +24,7 @@
 #include "OdePhysicsController.h"
 
 // Ode
-#include <ode/config.h>
+//#include <ode/config.h>
 #include <ode/ode.h>
 #include <../ode/src/joint.h>
 #include <ode/odemath.h>
@@ -105,8 +105,10 @@ bool               ODEPhysicsEnvironment::proceedDeltaTime(double  curTime,float timeStep1)
                int m_odeContacts = GetNumOdeContacts();
                
                //physics integrator + resolver update
-               dWorldStep (m_OdeWorld,deltaTime);
-               
+               //dWorldStep (m_OdeWorld,deltaTime);
+               dWorldQuickStep (m_OdeWorld,deltaTime);
+               //dWorldID w, dReal stepsize)
+
                //clear collision points
                this->ClearOdeContactGroup();
        }
index f800a5494cb2eb57e9f5408bb16f835d0d3175a4..340e4b214674be1bb8b547c8ab971bbe1ed96f7f 100644 (file)
 #ifndef __PHY_DYNAMIC_TYPES
 #define __PHY_DYNAMIC_TYPES
 
-/// PHY_ScalarType enumerates possible scalar types.
-/// See the PHY_IMeshInterface for its use
-typedef enum PHY_ScalarType {
-       PHY_FLOAT,
-       PHY_DOUBLE,
-       PHY_INTEGER,
-       PHY_SHORT,
-       PHY_FIXEDPOINT88
-} PHY_ScalarType;
 
 class  PHY_ResponseTable;