2006-02-21 05:36:56 +00:00
|
|
|
/*
|
2006-03-27 06:37:30 +00:00
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2006-02-21 05:36:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COLLISION_WORLD_H
|
|
|
|
#define COLLISION_WORLD_H
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
class CollisionShape;
|
2006-02-21 05:36:56 +00:00
|
|
|
class BroadphaseInterface;
|
2006-04-28 00:08:18 +00:00
|
|
|
#include "SimdVector3.h"
|
|
|
|
#include "SimdTransform.h"
|
|
|
|
#include "CollisionObject.h"
|
2006-06-17 13:55:59 +00:00
|
|
|
#include "CollisionDispatcher.h" //for definition of CollisionObjectArray
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2006-06-17 13:55:59 +00:00
|
|
|
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
///CollisionWorld is interface and container for the collision detection
|
|
|
|
class CollisionWorld
|
|
|
|
{
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
std::vector<CollisionObject*> m_collisionObjects;
|
|
|
|
|
|
|
|
CollisionDispatcher* m_dispatcher;
|
|
|
|
|
|
|
|
BroadphaseInterface* m_broadphase;
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
public:
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
CollisionWorld(CollisionDispatcher* dispatcher,BroadphaseInterface* broadphase)
|
|
|
|
:m_dispatcher(dispatcher),
|
|
|
|
m_broadphase(broadphase)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2006-05-19 20:20:46 +00:00
|
|
|
virtual ~CollisionWorld();
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
virtual void UpdateActivationState();
|
2006-06-17 13:55:59 +00:00
|
|
|
virtual void StoreIslandActivationState();
|
2006-02-21 05:36:56 +00:00
|
|
|
|
|
|
|
BroadphaseInterface* GetBroadphase()
|
|
|
|
{
|
|
|
|
return m_broadphase;
|
|
|
|
}
|
|
|
|
|
|
|
|
CollisionDispatcher* GetDispatcher()
|
|
|
|
{
|
|
|
|
return m_dispatcher;
|
|
|
|
}
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
///LocalShapeInfo gives extra information for complex shapes
|
|
|
|
///Currently, only TriangleMeshShape is available, so it just contains triangleIndex and subpart
|
|
|
|
struct LocalShapeInfo
|
|
|
|
{
|
|
|
|
int m_shapePart;
|
|
|
|
int m_triangleIndex;
|
|
|
|
|
|
|
|
//const CollisionShape* m_shapeTemp;
|
|
|
|
//const SimdTransform* m_shapeLocalTransform;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LocalRayResult
|
|
|
|
{
|
|
|
|
LocalRayResult(const CollisionObject* collisionObject,
|
|
|
|
LocalShapeInfo* localShapeInfo,
|
|
|
|
const SimdVector3& hitNormalLocal,
|
|
|
|
float hitFraction)
|
|
|
|
:m_collisionObject(collisionObject),
|
|
|
|
m_localShapeInfo(m_localShapeInfo),
|
|
|
|
m_hitNormalLocal(hitNormalLocal),
|
|
|
|
m_hitFraction(hitFraction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const CollisionObject* m_collisionObject;
|
|
|
|
LocalShapeInfo* m_localShapeInfo;
|
|
|
|
const SimdVector3& m_hitNormalLocal;
|
|
|
|
float m_hitFraction;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
///RayResultCallback is used to report new raycast results
|
|
|
|
struct RayResultCallback
|
|
|
|
{
|
2006-05-11 17:58:23 +00:00
|
|
|
virtual ~RayResultCallback()
|
|
|
|
{
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
float m_closestHitFraction;
|
|
|
|
bool HasHit()
|
|
|
|
{
|
|
|
|
return (m_closestHitFraction < 1.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
RayResultCallback()
|
|
|
|
:m_closestHitFraction(1.f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual float AddSingleResult(const LocalRayResult& rayResult) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ClosestRayResultCallback : public RayResultCallback
|
|
|
|
{
|
|
|
|
ClosestRayResultCallback(SimdVector3 rayFromWorld,SimdVector3 rayToWorld)
|
|
|
|
:m_rayFromWorld(rayFromWorld),
|
|
|
|
m_rayToWorld(rayToWorld),
|
|
|
|
m_collisionObject(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SimdVector3 m_rayFromWorld;//used to calculate hitPointWorld from hitFraction
|
|
|
|
SimdVector3 m_rayToWorld;
|
|
|
|
|
|
|
|
SimdVector3 m_hitNormalWorld;
|
|
|
|
SimdVector3 m_hitPointWorld;
|
|
|
|
const CollisionObject* m_collisionObject;
|
|
|
|
|
|
|
|
virtual float AddSingleResult(const LocalRayResult& rayResult)
|
|
|
|
{
|
|
|
|
|
2006-05-11 02:14:48 +00:00
|
|
|
//caller already does the filter on the m_closestHitFraction
|
|
|
|
assert(rayResult.m_hitFraction <= m_closestHitFraction);
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
m_closestHitFraction = rayResult.m_hitFraction;
|
|
|
|
m_collisionObject = rayResult.m_collisionObject;
|
|
|
|
m_hitNormalWorld = m_collisionObject->m_worldTransform.getBasis()*rayResult.m_hitNormalLocal;
|
|
|
|
m_hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction);
|
|
|
|
return rayResult.m_hitFraction;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
int GetNumCollisionObjects() const
|
|
|
|
{
|
|
|
|
return m_collisionObjects.size();
|
|
|
|
}
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
void RayTest(const SimdVector3& rayFromWorld, const SimdVector3& rayToWorld, RayResultCallback& resultCallback);
|
|
|
|
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
void AddCollisionObject(CollisionObject* collisionObject);
|
|
|
|
|
2006-06-17 13:55:59 +00:00
|
|
|
CollisionObjectArray& GetCollisionObjectArray()
|
|
|
|
{
|
|
|
|
return m_collisionObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CollisionObjectArray& GetCollisionObjectArray() const
|
|
|
|
{
|
|
|
|
return m_collisionObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
void RemoveCollisionObject(CollisionObject* collisionObject);
|
|
|
|
|
2006-03-27 06:37:30 +00:00
|
|
|
virtual void PerformDiscreteCollisionDetection();
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //COLLISION_WORLD_H
|