From: <lul...@us...> - 2011-06-29 13:39:38
|
Revision: 36582 http://crystal.svn.sourceforge.net/crystal/?rev=36582&view=rev Author: luluathena Date: 2011-06-29 13:39:29 +0000 (Wed, 29 Jun 2011) Log Message: ----------- Lulu: Fix some errors. Add the code about kinematic camera, sector and collision filter. TODO: implement ghost camera in phystut2, test collision filter, and add spring joint demo. Modified Paths: -------------- CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.cpp CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.h CS/branches/soc2011/collphys/include/ivaria/bullet2.h CS/branches/soc2011/collphys/include/ivaria/collision2.h CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.cpp CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.h CS/branches/soc2011/collphys/plugins/physics2/bullet/colliders2.cpp CS/branches/soc2011/collphys/plugins/physics2/bullet/collisionobject2.cpp CS/branches/soc2011/collphys/plugins/physics2/bullet/collisionobject2.h CS/branches/soc2011/collphys/plugins/physics2/bullet/common2.h CS/branches/soc2011/collphys/plugins/physics2/bullet/joint2.cpp CS/branches/soc2011/collphys/plugins/physics2/bullet/rigidbody2.cpp CS/branches/soc2011/collphys/plugins/physics2/bullet/rigidbody2.h CS/branches/soc2011/collphys/plugins/physics2/bullet/softbody2.cpp CS/branches/soc2011/collphys/plugins/physics2/bullet/softbody2.h Modified: CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.cpp =================================================================== --- CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.cpp 2011-06-28 17:03:04 UTC (rev 36581) +++ CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.cpp 2011-06-29 13:39:29 UTC (rev 36582) @@ -16,9 +16,9 @@ Simple::Simple() : DemoApplication ("CrystalSpace.PhysTut2"), isSoftBodyWorld (true), environment (ENVIRONMENT_WALLS), solver (0), -do_bullet_debug (true), do_soft_debug (false), remainingStepDuration (0.0f), -allStatic (false), pauseDynamic (false), dynamicSpeed (1.0f), physicalCameraMode (CAMERA_DYNAMIC), -dragging (false), softDragging (false), debugMode (CS::Physics2::Bullet2::DEBUG_JOINTS) +do_bullet_debug (false), do_soft_debug (true), allStatic (false), +pauseDynamic (false), dynamicSpeed (1.0f), physicalCameraMode (CAMERA_DYNAMIC), +dragging (false), softDragging (false), remainingStepDuration (0.0f), debugMode (CS::Physics2::Bullet2::DEBUG_COLLIDERS) { localTrans.Identity (); } @@ -55,7 +55,7 @@ const float speed = elapsed_time / 1000.0; // Camera is controlled by a rigid body - if (physicalCameraMode == CAMERA_DYNAMIC) + if (physicalCameraMode == CAMERA_DYNAMIC || physicalCameraMode == CAMERA_KINEMATIC) { if (kbd->GetKeyState (CSKEY_RIGHT)) view->GetCamera()->GetTransform().RotateThis (CS_VEC_ROT_RIGHT, speed); @@ -65,15 +65,32 @@ view->GetCamera()->GetTransform().RotateThis (CS_VEC_TILT_UP, speed); if (kbd->GetKeyState (CSKEY_PGDN)) view->GetCamera()->GetTransform().RotateThis (CS_VEC_TILT_DOWN, speed); - if (kbd->GetKeyState (CSKEY_UP)) + if (physicalCameraMode == CAMERA_DYNAMIC) { - cameraBody->SetLinearVelocity (view->GetCamera()->GetTransform() - .GetT2O () * csVector3 (0, 0, 5)); + if (kbd->GetKeyState (CSKEY_UP)) + { + cameraBody->SetLinearVelocity (view->GetCamera()->GetTransform() + .GetT2O () * csVector3 (0, 0, 5)); + } + if (kbd->GetKeyState (CSKEY_DOWN)) + { + cameraBody->SetLinearVelocity (view->GetCamera()->GetTransform() + .GetT2O () * csVector3 (0, 0, -5)); + } } - if (kbd->GetKeyState (CSKEY_DOWN)) + else { - cameraBody->SetLinearVelocity (view->GetCamera()->GetTransform() - .GetT2O () * csVector3 (0, 0, -5)); + csOrthoTransform trans = view->GetCamera()->GetTransform(); + if (kbd->GetKeyState (CSKEY_UP)) + { + trans.SetOrigin (trans.GetOrigin () + trans.GetT2O () * csVector3 (0, 0, 5) * speed); + cameraBody->SetTransform (trans); + } + if (kbd->GetKeyState (CSKEY_DOWN)) + { + trans.SetOrigin (trans.GetOrigin () + trans.GetT2O () * csVector3 (0, 0, -5) * speed); + cameraBody->SetTransform (trans); + } } } @@ -142,11 +159,7 @@ if (!pauseDynamic) physicalSector->Step (speed / dynamicSpeed); - // Update camera position if it is controlled by a rigid body. - // (in this mode we want to control the orientation of the camera, - // so we update the camera position by ourselves instead of using - // 'cameraBody->AttachCamera (camera)') - if (physicalCameraMode == CAMERA_DYNAMIC) + if (physicalCameraMode == CAMERA_DYNAMIC || physicalCameraMode == CAMERA_KINEMATIC) view->GetCamera ()->GetTransform ().SetOrigin (cameraBody->GetTransform ().GetOrigin ()); @@ -198,7 +211,7 @@ CS::Physics2::iSoftBody* softBody = physicalSector->GetSoftBody (i); csRef<CS::Physics2::Bullet2::iSoftBody> bulletSoftBody = scfQueryInterface<CS::Physics2::Bullet2::iSoftBody> (softBody); - if (softBody->GetTriangleCount ()) + if (softBody->GetVertexCount ()) bulletSoftBody->DebugDraw (view); } } @@ -445,21 +458,19 @@ && hitResult.object->GetObjectType () == CS::Collision2::COLLISION_OBJECT_PHYSICAL) { // Remove the body and the mesh from the simulation, and put them in the clipboard - + + clipboardBody = hitResult.object->QueryPhysicalBody (); + clipboardMovable = hitResult.object->GetAttachedMovable (); + if (clipboardBody->GetBodyType () == CS::Physics2::BODY_RIGID) { - clipboardBody = hitResult.object->QueryPhysicalBody (); - clipboardMovable = hitResult.object->GetAttachedMovable (); - CS::Physics2::iRigidBody* rigidBody = clipboardBody->QueryRigidBody (); if (rigidBody->GetState () == CS::Physics2::STATE_DYNAMIC) { physicalSector->RemoveRigidBody (clipboardBody->QueryRigidBody ()); - room->GetMeshes ()->Remove (clipboardMovable->GetSceneNode ()->QueryMesh ()); + //room->GetMeshes ()->Remove (clipboardMovable->GetSceneNode ()->QueryMesh ()); } } - else - physicalSector->RemoveSoftBody (clipboardBody->QuerySoftBody ()); // Update the display of the dynamics debugger //dynamicsDebugger->UpdateDisplay (); @@ -488,8 +499,6 @@ if (clipboardBody->GetBodyType () == CS::Physics2::BODY_RIGID) physicalSector->AddRigidBody (clipboardBody->QueryRigidBody ()); - if (clipboardMovable) - room->GetMeshes ()->Add (clipboardMovable->GetSceneNode ()->QueryMesh ()); clipboardBody = 0; clipboardMovable = 0; @@ -803,8 +812,7 @@ view->GetCamera ()->GetTransform ().SetOrigin (csVector3 (0, 30, -3)); } - // Initialize the dynamics debugger - //dynamicsDebugger->SetDebugSector (room); + collisionSector->SetSector (room); // Preload some meshes and materials iTextureWrapper* txt = loader->LoadTexture ("spark", @@ -966,11 +974,11 @@ cameraBody->SetElasticity (0.8f); cameraBody->SetFriction (10.0f); cameraBody->RebuildObject (); - physicalSector->AddRigidBody (cameraBody); // Make it kinematic cameraBody->SetState (CS::Physics2::STATE_KINEMATIC); + physicalSector->AddRigidBody (cameraBody); // Attach the camera to the body so as to benefit of the default // kinematic callback cameraBody->SetAttachedMovable (view->GetCamera ()->QuerySceneNode ()->GetMovable ()); @@ -989,8 +997,7 @@ const csOrthoTransform& tc = view->GetCamera ()->GetTransform (); // Create the mesh. - csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (boxFact, "box", room)); - //meshes.Push (mesh); + csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (boxFact, "box")); // Create a body and attach the mesh. csRef<CS::Physics2::iRigidBody> rb = physicalSystem->CreateRigidBody (); @@ -1052,8 +1059,7 @@ ballFact->HardTransform (t); // Create the mesh. - csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (ballFact, "ball", room)); - //meshes.Push (mesh); + csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (ballFact, "ball")); iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName ("spark"); mesh->GetMeshObject ()->SetMaterialWrapper (mat); @@ -1163,8 +1169,7 @@ // Create the mesh. csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper ( - cylinderFact, "cylinder", room)); - //meshes.Push (mesh); + cylinderFact, "cylinder")); iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName ("spark"); mesh->GetMeshObject ()->SetMaterialWrapper (mat); @@ -1224,8 +1229,7 @@ // Create the mesh. csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper ( - capsuleFact, "capsule", room)); - //meshes.Push (mesh); + capsuleFact, "capsule")); iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName ("spark"); mesh->GetMeshObject ()->SetMaterialWrapper (mat); @@ -1280,9 +1284,7 @@ tc.SetOrigin (tc.This2Other (csVector3 (0, 0, 3))); // Create the mesh. - csRef<iMeshWrapper> star = engine->CreateMeshWrapper (starFact, "star", - room); - //meshes.Push (star); + csRef<iMeshWrapper> star = engine->CreateMeshWrapper (starFact, "star"); star->GetMovable ()->SetTransform (tc); star->GetMovable ()->UpdateMove (); @@ -1335,8 +1337,7 @@ // Create the mesh. csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper ( - capsuleFact, "capsule", room)); - //meshes.Push (mesh); + capsuleFact, "capsule")); iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName ("spark"); mesh->GetMeshObject ()->SetMaterialWrapper (mat); @@ -1375,8 +1376,7 @@ const csOrthoTransform& tc = view->GetCamera ()->GetTransform (); // Create the mesh. - csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (meshFact, "mesh", room)); - //meshes.Push (mesh); + csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (meshFact, "mesh")); // Create a body and attach the mesh. // Create a body and attach the mesh. @@ -1405,7 +1405,7 @@ CS::Physics2::iJoint* Simple::SpawnJointed () { -#define SOFT_ANGULAR +#define SLIDE #ifdef P2P // Create and position two rigid bodies @@ -1811,8 +1811,6 @@ // Attach the two top corners body->AnchorVertex (0); body->AnchorVertex (9); - body->RebuildObject (); - physicalSector->AddSoftBody (body); // Create the cloth mesh factory csRef<iMeshFactoryWrapper> clothFact = @@ -1824,12 +1822,18 @@ // Create the mesh gmstate->SetAnimationControlFactory (softBodyAnimationFactory); csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper ( - clothFact, "cloth_body", room)); + clothFact, "cloth_body")); iMaterialWrapper* mat = CS::Material::MaterialBuilder::CreateColorMaterial (GetObjectRegistry (), "cloth", csColor4 (1.0f, 0.0f, 0.0f, 1.0f)); mesh->GetMeshObject ()->SetMaterialWrapper (mat); + body->SetAttachedMovable (mesh->GetMovable ()); + + body->RebuildObject (); + physicalSector->AddSoftBody (body); + // Init the animation control for the animation of the genmesh + // If it's a double-side soft body like cloth, you have to call SetSoftBody (body, true); csRef<iGeneralMeshState> meshState = scfQueryInterface<iGeneralMeshState> (mesh->GetMeshObject ()); csRef<CS::Physics2::iSoftBodyAnimationControl> animationControl = @@ -1879,22 +1883,25 @@ // Fling the body. body->SetLinearVelocity (tc.GetT2O () * csVector3 (0, 0, 5)); } - body->RebuildObject (); - physicalSector->AddSoftBody (body); // Create the mesh gmstate->SetAnimationControlFactory (softBodyAnimationFactory); csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper ( - ballFact, "soft_body", room)); + ballFact, "soft_body")); iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName ("spark"); mesh->GetMeshObject ()->SetMaterialWrapper (mat); + body->SetAttachedMovable (mesh->GetMovable ()); + + body->RebuildObject (); + physicalSector->AddSoftBody (body); + // Init the animation control for the animation of the genmesh - csRef<iGeneralMeshState> meshState = + /*csRef<iGeneralMeshState> meshState = scfQueryInterface<iGeneralMeshState> (mesh->GetMeshObject ()); csRef<CS::Physics2::iSoftBodyAnimationControl> animationControl = scfQueryInterface<CS::Physics2::iSoftBodyAnimationControl> (meshState->GetAnimationControl ()); - animationControl->SetSoftBody (body); + animationControl->SetSoftBody (body);*/ // This would have worked too Modified: CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.h =================================================================== --- CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.h 2011-06-28 17:03:04 UTC (rev 36581) +++ CS/branches/soc2011/collphys/apps/tutorial/phystut2/phystut2.h 2011-06-29 13:39:29 UTC (rev 36582) @@ -24,7 +24,6 @@ // Meshes csRef<iMeshFactoryWrapper> boxFact; csRef<iMeshFactoryWrapper> meshFact; - //csRefArray<iMeshWrapper> meshes; csRef<CS::Collision2::iColliderConcaveMesh> mainCollider; Modified: CS/branches/soc2011/collphys/include/ivaria/bullet2.h =================================================================== --- CS/branches/soc2011/collphys/include/ivaria/bullet2.h 2011-06-28 17:03:04 UTC (rev 36581) +++ CS/branches/soc2011/collphys/include/ivaria/bullet2.h 2011-06-29 13:39:29 UTC (rev 36582) @@ -21,7 +21,7 @@ DEBUG_NOTHING = 0, /*!< Nothing will be displayed. */ DEBUG_COLLIDERS = 1, /*!< Display the colliders of the bodies. */ DEBUG_AABB = 2, /*!< Display the axis aligned bounding boxes of the bodies. */ - DEBUG_JOINTS = 4 /*!< Display the joint positions and limits. */ + DEBUG_JOINTS = 4, /*!< Display the joint positions and limits. */ }; struct iSoftBody : public virtual iBase Modified: CS/branches/soc2011/collphys/include/ivaria/collision2.h =================================================================== --- CS/branches/soc2011/collphys/include/ivaria/collision2.h 2011-06-28 17:03:04 UTC (rev 36581) +++ CS/branches/soc2011/collphys/include/ivaria/collision2.h 2011-06-29 13:39:29 UTC (rev 36582) @@ -31,7 +31,7 @@ struct csConvexResult; struct iCollisionCallback; struct iCollisionObject; -typedef size_t CollisionGroupMask; +typedef short CollisionGroupMask; enum ColliderType { @@ -60,6 +60,12 @@ { csString name; CollisionGroupMask value; + + CollisionGroup () {} + + CollisionGroup (const char* name) + : name (name) + {} }; struct MoveResult @@ -361,7 +367,7 @@ virtual CS::Physics2::iPhysicalBody* QueryPhysicalBody () = 0; /// Set the type of the collision object. - virtual void SetObjectType (CollisionObjectType type) = 0; + virtual void SetObjectType (CollisionObjectType type, bool forceRebuild = true) = 0; /// Return the type of the collision object. virtual CollisionObjectType GetObjectType () = 0; @@ -564,6 +570,19 @@ */ virtual bool CollisionTest (iCollisionObject* object, csArray<CollisionData>& collisions) = 0; + /// Create a collision group. + virtual CollisionGroup& CreateCollisionGroup (const char* name) = 0; + + /// Find a collision group by name. + virtual CollisionGroup& FindCollisionGroup (const char* name) = 0; + + /// Set whether the two groups collide with each other. + virtual void SetGroupCollision (const char* name1, + const char* name2, bool collide) = 0; + + /// Get true if the two groups collide with each other. + virtual bool GetGroupCollision (const char* name1, const char* name2) = 0; + /** * Try to move the given object from \a fromWorld to \a toWorld and return the first collision occured if any. */ @@ -638,20 +657,6 @@ /// Create a collision sector. virtual csRef<iCollisionSector> CreateCollisionSector () = 0; - /// Create a collision group. - virtual CollisionGroup& CreateCollisionGroup (const char* name) = 0; - - /// Find a collision group by name. - virtual CollisionGroup& FindCollisionGroup (const char* name) = 0; - - /// Set whether the two groups collide with each other. - virtual void SetGroupCollision (CollisionGroup& group1, - CollisionGroup& group2, bool collide) = 0; - - /// Get true if the two groups collide with each other. - virtual bool GetGroupCollision (CollisionGroup& group1, - CollisionGroup& group2) = 0; - /** * Decompose a concave mesh in convex parts. Each convex part will be added to * the collision object as a separate iColliderConvexMesh. Modified: CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.cpp =================================================================== --- CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.cpp 2011-06-28 17:03:04 UTC (rev 36581) +++ CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.cpp 2011-06-29 13:39:29 UTC (rev 36582) @@ -1,4 +1,8 @@ #include "cssysdef.h" +#include "ivaria/softanim.h" +#include "imesh/animesh.h" +#include "iengine/scenenode.h" +#include "iengine/movable.h" #include "csgeom/sphere.h" #include "csgeom/tri.h" #include "imesh/genmesh.h" @@ -37,14 +41,14 @@ struct PointContactResult : public btCollisionWorld::ContactResultCallback { - csArray<CollisionData>& colls; + csArray<CS::Collision2::CollisionData>& colls; csBulletSystem* sys; - PointContactResult(csBulletSystem* sys, csArray<CollisionData>& collisions) : colls(collisions), sys(sys) + PointContactResult(csBulletSystem* sys, csArray<CS::Collision2::CollisionData>& collisions) : colls(collisions), sys(sys) { } virtual btScalar addSingleResult (btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) { - CollisionData data; + CS::Collision2::CollisionData data; data.penetration = cp.m_distance1 * sys->getInternalScale (); data.positionWorldOnA = BulletToCS (cp.m_positionWorldOnA, sys->getInternalScale ()); data.positionWorldOnB = BulletToCS (cp.m_positionWorldOnB, sys->getInternalScale ()); @@ -73,6 +77,30 @@ broadphase, solver, configuration); SetGravity (csVector3 (0.0f, -9.81f, 0.0f)); + + CS::Collision2::CollisionGroup defaultGroup ("Default"); + defaultGroup.value = 1; + collGroups.Push (defaultGroup); + + CS::Collision2::CollisionGroup staticGroup ("Static"); + staticGroup.value = 2; + collGroups.Push (staticGroup); + + CS::Collision2::CollisionGroup kinematicGroup ("Kinematic"); + kinematicGroup.value = 4; + collGroups.Push (kinematicGroup); + + CS::Collision2::CollisionGroup debrisGroup ("Debris"); + debrisGroup.value = 8; + collGroups.Push (debrisGroup); + + CS::Collision2::CollisionGroup sensorGroup ("Sensor"); + sensorGroup.value = 16; + collGroups.Push (sensorGroup); + + CS::Collision2::CollisionGroup characterGroup ("Character"); + characterGroup.value = 32; + collGroups.Push (characterGroup); } csBulletSector::~csBulletSector () @@ -102,20 +130,22 @@ softWorldInfo->m_gravity = gravity; } -void csBulletSector::AddCollisionObject (iCollisionObject* object) +void csBulletSector::AddCollisionObject (CS::Collision2::iCollisionObject* object) { csRef<csBulletCollisionObject> obj (dynamic_cast<csBulletCollisionObject*>(object)); collisionObjects.Push (obj); obj->sector = this; obj->AddBulletObject (); + + AddMovableToSector (object); } -void csBulletSector::RemoveCollisionObject (iCollisionObject* object) +void csBulletSector::RemoveCollisionObject (CS::Collision2::iCollisionObject* object) { csBulletCollisionObject* collObject = dynamic_cast<csBulletCollisionObject*> (object); CS_ASSERT (collObject); - if (collObject->GetObjectType () == COLLISION_OBJECT_PHYSICAL) + if (collObject->GetObjectType () == CS::Collision2::COLLISION_OBJECT_PHYSICAL) { iPhysicalBody* phyBody = dynamic_cast<iPhysicalBody*> (object); if (phyBody->GetBodyType () == CS::Physics2::BODY_RIGID) @@ -128,10 +158,12 @@ collObject->RemoveBulletObject (); collObject->insideWorld = false; collisionObjects.Delete (collObject); + + RemoveMovableFromSector (object); } } -iCollisionObject* csBulletSector::GetCollisionObject (size_t index) +CS::Collision2::iCollisionObject* csBulletSector::GetCollisionObject (size_t index) { return collisionObjects[index]->QueryCollisionObject (); } @@ -146,12 +178,30 @@ //TODO } -void csBulletSector::SetSector (iSector* sector) +CS::Collision2::HitBeamResult csBulletSector::HitBeam (const csVector3& start, const csVector3& end) { - //TODO + CS::Collision2::HitBeamResult result = HitBeamPortal (start, end); + + if (result.hasHit) + { + if (result.object->GetObjectType () == CS::Collision2::COLLISION_OBJECT_GHOST) + { + //Portals are not included. + for (size_t i = 0; i < portals.GetSize (); i++) + { + if (portals[i].ghostPortal1 == result.object + || portals[i].ghostPortal2 == result.object) + { + result.hasHit = false; + break; + } + } + } + } + return result; } -HitBeamResult csBulletSector::HitBeam (const csVector3& start, const csVector3& end) +CS::Collision2::HitBeamResult csBulletSector::HitBeamPortal (const csVector3& start, const csVector3& end) { btVector3 rayFrom = CSToBullet (start, sys->getInternalScale ()); btVector3 rayTo = CSToBullet (end, sys->getInternalScale ()); @@ -163,110 +213,55 @@ if(rayCallback.hasHit ()) { - iCollisionObject* collObject = static_cast<iCollisionObject*> ( + CS::Collision2::iCollisionObject* collObject = static_cast<CS::Collision2::iCollisionObject*> ( rayCallback.m_collisionObject->getUserPointer ()); - if (!collObject->GetObjectType () == COLLISION_OBJECT_PHYSICAL) + if (rayCallback.m_collisionObject->getInternalType () == btCollisionObject::CO_SOFT_BODY) { - if(collObject->GetObjectType () == CS::Collision2::CollisionObjectType::COLLISION_OBJECT_GHOST) - { - //Portals are not included. - for (size_t i = 0; i < portals.GetSize (); i++) - { - if (portals[i].ghostPortal1 == collObject - || portals[i].ghostPortal2 == collObject) - return result; - } - } - result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); - return result; - } - else - { - iPhysicalBody* phyBody = collObject->QueryPhysicalBody (); - CS_ASSERT (phyBody); + btSoftBody* body = btSoftBody::upcast (rayCallback.m_collisionObject); + btSoftBody::sRayCast ray; - if(phyBody->GetBodyType () == BODY_SOFT) + if (body->rayTest (rayFrom, rayTo, ray)) { - btSoftBody* body = btSoftBody::upcast (rayCallback.m_collisionObject); - btSoftBody::sRayCast ray; + result.hasHit = true; + result.object = collObject; + result.isect = BulletToCS (rayCallback.m_hitPointWorld, + sys->getInverseInternalScale ()); + result.normal = BulletToCS (rayCallback.m_hitNormalWorld, + sys->getInverseInternalScale ()); - if (body->rayTest (rayFrom, rayTo, ray)) + // Find the closest vertex that was hit + // TODO: there must be something more efficient than a second ray test + btVector3 impact = rayFrom + (rayTo - rayFrom) * ray.fraction; + switch (ray.feature) { - result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); - - // Find the closest vertex that was hit - // TODO: there must be something more efficient than a second ray test - btVector3 impact = rayFrom + (rayTo - rayFrom) * ray.fraction; - switch (ray.feature) + case btSoftBody::eFeature::Face: { - case btSoftBody::eFeature::Face: - { - btSoftBody::Face& face = body->m_faces[ray.index]; - btSoftBody::Node* node = face.m_n[0]; - float distance = (node->m_x - impact).length2 (); + btSoftBody::Face& face = body->m_faces[ray.index]; + btSoftBody::Node* node = face.m_n[0]; + float distance = (node->m_x - impact).length2 (); - for (int i = 1; i < 3; i++) + for (int i = 1; i < 3; i++) + { + float nodeDistance = (face.m_n[i]->m_x - impact).length2 (); + if (nodeDistance < distance) { - float nodeDistance = (face.m_n[i]->m_x - impact).length2 (); - if (nodeDistance < distance) - { - node = face.m_n[i]; - distance = nodeDistance; - } + node = face.m_n[i]; + distance = nodeDistance; } - - result.vertexIndex = size_t (node - &body->m_nodes[0]); - break; } - default: - break; + + result.vertexIndex = size_t (node - &body->m_nodes[0]); + break; } - return result; + default: + break; } - } - else - { - result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); return result; - } - } - } - return result; -} - -HitBeamResult csBulletSector::HitBeamPortal (const csVector3& start, const csVector3& end) -{ - btVector3 rayFrom = CSToBullet (start, sys->getInternalScale ()); - btVector3 rayTo = CSToBullet (end, sys->getInternalScale ()); - - btCollisionWorld::ClosestRayResultCallback rayCallback (rayFrom, rayTo); - bulletWorld->rayTest (rayFrom, rayTo, rayCallback); - - CS::Collision2::HitBeamResult result; - - if(rayCallback.hasHit ()) - { - csBulletCollisionObject* collObject = static_cast<csBulletCollisionObject*> ( - rayCallback.m_collisionObject->getUserPointer ()); - - if (!collObject->GetObjectType () == COLLISION_OBJECT_PHYSICAL) - { + } //has hit softbody + } //softBody + else + { result.hasHit = true; result.object = collObject; result.isect = BulletToCS (rayCallback.m_hitPointWorld, @@ -274,71 +269,70 @@ result.normal = BulletToCS (rayCallback.m_hitNormalWorld, sys->getInverseInternalScale ()); return result; - } - else - { - iPhysicalBody* phyBody = dynamic_cast<iPhysicalBody*> (collObject); - if(phyBody->GetBodyType () == BODY_SOFT) - { - btSoftBody* body = btSoftBody::upcast (rayCallback.m_collisionObject); - btSoftBody::sRayCast ray; + } // not softBody + } //has hit + return result; +} - if (body->rayTest (rayFrom, rayTo, ray)) - { - result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); +CS::Collision2::CollisionGroup& csBulletSector::CreateCollisionGroup (const char* name) +{ + //TODO + size_t groupCount = 1 << collGroups.GetSize (); + if (groupCount >= sizeof (CS::Collision2::CollisionGroupMask) * 8) + return collGroups[0]; - // Find the closest vertex that was hit - // TODO: there must be something more efficient than a second ray test - btVector3 impact = rayFrom + (rayTo - rayFrom) * ray.fraction; - switch (ray.feature) - { - case btSoftBody::eFeature::Face: - { - btSoftBody::Face& face = body->m_faces[ray.index]; - btSoftBody::Node* node = face.m_n[0]; - float distance = (node->m_x - impact).length2 (); + CS::Collision2::CollisionGroup newGroup(name); + newGroup.value = 1 << groupCount; + collGroups.Push (newGroup); + return collGroups[groupCount]; +} - for (int i = 1; i < 3; i++) - { - float nodeDistance = (face.m_n[i]->m_x - impact).length2 (); - if (nodeDistance < distance) - { - node = face.m_n[i]; - distance = nodeDistance; - } - } +CS::Collision2::CollisionGroup& csBulletSector::FindCollisionGroup (const char* name) +{ + size_t index = collGroups.FindKey (CollisionGroupVector::KeyCmp (name)); + if (index == csArrayItemNotFound) + return collGroups[index]; + else + return collGroups[0]; +} - result.vertexIndex = size_t (node - &body->m_nodes[0]); - break; - } - default: - break; - } - return result; - } - } - else - { - result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); - return result; - } - } +void csBulletSector::SetGroupCollision (const char* name1, + const char* name2, + bool collide) +{ + int index1 = collGroups.FindKey (CollisionGroupVector::KeyCmp (name1)); + int index2 = collGroups.FindKey (CollisionGroupVector::KeyCmp (name2)); + if (index1 == csArrayItemNotFound || index2 == csArrayItemNotFound) + return; + if (collide) + { + collGroups[index1].value &= ~(1 << index2); + collGroups[index2].value &= ~(1 << index1); } - return result; + else + { + collGroups[index1].value |= 1 << index2; + collGroups[index2].value |= 1 << index1; + } } -bool csBulletSector::CollisionTest (iCollisionObject* object, csArray<CollisionData>& collisions) +bool csBulletSector::GetGroupCollision (const char* name1, + const char* name2) { + int index1 = collGroups.FindKey (CollisionGroupVector::KeyCmp (name1)); + int index2 = collGroups.FindKey (CollisionGroupVector::KeyCmp (name2)); + if (index1 == csArrayItemNotFound || index2 == csArrayItemNotFound) + return false; + if ((collGroups[index1].value & (1 << index2)) != 0 + && (collGroups[index2].value & (1 << index1)) != 0) + return true; + else + return false; +} + +bool csBulletSector::CollisionTest (CS::Collision2::iCollisionObject* object, + csArray<CS::Collision2::CollisionData>& collisions) +{ size_t length = collisions.GetSize (); PointContactResult result(sys, collisions); @@ -365,7 +359,7 @@ { //contactPairTest //Does user need the collision data? - csArray<CollisionData> data; + csArray<CS::Collision2::CollisionData> data; PointContactResult result(sys, data); bulletWorld->contactPairTest (objectA, objectB, result); if (data.IsEmpty ()) @@ -374,106 +368,85 @@ return false; } -HitBeamResult csBulletSector::RigidHitBeam (btCollisionObject* object, +CS::Collision2::HitBeamResult csBulletSector::RigidHitBeam (btCollisionObject* object, const csVector3& start, const csVector3& end) { btVector3 rayFrom = CSToBullet (start, sys->getInternalScale ()); btVector3 rayTo = CSToBullet (end, sys->getInternalScale ()); - btCollisionWorld::ClosestRayResultCallback rayCallback (rayFrom, rayTo); - - //Call rayTestSingle or use callback.process ? - //The latter calls the former, but before that it will check the collision filter. - btTransform rayFromTrans; - btTransform rayToTrans; - - rayFromTrans.setIdentity(); - rayFromTrans.setOrigin(rayFrom); - rayToTrans.setIdentity(); - rayToTrans.setOrigin(rayTo); - - bulletWorld->rayTestSingle (rayFromTrans, rayToTrans, object, - object->getCollisionShape(), - object->getWorldTransform(), - rayCallback); - CS::Collision2::HitBeamResult result; - if(rayCallback.hasHit ()) + if (object->getInternalType () == btCollisionObject::CO_SOFT_BODY) { - csBulletCollisionObject* collObject = static_cast<csBulletCollisionObject*> ( - rayCallback.m_collisionObject->getUserPointer ()); + btSoftBody* body = btSoftBody::upcast (object); + btSoftBody::sRayCast ray; - if (!collObject->GetObjectType () == COLLISION_OBJECT_PHYSICAL) + if (body->rayTest (rayFrom, rayTo, ray)) { result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); - return result; - } - else - { - iPhysicalBody* phyBody = dynamic_cast<iPhysicalBody*> (collObject); - if(phyBody->GetBodyType () == BODY_SOFT) - { - btSoftBody* body = btSoftBody::upcast (rayCallback.m_collisionObject); - btSoftBody::sRayCast ray; + result.object = static_cast<csBulletCollisionObject*> (object->getUserPointer ()); - if (body->rayTest (rayFrom, rayTo, ray)) + btVector3 impact = rayFrom + (rayTo - rayFrom) * ray.fraction; + switch (ray.feature) + { + case btSoftBody::eFeature::Face: { - result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); + btSoftBody::Face& face = body->m_faces[ray.index]; + btSoftBody::Node* node = face.m_n[0]; + float distance = (node->m_x - impact).length2 (); - // Find the closest vertex that was hit - // TODO: there must be something more efficient than a second ray test - btVector3 impact = rayFrom + (rayTo - rayFrom) * ray.fraction; - switch (ray.feature) + for (int i = 1; i < 3; i++) { - case btSoftBody::eFeature::Face: + float nodeDistance = (face.m_n[i]->m_x - impact).length2 (); + if (nodeDistance < distance) { - btSoftBody::Face& face = body->m_faces[ray.index]; - btSoftBody::Node* node = face.m_n[0]; - float distance = (node->m_x - impact).length2 (); - - for (int i = 1; i < 3; i++) - { - float nodeDistance = (face.m_n[i]->m_x - impact).length2 (); - if (nodeDistance < distance) - { - node = face.m_n[i]; - distance = nodeDistance; - } - } - - result.vertexIndex = size_t (node - &body->m_nodes[0]); - break; + node = face.m_n[i]; + distance = nodeDistance; } - default: - break; } - return result; + + result.isect = BulletToCS (node->m_x, + sys->getInverseInternalScale ()); + result.normal = BulletToCS (node->m_n, + sys->getInverseInternalScale ()); + result.vertexIndex = size_t (node - &body->m_nodes[0]); + break; } + default: + break; } - else - { - result.hasHit = true; - result.object = collObject; - result.isect = BulletToCS (rayCallback.m_hitPointWorld, - sys->getInverseInternalScale ()); - result.normal = BulletToCS (rayCallback.m_hitNormalWorld, - sys->getInverseInternalScale ()); - return result; - } + return result; } } + else + { + btCollisionWorld::ClosestRayResultCallback rayCallback (rayFrom, rayTo); + + btTransform rayFromTrans; + btTransform rayToTrans; + + rayFromTrans.setIdentity(); + rayFromTrans.setOrigin(rayFrom); + rayToTrans.setIdentity(); + rayToTrans.setOrigin(rayTo); + + bulletWorld->rayTestSingle (rayFromTrans, rayToTrans, object, + object->getCollisionShape(), + object->getWorldTransform(), + rayCallback); + + if(rayCallback.hasHit ()) + { + result.hasHit = true; + result.object = static_cast<csBulletCollisionObject*> (object->getUserPointer ()); + result.isect = BulletToCS (rayCallback.m_hitPointWorld, + sys->getInverseInternalScale ()); + result.normal = BulletToCS (rayCallback.m_hitNormalWorld, + sys->getInverseInternalScale ()); + return result; + } + } return result; } @@ -527,22 +500,26 @@ timeDisableThreshold = time; } -void csBulletSector::AddRigidBody (iRigidBody* body) +void csBulletSector::AddRigidBody (CS::Physics2::iRigidBody* body) { csRef<csBulletRigidBody> btBody (dynamic_cast<csBulletRigidBody*>(body)); rigidBodies.Push (btBody); btBody->sector = this; btBody->AddBulletObject (); + + AddMovableToSector (body); } -void csBulletSector::RemoveRigidBody (iRigidBody* body) +void csBulletSector::RemoveRigidBody (CS::Physics2::iRigidBody* body) { csBulletRigidBody* btBody = dynamic_cast<csBulletRigidBody*> (body); CS_ASSERT (btBody); btBody->RemoveBulletObject (); rigidBodies.Delete (btBody); + + RemoveMovableFromSector (body); } iRigidBody* csBulletSector::GetRigidBody (size_t index) @@ -550,29 +527,47 @@ return rigidBodies[index]->QueryRigidBody (); } -void csBulletSector::AddSoftBody (iSoftBody* body) +void csBulletSector::AddSoftBody (CS::Physics2::iSoftBody* body) { csRef<csBulletSoftBody> btBody (dynamic_cast<csBulletSoftBody*>(body)); softBodies.Push (btBody); btBody->sector = this; btBody->AddBulletObject (); + + iMovable* movable = body->GetAttachedMovable (); + if (movable) + { + iMeshWrapper* mesh = movable->GetSceneNode ()->QueryMesh (); + if (!mesh) + return; + csRef<iGeneralMeshState> meshState = + scfQueryInterface<iGeneralMeshState> (mesh->GetMeshObject ()); + csRef<CS::Physics2::iSoftBodyAnimationControl> animationControl = + scfQueryInterface<CS::Physics2::iSoftBodyAnimationControl> (meshState->GetAnimationControl ()); + if (!animationControl->GetSoftBody ()) + animationControl->SetSoftBody (body); + + sector->GetMeshes ()->Add (mesh); + } } -void csBulletSector::RemoveSoftBody (iSoftBody* body) +void csBulletSector::RemoveSoftBody (CS::Physics2::iSoftBody* body) { csBulletSoftBody* btBody = dynamic_cast<csBulletSoftBody*> (body); CS_ASSERT (btBody); btBody->RemoveBulletObject (); softBodies.Delete (btBody); + + RemoveMovableFromSector (body); } -iSoftBody* csBulletSector::GetSoftBody (size_t index) +CS::Physics2::iSoftBody* csBulletSector::GetSoftBody (size_t index) { return softBodies[index]->QuerySoftBody (); } -void csBulletSector::RemoveJoint (iJoint* joint) +void csBulletSector::RemoveJoint (CS::Physics2::iJoint* joint) { csBulletJoint* btJoint = dynamic_cast<csBulletJoint*> (joint); CS_ASSERT(btJoint); @@ -735,6 +730,34 @@ } } +void csBulletSector::AddMovableToSector (CS::Collision2::iCollisionObject* obj) +{ + iMovable* movable = obj->GetAttachedMovable (); + if (movable && sector) + { + iMeshWrapper* mesh = movable->GetSceneNode ()->QueryMesh (); + iLight* light = movable->GetSceneNode ()->QueryLight (); + if (mesh) + sector->GetMeshes ()->Add (mesh); + else + sector->GetLights ()->Add (light); + } +} + +void csBulletSector::RemoveMovableFromSector (CS::Collision2::iCollisionObject* obj) +{ + iMovable* movable = obj->GetAttachedMovable (); + if (movable && sector) + { + iMeshWrapper* mesh = movable->GetSceneNode ()->QueryMesh (); + iLight* light = movable->GetSceneNode ()->QueryLight (); + if (mesh) + sector->GetMeshes ()->Remove (mesh); + else + sector->GetLights ()->Remove (light); + } +} + SCF_IMPLEMENT_FACTORY (csBulletSystem) csBulletSystem::csBulletSystem (iBase* iParent) @@ -767,16 +790,16 @@ return true; } -csRef<iColliderConvexMesh> csBulletSystem::CreateColliderConvexMesh (iMeshWrapper* mesh) +csRef<CS::Collision2::iColliderConvexMesh> csBulletSystem::CreateColliderConvexMesh (iMeshWrapper* mesh) { csRef<csBulletColliderConvexMesh> collider; collider.AttachNew (new csBulletColliderConvexMesh (mesh, this)); //colliders.Push (collider); - return (iColliderConvexMesh*)collider; + return (CS::Collision2::iColliderConvexMesh*)collider; } -csRef<iColliderConcaveMesh> csBulletSystem::CreateColliderConcaveMesh (iMeshWrapper* mesh) +csRef<CS::Collision2::iColliderConcaveMesh> csBulletSystem::CreateColliderConcaveMesh (iMeshWrapper* mesh) { csRef<csBulletColliderConcaveMesh> collider; collider.AttachNew (new csBulletColliderConcaveMesh (mesh,this)); @@ -785,8 +808,8 @@ return collider; } -csRef<iColliderConcaveMeshScaled> csBulletSystem::CreateColliderConcaveMeshScaled ( - iColliderConcaveMesh* collider, csVector3 scale) +csRef<CS::Collision2::iColliderConcaveMeshScaled> csBulletSystem::CreateColliderConcaveMeshScaled ( + CS::Collision2::iColliderConcaveMesh* collider, csVector3 scale) { csRef<csBulletColliderConcaveMeshScaled> coll; coll.AttachNew (new csBulletColliderConcaveMeshScaled (collider, scale,this)); @@ -795,7 +818,7 @@ return coll; } -csRef<iColliderCylinder> csBulletSystem::CreateColliderCylinder (float length, float radius) +csRef<CS::Collision2::iColliderCylinder> csBulletSystem::CreateColliderCylinder (float length, float radius) { csRef<csBulletColliderCylinder> collider; collider.AttachNew (new csBulletColliderCylinder (length, radius, this)); @@ -804,7 +827,7 @@ return collider; } -csRef<iColliderBox> csBulletSystem::CreateColliderBox (const csVector3& size) +csRef<CS::Collision2::iColliderBox> csBulletSystem::CreateColliderBox (const csVector3& size) { csRef<csBulletColliderBox> collider; collider.AttachNew (new csBulletColliderBox (size, this)); @@ -813,7 +836,7 @@ return collider; } -csRef<iColliderSphere> csBulletSystem::CreateColliderSphere (float radius) +csRef<CS::Collision2::iColliderSphere> csBulletSystem::CreateColliderSphere (float radius) { csRef<csBulletColliderSphere> collider; collider.AttachNew (new csBulletColliderSphere (radius, this)); @@ -822,7 +845,7 @@ return collider; } -csRef<iColliderCapsule> csBulletSystem::CreateColliderCapsule (float length, float radius) +csRef<CS::Collision2::iColliderCapsule> csBulletSystem::CreateColliderCapsule (float length, float radius) { csRef<csBulletColliderCapsule> collider; collider.AttachNew (new csBulletColliderCapsule (length, radius, this)); @@ -831,7 +854,7 @@ return collider; } -csRef<iColliderCone> csBulletSystem::CreateColliderCone (float length, float radius) +csRef<CS::Collision2::iColliderCone> csBulletSystem::CreateColliderCone (float length, float radius) { csRef<csBulletColliderCone> collider; collider.AttachNew (new csBulletColliderCone (length, radius, this)); @@ -840,7 +863,7 @@ return collider; } -csRef<iColliderPlane> csBulletSystem::CreateColliderPlane (const csPlane3& plane) +csRef<CS::Collision2::iColliderPlane> csBulletSystem::CreateColliderPlane (const csPlane3& plane) { csRef<csBulletColliderPlane> collider; collider.AttachNew (new csBulletColliderPlane (plane, this)); @@ -849,7 +872,7 @@ return collider; } -csRef<iColliderTerrain> csBulletSystem::CreateColliderTerrain (iTerrainSystem* terrain, +csRef<CS::Collision2::iColliderTerrain> csBulletSystem::CreateColliderTerrain (iTerrainSystem* terrain, float minHeight /* = 0 */, float maxHeight /* = 0 */) { @@ -860,7 +883,7 @@ return collider; } -csRef<iCollisionObject> csBulletSystem::CreateCollisionObject () +csRef<CS::Collision2::iCollisionObject> csBulletSystem::CreateCollisionObject () { csRef<csBulletCollisionObject> collObject; collObject.AttachNew (new csBulletCollisionObject (this)); @@ -869,15 +892,15 @@ return collObject; } -csRef<iCollisionActor> csBulletSystem::CreateCollisionActor () +csRef<CS::Collision2::iCollisionActor> csBulletSystem::CreateCollisionActor () { - csRef<iCollisionActor> collActor; + csRef<CS::Collision2::iCollisionActor> collActor; /*collActor.AttachNew (new csBulletCollisionActor (this)); actors.Push (collActor);*/ return collActor; } -csRef<iCollisionSector> csBulletSystem::CreateCollisionSector () +csRef<CS::Collision2::iCollisionSector> csBulletSystem::CreateCollisionSector () { csRef<csBulletSector> collSector; collSector.AttachNew (new csBulletSector (this)); @@ -886,33 +909,8 @@ return collSector; } -CollisionGroup& csBulletSystem::CreateCollisionGroup (const char* name) +void csBulletSystem::DecomposeConcaveMesh (CS::Collision2::iCollisionObject* object, iMeshWrapper* mesh) { -//TODO - return CollisionGroup(); -} - -CollisionGroup& csBulletSystem::FindCollisionGroup (const char* name) -{ -//TODO - return CollisionGroup(); -} - -void csBulletSystem::SetGroupCollision (CollisionGroup& group1, - CollisionGroup& group2, - bool collide) -{ -//TODO -} -bool csBulletSystem::GetGroupCollision (CollisionGroup& group1, - CollisionGroup& group2) -{ -//TODO - return true; -} - -void csBulletSystem::DecomposeConcaveMesh (iCollisionObject* object, iMeshWrapper* mesh) -{ csBulletCollisionObject* btCollObject = dynamic_cast<csBulletCollisionObject*> (object); class MyConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface @@ -1048,7 +1046,7 @@ //RebuildObject? or let user do it? } -csRef<iRigidBody> csBulletSystem::CreateRigidBody () +csRef<CS::Physics2::iRigidBody> csBulletSystem::CreateRigidBody () { csRef<csBulletRigidBody> body; body.AttachNew (new csBulletRigidBody (this)); @@ -1057,7 +1055,7 @@ return body; } -csRef<iJoint> csBulletSystem::CreateJoint () +csRef<CS::Physics2::iJoint> csBulletSystem::CreateJoint () { csRef<csBulletJoint> joint; joint.AttachNew (new csBulletJoint (this)); @@ -1065,7 +1063,7 @@ return joint; } -csRef<iJoint> csBulletSystem::CreateRigidP2PJoint (const csVector3 position) +csRef<CS::Physics2::iJoint> csBulletSystem::CreateRigidP2PJoint (const csVector3 position) { csRef<csBulletJoint> joint; joint.AttachNew (new csBulletJoint (this)); @@ -1079,7 +1077,7 @@ return joint; } -csRef<iJoint> csBulletSystem::CreateRigidSlideJoint (const csOrthoTransform trans, +csRef<CS::Physics2::iJoint> csBulletSystem::CreateRigidSlideJoint (const csOrthoTransform trans, float minDist, float maxDist, float minAngle, float maxAngle, int axis) { @@ -1106,7 +1104,7 @@ return joint; } -csRef<iJoint> csBulletSystem::CreateRigidHingeJoint (const csVector3 position, +csRef<CS::Physics2::iJoint> csBulletSystem::CreateRigidHingeJoint (const csVector3 position, float minAngle, float maxAngle, int axis) { csRef<csBulletJoint> joint; @@ -1126,7 +1124,7 @@ return joint; } -csRef<iJoint> csBulletSystem::CreateSoftLinearJoint (const csVector3 position) +csRef<CS::Physics2::iJoint> csBulletSystem::CreateSoftLinearJoint (const csVector3 position) { csRef<csBulletJoint> joint; joint.AttachNew (new csBulletJoint (this)); @@ -1136,7 +1134,7 @@ return joint; } -csRef<iJoint> csBulletSystem::CreateSoftAngularJoint (int axis) +csRef<CS::Physics2::iJoint> csBulletSystem::CreateSoftAngularJoint (int axis) { csRef<csBulletJoint> joint; if (axis < 0 || axis > 2) @@ -1154,7 +1152,7 @@ return joint; } -csRef<iJoint> csBulletSystem::CreateRigidPivotJoint (iRigidBody* body, const csVector3 position) +csRef<CS::Physics2::iJoint> csBulletSystem::CreateRigidPivotJoint (iRigidBody* body, const csVector3 position) { csRef<csBulletJoint> joint; joint.AttachNew (new csBulletJoint (this)); @@ -1169,7 +1167,7 @@ return joint; } -csRef<iSoftBody> csBulletSystem::CreateRope (csVector3 start, +csRef<CS::Physics2::iSoftBody> csBulletSystem::CreateRope (csVector3 start, csVector3 end, size_t segmentCount) { @@ -1190,7 +1188,7 @@ return csRef<iSoftBody>(csBody->QuerySoftBody()); } -csRef<iSoftBody> csBulletSystem::CreateRope (csVector3* vertices, size_t vertexCount) +csRef<CS::Physics2::iSoftBody> csBulletSystem::CreateRope (csVector3* vertices, size_t vertexCount) { // Create the nodes CS_ALLOC_STACK_ARRAY(btVector3, nodes, vertexCount); @@ -1220,7 +1218,7 @@ return csBody; } -csRef<iSoftBody> csBulletSystem::CreateCloth (csVector3 corner1, csVector3 corner2, +csRef<CS::Physics2::iSoftBody> csBulletSystem::CreateCloth (csVector3 corner1, csVector3 corner2, csVector3 corner3, csVector3 corner4, size_t segmentCount1, size_t segmentCount2, bool withDiagonals /* = false */) @@ -1239,7 +1237,7 @@ return csBody; } -csRef<iSoftBody> csBulletSystem::CreateSoftBody (iGeneralFactoryState* genmeshFactory, +csRef<CS::Physics2::iSoftBody> csBulletSystem::CreateSoftBody (iGeneralFactoryState* genmeshFactory, const csOrthoTransform& bodyTransform) { btScalar* vertices = new btScalar[genmeshFactory->GetVertexCount () * 3]; @@ -1277,7 +1275,7 @@ return csBody; } -csRef<iSoftBody> csBulletSystem::CreateSoftBody (csVector3* vertices, size_t vertexCount, +csRef<CS::Physics2::iSoftBody> csBulletSystem::CreateSoftBody (csVector3* vertices, size_t vertexCount, csTriangle* triangles, size_t triangleCount, const csOrthoTransform& bodyTransform) { Modified: CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.h =================================================================== --- CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.h 2011-06-28 17:03:04 UTC (rev 36581) +++ CS/branches/soc2011/collphys/plugins/physics2/bullet/bullet2.h 2011-06-29 13:39:29 UTC (rev 36582) @@ -9,6 +9,7 @@ #include "ivaria/physical2.h" #include "ivaria/bullet2.h" #include "ivaria/view.h" +#include "iengine/sector.h" #include "iengine/movable.h" #include "csutil/csobject.h" @@ -32,9 +33,6 @@ class csBulletCollider; class csBulletJoint; -using namespace CS::Collision2; -using namespace CS::Physics2; - //Will also implement iPhysicalSector... class csBulletSector : public scfImplementationExt3< csBulletSector, csObject, CS::Collision2::iCollisionSector, @@ -56,7 +54,7 @@ csBulletCollisionObject* ghostPortal1; csBulletCollisionObject* ghostPortal2; }; - iSector* sector; + csRef<iSector> sector; csBulletSystem* sys; csVector3 gravity; csRefArrayObject<csBulletCollisionObject> collisionObjects; @@ -65,7 +63,7 @@ csWeakRefArray<csBulletSoftBody> anchoredSoftBodies; csRefArray<csBulletJoint> joints; csArray<CollisionPortal> portals; - csArray<CollisionData> points; + csArray<CS::Collision2::CollisionData> points; csBulletDebugDraw* debugDraw; btDynamicsWorld* bulletWorld; btCollisionDispatcher* dispatcher; @@ -85,6 +83,25 @@ float angularDisableThreshold; float timeDisableThreshold; + class CollisionGroupVector : public csArray<CS::Collision2::CollisionGroup> + { + public: + CollisionGroupVector () : csArray<CS::Collision2::CollisionGroup> () {} + static int CompareKey (CS::Collision2::CollisionGroup const& item, + char const* const& key) + { + return strcmp (item.name.GetData (), key); + } + static csArrayCmp<CS::Collision2::CollisionGroup, char const*> + KeyCmp(char const* k) + { + return csArrayCmp<CS::Collision2::CollisionGroup, char const*> (k,CompareKey); + } + }; + + CollisionGroupVector collGroups; + //csArray<size_t> collGroupMasks; + public: csBulletSector (csBulletSystem* sys); virtual ~csBulletSector(); @@ -94,26 +111,35 @@ virtual void SetGravity (const csVector3& v); virtual csVector3 GetGravity () const {return gravity;} - virtual void AddCollisionObject(iCollisionObject* object); - virtual void RemoveCollisionObject(iCollisionObject* object); + virtual void AddCollisionObject(CS::Collision2::iCollisionObject* object); + virtual void RemoveCollisionObject(CS::Collision2::iCollisionObject* object); virtual size_t GetCollisionObjectCount () {return collisionObjects.GetSize ();} - virtual iCollisionObject* GetCollisionObject (size_t index); + virtual CS::Collision2::iCollisionObject* GetCollisionObject (size_t index); virtual void AddPortal(iPortal* portal); virtual void RemovePortal(iPortal* portal); - virtual void SetSector(iSector* sector); + virtual void SetSector(iSector* sector) {this->sector = sector;} virtual iSector* GetSector(){return sector;} - virtual HitBeamResult HitBeam(const csVector3& start, + virtual CS::Collision2::HitBeamResult HitBeam(const csVector3& start, const csVector3& end); - virtual HitBeamResult HitBeamPortal(const csVector3& start, + virtual CS::Collision2::HitBeamResult HitBeamPortal(const csVector3& start, const csVector3& end); - virtual bool CollisionTest(iCollisionObject* object, csArray<CollisionData>& collisions); + virtual CS::Collision2::CollisionGroup& CreateCollisionGroup (const char* name); + virtual CS::Collision2::CollisionGroup& FindCollisionGroup (const char* name); + virtual void SetGroupCollision (const char* name1, + const char* name2, bool collide); + virtual bool GetGroupCollision (const char* name1, + const char* name2); + + virtual bool CollisionTest(CS::Collision2::iCollisionObject* object, + csArray<CS::Collision2::CollisionData>& collisions); + /*virtual MoveResult MoveTest (iCollisionObject* object, const csOrthoTransform& fromWorld, const csOrthoTransform& toWorld);*/ @@ -132,19 +158,19 @@ virtual void SetAutoDisableParams (float linear, float angular, float time); - virtual void AddRigidBody (iRigidBody* body); - virtual void RemoveRigidBody (iRigidBody* body); + virtual void AddRigidBody (CS::Physics2::iRigidBody* body); + virtual void RemoveRigidBody (CS::Physics2::iRigidBody* body); virtual size_t GetRigidBodyCount () {return rigidBodies.GetSize ();} - virtual iRigidBody* GetRigidBody (size_t index); + virtual CS::Physics2::iRigidBody* GetRigidBody (size_t index); - virtual void AddSoftBody (iSoftBody* body); - virtual void RemoveSoftBody (iSoftBody* body); + virtual void AddSoftBody (CS::Physics2::iSoftBody* body); + virtual void RemoveSoftBody (CS::Physics2::iSoftBody* body); virtual size_t GetSoftBodyCount () {return softBodies.GetSize ();} - virtual iSoftBody* GetSoftBody (size_t index); + virtual CS::Physics2::iSoftBody* GetSoftBody (size_t index); - virtual void RemoveJoint (iJoint* joint); + virtual void RemoveJoint (CS::Physics2::iJoint* joint); virtual void SetSoftBodyEnabled (bool enabled); virtual bool GetSoftBodyEnabled () {return isSoftWorld;} @@ -169,11 +195,15 @@ bool BulletCollide(btCollisionObject* objectA, btCollisionObject* objectB); - HitBeamResult RigidHitBeam(btCollisionObject* object, + CS::Collision2::HitBeamResult RigidHitBeam(btCollisionObject* object, const csVector3& start, const csVector3& end); void UpdateSoftBodies (float timeStep); + + void AddMovableToSector(CS::Collision2::iCollisionObject* obj); + + void RemoveMovableFromSector(CS::Collision2::iCollisionObject* obj); }; class csBulletSystem : public scfImplementation3< @@ -196,28 +226,7 @@ float inverseInternalScale; csStringID baseID; csStringID colldetID; - //Todo: think about it.. - //csArray<CollisionGroup> groups; - class CollisionGroupVector : csArray<CollisionGroup> - { - public: - CollisionGroupVector () : csArray<CollisionGroup> () {} - static int CompareKey (CollisionGroup const& item, - char const* const& key) - { - return strcmp (item.name.GetData (), key); - } - static csArrayCmp<CollisionGroup, char const*> - KeyCmp(char const* k) - { - return csArrayCmp<CollisionGroup, char const*> (k,CompareKey); - } - }; - - CollisionGroupVector collGroups; - csArray<size_t> collGroupMasks; - void RegisterGimpact (); public: csBulletSystem (iBase* iParent); @@ -228,58 +237,50 @@ // iCollisionSystem virtual void SetInternalScale (float scale); - virtual csRef<iColliderConvexMesh> CreateColliderConvexMesh (iMeshWrapper* mesh); - virtual csRef<iColliderConcaveMesh> CreateColliderConcaveMesh (iMeshWrapper* mesh); - virtual csRef<iColliderConcaveMeshScaled> CreateColliderConcaveMeshScaled - (iColliderConcaveMesh* collider, csVector3 scale); - virtual csRef<iColliderCylinder> CreateColliderCylinder (float length, float radius); - virtual csRef<iColliderBox> CreateColliderBox (const csVector3& size); - virtual csRef<iColliderSphere> CreateColliderSphere (float radius); - virtual csRef<iColliderCapsule> CreateColliderCapsule (float length, float radius); - virtual csRef<iColliderCone> CreateColliderCone (float length, float radius); - virtual csRef<iColliderPlane> CreateColliderPlane (const csPlane3& plane); - virtual csRef<iColliderTerrain> CreateColliderTerrain (iTerrainSystem* terrain, + virtual csRef<CS::Collision2::iColliderConvexMesh> CreateColliderConvexMesh (iMeshWrapper* mesh); + virtual csRef<CS::Collision2::iColliderConcaveMesh> CreateColliderConcaveMesh (iMeshWrapper* mesh); + virtual csRef<CS::Collision2::iColliderConcaveMeshScaled> CreateColliderConcaveMeshScaled + (CS::Collision2::iColliderConcaveMesh* collider, csVector3 scale); + virtual csRef<CS::Collision2::iColliderCylinder> CreateColliderCylinder (float length, float radius); + virtual csRef<CS::Collision2::iColliderBox> CreateColliderBox (const csVector3& size); + virtual csRef<CS::Collision2::iColliderSphere> CreateColliderSphere (float radius); + virtual csRef<CS::Collision2::iColliderCapsule> CreateColliderCapsule (float length, float radius); + virtual csRef<CS::Collision2::iColliderCone> CreateColliderCone (float length, float radius); + virtual csRef<CS::Collision2::iColliderPlane> CreateColliderPlane (const csPlane3& plane); + virtual csRef<CS::Collision2::iColliderTerrain> CreateColliderTerrain (iTerrainSystem* terrain, float minHeight = 0, float maxHeight = 0); - virtual csRef<iCollisionObject> CreateCollisionObject (); - virtual csRef<iCollisionActor> CreateCollisionActor (); - virtual csRef<iCollisionSector> CreateCollisionSector (); + virtual csRef<CS::Collision2::iCollisionObject> CreateCollisionObject (); + virtual csRef<CS::Collision2::iCollisionActor> CreateCollisionActor (); + virtual csRef<CS::Collision2::iCollisionSector> CreateCollisionSector (); - virtual CollisionGroup& CreateCollisionGroup (const char* name); - virtual CollisionGroup& FindCollisionGroup (const char* name); + virtual void DecomposeConcaveMesh (CS::Collision2::iCollisionObject* object, iMeshWrapper* mesh); - virtual void SetGroupCollision (CollisionGroup& group1, - CollisionGroup& group2, bool collide); - virtual bool GetGroupCollision (CollisionGroup& group1, - CollisionGroup& group2); - - virtual void DecomposeConca... [truncated message content] |