diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2005-08-05 21:00:32 +0400 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2005-08-05 21:00:32 +0400 |
commit | b6d9fbf0dbe44efee9309f09bc1a518a2cd67813 (patch) | |
tree | 43aaf1f693bec9849914001b9cf1fd1dce185de1 /extern/bullet | |
parent | 0f044af97ef785f73e0aa2188716dcafd0c0d54e (diff) |
fixed the mouse-over sensor,
added raycast support for bullet (no triangle-mesh support, soon)
added python methods for 'getHitObject', getRayDirection, getHitPosition and getHitNormal for mouse over sensor,
which makes it easy for a shootout.blend demo :)
Diffstat (limited to 'extern/bullet')
6 files changed, 95 insertions, 8 deletions
diff --git a/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp b/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp index 1cc62263603..98f2a3d5444 100644 --- a/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp +++ b/extern/bullet/Bullet/CollisionShapes/BoxShape.cpp @@ -31,7 +31,7 @@ void BoxShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& //todo: this is a quick fix, we need to enlarge the aabb dependent on several criteria - //extent += SimdVector3(.2f,.2f,.2f); + extent += SimdVector3(.2f,.2f,.2f); aabbMin = center - extent; aabbMax = center + extent; diff --git a/extern/bullet/Bullet/CollisionShapes/CylinderShape.h b/extern/bullet/Bullet/CollisionShapes/CylinderShape.h index d60bacff962..11f184db761 100644 --- a/extern/bullet/Bullet/CollisionShapes/CylinderShape.h +++ b/extern/bullet/Bullet/CollisionShapes/CylinderShape.h @@ -27,7 +27,24 @@ public: virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const; + virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec) const + { + SimdVector3 supVertex; + supVertex = LocalGetSupportingVertexWithoutMargin(vec); + + if ( GetMargin()!=0.f ) + { + SimdVector3 vecnorm = vec; + if (vecnorm .length2() == 0.f) + { + vecnorm.setValue(-1.f,-1.f,-1.f); + } + vecnorm.normalize(); + supVertex+= GetMargin() * vecnorm; + } + return supVertex; + } //use box inertia diff --git a/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp b/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp index 7be5ff4d145..9450eb2e845 100644 --- a/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp +++ b/extern/bullet/BulletDynamics/CollisionDispatch/ConvexConvexAlgorithm.cpp @@ -34,6 +34,11 @@ #include "NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.h" +///Solid3EpaPenetrationDepth is not shipped by default, the license doesn't allow commercial, closed source. contact if you want the file +///It improves the penetration depth handling dramatically +#ifdef USE_EPA +#include "NarrowPhaseCollision/Solid3EpaPenetrationDepth.h" +#endif// USE_EPA #ifdef WIN32 void DrawRasterizerLine(const float* from,const float* to,int color); @@ -136,8 +141,10 @@ void ConvexConvexAlgorithm::CheckPenetrationDepthSolver() m_useEpa = gUseEpa; if (m_useEpa) { - //not distributed - //m_gjkPairDetector.SetPenetrationDepthSolver(new Solid3EpaPenetrationDepth); + //not distributed, see top of this file + #ifdef USE_EPA + m_gjkPairDetector.SetPenetrationDepthSolver(new Solid3EpaPenetrationDepth); + #endif } else { m_gjkPairDetector.SetPenetrationDepthSolver(new MinkowskiPenetrationDepthSolver); diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp index f4634668296..f1f7ba2c1d2 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp @@ -18,7 +18,7 @@ SimdVector3 startVel(0,0,0);//-10000); CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci) { m_collisionDelay = 0; - + m_newClientInfo = 0; m_MotionState = ci.m_MotionState; @@ -163,6 +163,17 @@ void CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa } void CcdPhysicsController::applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ) { + printf("CcdPhysicsController::applyImpulse\n"); + + SimdVector3 impulse(impulseX,impulseY,impulseZ); + SimdVector3 pos(attachX,attachY,attachZ); + + //it might be sleeping... wake up ! + m_body->SetActivationState(1); + m_body->m_deactivationTime = 0.f; + + m_body->applyImpulse(impulse,pos); + } void CcdPhysicsController::SetActive(bool active) { @@ -186,11 +197,11 @@ void CcdPhysicsController::setRigidBody(bool rigid) // clientinfo for raycasts for example void* CcdPhysicsController::getNewClientInfo() { - return 0; + return m_newClientInfo; } void CcdPhysicsController::setNewClientInfo(void* clientinfo) { - + m_newClientInfo = clientinfo; } diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h index e0cba58cb53..8c87940721a 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.h @@ -51,6 +51,7 @@ class CcdPhysicsController : public PHY_IPhysicsController RigidBody* m_body; class PHY_IMotionState* m_MotionState; CollisionShape* m_collisionShape; + void* m_newClientInfo; public: diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp index aac699468d0..fa3253003fc 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp @@ -16,6 +16,8 @@ #include "IDebugDraw.h" +#include "NarrowPhaseCollision/VoronoiSimplexSolver.h" +#include "NarrowPhaseCollision/SubsimplexConvexCast.h" #include "CollisionDispatch/ToiContactDispatcher.h" @@ -24,6 +26,7 @@ #include "CollisionDispatch/UnionFind.h" #include "NarrowPhaseCollision/RaycastCallback.h" +#include "CollisionShapes/SphereShape.h" bool useIslands = true; @@ -678,6 +681,7 @@ void CcdPhysicsEnvironment::SyncMotionStates(float timeStep) // // synchronize the physics and graphics transformations // + for (i=m_controllers.begin(); !(i==m_controllers.end()); i++) { @@ -856,9 +860,56 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IPhysicsController* i float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ) { + int minFraction = 1.f; -// m_broadphase->cast( - return 0; + SimdTransform rayFromTrans,rayToTrans; + rayFromTrans.setIdentity(); + rayFromTrans.setOrigin(SimdVector3(fromX,fromY,fromZ)); + rayToTrans.setIdentity(); + rayToTrans.setOrigin(SimdVector3(toX,toY,toZ)); + + + CcdPhysicsController* nearestHit = 0; + + std::vector<CcdPhysicsController*>::iterator i; + SphereShape pointShape(0.0f); + + /// brute force go over all objects. Once there is a broadphase, use that, or + /// add a raycast against aabb first. + for (i=m_controllers.begin(); + !(i==m_controllers.end()); i++) + { + CcdPhysicsController* ctrl = (*i); + RigidBody* body = ctrl->GetRigidBody(); + + if (body->GetCollisionShape()->IsConvex()) + { + ConvexCast::CastResult rayResult; + rayResult.m_fraction = 1.f; + + ConvexShape* convexShape = (ConvexShape*) body->GetCollisionShape(); + VoronoiSimplexSolver simplexSolver; + SubsimplexConvexCast convexCaster(&pointShape,convexShape,&simplexSolver); + if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,body->getCenterOfMassTransform(),body->getCenterOfMassTransform(),rayResult)) + { + //add hit + rayResult.m_normal.normalize(); + if (rayResult.m_fraction < minFraction) + { + minFraction = rayResult.m_fraction; + nearestHit = ctrl; + normalX = rayResult.m_normal.getX(); + normalY = rayResult.m_normal.getY(); + normalZ = rayResult.m_normal.getZ(); + hitX = rayResult.m_hitTransformA.getOrigin().getX(); + hitY = rayResult.m_hitTransformA.getOrigin().getY(); + hitZ = rayResult.m_hitTransformA.getOrigin().getZ(); + } + } + } + } + + return nearestHit; } |