From 2d73b31aff247a08c0706125fe6eb7f3e8d06b11 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Sat, 16 Jul 2005 21:47:54 +0000 Subject: [PATCH] preparation for bullet physics --- source/blender/blenlib/intern/storage.c | 1 + source/blender/render/intern/include/zblur.h | 58 ++- source/blender/src/buttons_shading.c | 9 +- .../Converter/BL_BlenderDataConversion.cpp | 12 +- .../Converter/KX_BlenderSceneConverter.cpp | 23 +- .../Ketsji/KX_BulletPhysicsController.cpp | 138 ++++++ .../Ketsji/KX_BulletPhysicsController.h | 69 +++ .../Ketsji/KX_ConvertPhysicsObject.h | 14 + .../Ketsji/KX_ConvertPhysicsObjects.cpp | 392 ++++++++++++++++++ source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 4 +- .../gameengine/Ketsji/KX_PhysicsEngineEnums.h | 3 +- source/gameengine/Ketsji/KX_Scene.cpp | 2 +- .../Physics/BlOde/OdePhysicsController.cpp | 1 + .../Physics/BlOde/OdePhysicsEnvironment.cpp | 8 +- .../Physics/common/PHY_DynamicTypes.h | 9 - 15 files changed, 715 insertions(+), 28 deletions(-) create mode 100644 source/gameengine/Ketsji/KX_BulletPhysicsController.cpp create mode 100644 source/gameengine/Ketsji/KX_BulletPhysicsController.h diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 25327c4943e..64cf2888b50 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -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); diff --git a/source/blender/render/intern/include/zblur.h b/source/blender/render/intern/include/zblur.h index a0e1c6a39ce..016cb237ba4 100644 --- a/source/blender/render/intern/include/zblur.h +++ b/source/blender/render/intern/include/zblur.h @@ -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 */ + +/* Includes */ + /*-----------------------------------------------------------*/ + + +/*-----------------------------------------------------------*/ + +/* Function */ + +/*-----------------------------------------------------------*/ + + + void add_zblur(void); + + #ifdef __cplusplus + } -#endif #endif + + +#endif + + + diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c index 7fc420c34fa..dfcc2bad78f 100644 --- a/source/blender/src/buttons_shading.c +++ b/source/blender/src/buttons_shading.c @@ -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) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 825e70ac240..3edd9ea5818 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -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;iGetCount();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 - diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 283710a5d5b..f8a628bd0c7 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -45,6 +45,10 @@ //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 index 00000000000..c9168622320 --- /dev/null +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -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 index 00000000000..9e9b0816cbe --- /dev/null +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h @@ -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 diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index 8631048dc4a..60a9d560a06 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -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 diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index c877b699860..bb33d0aab31 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -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 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; pGetPolygon(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; p2GetPolygon(p2); + + // only add polygons that have the collisionflag set + if (poly->IsCollider()) + { + //Bullet can raycast any shape, so + if (polytope) + { + for (int i=0;iVertexCount();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;iStartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime); + m_previoustime = curtime; } // suspended DoSound(scene); diff --git a/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h b/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h index 9c1267ff34c..bafc8620dfd 100644 --- a/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h +++ b/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h @@ -39,7 +39,8 @@ enum e_PhysicsEngine UseEnji = 1, UseSumo = 2, UseDynamo = 3, - UseODE = 4 + UseODE = 4, + UseBullet = 5, }; #endif //__KX_PHYSICSENGINEENUMS diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index de2850864f1..cabba5cacb0 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -207,7 +207,7 @@ KX_Scene::~KX_Scene() { delete m_bucketmanager; } - Py_DECREF(m_attrlist); + //Py_DECREF(m_attrlist); } diff --git a/source/gameengine/Physics/BlOde/OdePhysicsController.cpp b/source/gameengine/Physics/BlOde/OdePhysicsController.cpp index d403d5100fc..a0fe068ab5c 100644 --- a/source/gameengine/Physics/BlOde/OdePhysicsController.cpp +++ b/source/gameengine/Physics/BlOde/OdePhysicsController.cpp @@ -20,6 +20,7 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ +#define USE_ODE #ifdef USE_ODE #include "OdePhysicsController.h" diff --git a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.cpp b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.cpp index 54d94351815..9a489a38553 100644 --- a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.cpp +++ b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.cpp @@ -24,7 +24,7 @@ #include "OdePhysicsController.h" // Ode -#include +//#include #include #include <../ode/src/joint.h> #include @@ -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(); } diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index f800a5494cb..340e4b21467 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -32,15 +32,6 @@ #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;