diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-11-21 03:53:40 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-11-21 03:53:40 +0300 |
commit | 46234f90cee9b3967cb6361661ce47b455cbaa57 (patch) | |
tree | 8f32252f55c29694c1fa619d00a67ea4b4941099 /source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | |
parent | 4bbbabd04957d6564d43b076e1e144f0bb4da439 (diff) |
Removed old Blender/extern/bullet, and upgraded game engine to use Bullet 2.x
All platforms/build systems: either upgrade to use extern/bullet2, or disable the game engine until the build is fixed.
Diffstat (limited to 'source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 115 |
1 files changed, 53 insertions, 62 deletions
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index e08e5e7cbf1..d637df95756 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -662,19 +662,10 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj, #include "CcdPhysicsEnvironment.h" #include "CcdPhysicsController.h" -#include "BroadphaseCollision/BroadphaseInterface.h" +#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" #include "KX_BulletPhysicsController.h" -#include "CollisionShapes/BoxShape.h" -#include "CollisionShapes/SphereShape.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" -#include "CollisionShapes/BvhTriangleMeshShape.h" +#include "btBulletDynamicsCommon.h" #ifdef WIN32 #if _MSC_VER >= 1310 @@ -691,26 +682,26 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj, #endif //WIN32 -static GEN_Map<GEN_HashedPtr,CollisionShape*> map_gamemesh_to_bulletshape; +static GEN_Map<GEN_HashedPtr,btCollisionShape*> map_gamemesh_to_bulletshape; // forward declarations -static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool polytope) +static btCollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool polytope) { if (!meshobj) return 0; - CollisionShape* collisionMeshShape = 0; - ConvexHullShape* convexHullShape = 0; - TriangleMeshShape* concaveShape = 0; + btCollisionShape* collisionMeshShape = 0; + btConvexHullShape* convexHullShape = 0; + btTriangleMeshShape* concaveShape = 0; - TriangleMesh* collisionMeshData = 0; + btTriangleMesh* collisionMeshData = 0; //see if there is any polygons, if not, bail out. int numPoints = 0; - SimdVector3* points = 0; + btVector3* points = 0; - CollisionShape** shapeptr = map_gamemesh_to_bulletshape[GEN_HashedPtr(meshobj)]; + btCollisionShape** shapeptr = map_gamemesh_to_bulletshape[GEN_HashedPtr(meshobj)]; // Mesh has already been converted: reuse if (shapeptr) @@ -780,12 +771,12 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p if (polytope) { - convexHullShape = new ConvexHullShape(points,numPoints); + convexHullShape = new btConvexHullShape(&points[0].getX(),numPoints); collisionMeshShape = convexHullShape; } else { - collisionMeshData = new TriangleMesh(); -// concaveShape = new TriangleMeshShape(collisionMeshData); + collisionMeshData = new btTriangleMesh(); +// concaveShape = new btTriangleMeshShape(collisionMeshData); //collisionMeshShape = concaveShape; } @@ -808,8 +799,8 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p 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); + btPoint3 point(vtx[0],vtx[1],vtx[2]); + convexHullShape->addPoint(point); } if (poly->VertexCount()) numvalidpolys++; @@ -820,16 +811,16 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p 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]); + btPoint3 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]); + btPoint3 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); + btPoint3 vertex2(vtx[0],vtx[1],vtx[2]); + collisionMeshData->addTriangle(vertex0,vertex1,vertex2); numvalidpolys++; } if (poly->VertexCount() == 4) @@ -837,16 +828,16 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p 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]); + btPoint3 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]); + btPoint3 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); + btPoint3 vertex2(vtx[0],vtx[1],vtx[2]); + collisionMeshData->addTriangle(vertex0,vertex1,vertex2); numvalidpolys++; } @@ -862,10 +853,10 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p //map_gamemesh_to_bulletshape.insert(GEN_HashedPtr(meshobj),collisionMeshShape); if (!polytope) { - concaveShape = new BvhTriangleMeshShape( collisionMeshData ); - //concaveShape = new TriangleMeshShape( collisionMeshData ); + concaveShape = new btBvhTriangleMeshShape( collisionMeshData ); + //concaveShape = new btTriangleMeshShape( collisionMeshData ); - concaveShape->RecalcLocalAabb(); + concaveShape->recalcLocalAabb(); collisionMeshShape = concaveShape; } @@ -901,34 +892,34 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, if (objprop->m_ghost) { - ci.m_collisionFlags |= CollisionObject::noContactResponse; + ci.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; } if (!objprop->m_dyna) { - ci.m_collisionFlags |= CollisionObject::isStatic; + ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT; } ci.m_MotionState = motionstate; - ci.m_gravity = SimdVector3(0,0,0); - ci.m_localInertiaTensor =SimdVector3(0,0,0); + 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 = SimdVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f); + ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f); - SimdTransform trans; + btTransform trans; trans.setIdentity(); - CollisionShape* bm = 0; + btCollisionShape* bm = 0; switch (objprop->m_boundclass) { case KX_BOUNDSPHERE: { float radius = objprop->m_radius; - SimdVector3 inertiaHalfExtents ( + btVector3 inertiaHalfExtents ( radius, radius, radius); @@ -936,8 +927,8 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, //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); + bm = new btSphereShape(objprop->m_radius); + bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); break; }; case KX_BOUNDBOX: @@ -949,41 +940,41 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, halfExtents /= 2.f; - //SimdVector3 he (halfExtents[0]-CONVEX_DISTANCE_MARGIN ,halfExtents[1]-CONVEX_DISTANCE_MARGIN ,halfExtents[2]-CONVEX_DISTANCE_MARGIN ); + //btVector3 he (halfExtents[0]-CONVEX_DISTANCE_MARGIN ,halfExtents[1]-CONVEX_DISTANCE_MARGIN ,halfExtents[2]-CONVEX_DISTANCE_MARGIN ); //he = he.absolute(); - SimdVector3 he (halfExtents[0],halfExtents[1],halfExtents[2]); + btVector3 he (halfExtents[0],halfExtents[1],halfExtents[2]); he = he.absolute(); - bm = new BoxShape(he); - bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); + bm = new btBoxShape(he); + bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); break; }; case KX_BOUNDCYLINDER: { - SimdVector3 halfExtents ( + btVector3 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); + bm = new btCylinderShapeZ(halfExtents); + bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); break; } case KX_BOUNDCONE: { - SimdVector3 halfExtents (objprop->m_boundobject.box.m_extends[0], + btVector3 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; - bm = new ConeShape(objprop->m_boundobject.c.m_radius,objprop->m_boundobject.c.m_height); - bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); + bm = new btConeShape(objprop->m_boundobject.c.m_radius,objprop->m_boundobject.c.m_height); + bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); break; } @@ -992,7 +983,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, bm = CreateBulletShapeFromMesh(meshobj,true); if (bm) { - bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); + bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); } break; } @@ -1003,7 +994,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, 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); + //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); } break; @@ -1034,7 +1025,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, if (!bm) return; - bm->SetMargin(0.06); + bm->setMargin(0.06); #ifdef TEST_SIMD_HULL if (bm->IsPolyhedral()) @@ -1048,7 +1039,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, //first 4 points should not be co-planar, so add central point to satisfy MakeHull points[0] = Point3(0.f,0.f,0.f); - SimdVector3 vertex; + btVector3 vertex; for (int p=0;p<numPoints;p++) { polyhedron->GetVertex(p,vertex); @@ -1089,14 +1080,14 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, physicscontroller->setNewClientInfo(gameobj->getClientInfo()); if (objprop->m_disableSleeping) - physicscontroller->GetRigidBody()->SetActivationState(DISABLE_DEACTIVATION); + physicscontroller->GetRigidBody()->setActivationState(DISABLE_DEACTIVATION); if (objprop->m_dyna && !objprop->m_angular_rigidbody) { /* //setting the inertia could achieve similar results to constraint the up //but it is prone to instability, so use special 'Angular' constraint - SimdVector3 inertia = physicscontroller->GetRigidBody()->getInvInertiaDiagLocal(); + btVector3 inertia = physicscontroller->GetRigidBody()->getInvInertiaDiagLocal(); inertia.setX(0.f); inertia.setZ(0.f); @@ -1137,7 +1128,7 @@ void KX_ClearBulletSharedShapes() { int numshapes = map_gamemesh_to_bulletshape.size(); int i; - CollisionShape*shape=0; + btCollisionShape*shape=0; for (i=0;i<numshapes ;i++) { shape = *map_gamemesh_to_bulletshape.at(i); |