added non-uniform scaling to btMultiSphereShape
added ray-aabb check modified Raycast demo to be more useful for debugging collision shapes
This commit is contained in:
@@ -297,7 +297,7 @@ public:
|
||||
}
|
||||
|
||||
///users can point to their objects, userPointer is not used by Bullet
|
||||
void* getUserPointer()
|
||||
void* getUserPointer() const
|
||||
{
|
||||
return m_userObjectPointer;
|
||||
}
|
||||
|
||||
@@ -344,7 +344,9 @@ void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& r
|
||||
|
||||
//check aabb overlap
|
||||
|
||||
if (TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,collisionObjectAabbMin,collisionObjectAabbMax))
|
||||
float hitLambda = 1.f;
|
||||
btVector3 hitNormal;
|
||||
if (btRayAabb(rayAabbMin,rayAabbMax,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
|
||||
{
|
||||
rayTestSingle(rayFromTrans,rayToTrans,
|
||||
collisionObject,
|
||||
|
||||
@@ -20,17 +20,17 @@ subject to the following restrictions:
|
||||
btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres)
|
||||
:m_inertiaHalfExtents(inertiaHalfExtents)
|
||||
{
|
||||
m_minRadius = 1e30f;
|
||||
float startMargin = 1e30f;
|
||||
|
||||
m_numSpheres = numSpheres;
|
||||
for (int i=0;i<m_numSpheres;i++)
|
||||
{
|
||||
m_localPositions[i] = positions[i];
|
||||
m_radi[i] = radi[i];
|
||||
if (radi[i] < m_minRadius)
|
||||
m_minRadius = radi[i];
|
||||
if (radi[i] < startMargin)
|
||||
startMargin = radi[i];
|
||||
}
|
||||
setMargin(m_minRadius);
|
||||
setMargin(startMargin);
|
||||
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,cons
|
||||
|
||||
for (i=0;i<m_numSpheres;i++)
|
||||
{
|
||||
vtx = (*pos) +vec*((*rad)-m_minRadius);
|
||||
vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
|
||||
pos++;
|
||||
rad++;
|
||||
newDot = vec.dot(vtx);
|
||||
@@ -96,7 +96,7 @@ btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,cons
|
||||
|
||||
for (int i=0;i<m_numSpheres;i++)
|
||||
{
|
||||
vtx = (*pos) +vec*((*rad)-m_minRadius);
|
||||
vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
|
||||
pos++;
|
||||
rad++;
|
||||
newDot = vec.dot(vtx);
|
||||
|
||||
@@ -31,9 +31,7 @@ class btMultiSphereShape : public btConvexShape
|
||||
btVector3 m_inertiaHalfExtents;
|
||||
|
||||
int m_numSpheres;
|
||||
float m_minRadius;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ subject to the following restrictions:
|
||||
#define AABB_UTIL2
|
||||
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btSimdMinMax.h"
|
||||
|
||||
|
||||
#define btMin(a,b) ((a < b ? a : b))
|
||||
#define btMax(a,b) ((a > b ? a : b))
|
||||
@@ -53,5 +55,72 @@ SIMD_FORCE_INLINE bool TestTriangleAgainstAabb2(const btVector3 *vertices,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE int btOutcode(const btVector3& p,const btVector3& halfExtent)
|
||||
{
|
||||
return (p.getX() < -halfExtent.getX() ? 0x01 : 0x0) |
|
||||
(p.getX() > halfExtent.getX() ? 0x08 : 0x0) |
|
||||
(p.getY() < -halfExtent.getY() ? 0x02 : 0x0) |
|
||||
(p.getY() > halfExtent.getY() ? 0x10 : 0x0) |
|
||||
(p.getZ() < -halfExtent.getZ() ? 0x4 : 0x0) |
|
||||
(p.getZ() > halfExtent.getZ() ? 0x20 : 0x0);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE bool btRayAabb(const btVector3& rayFrom,
|
||||
const btVector3& rayTo,
|
||||
const btVector3& aabbMin,
|
||||
const btVector3& aabbMax,
|
||||
btScalar& param, btVector3& normal)
|
||||
{
|
||||
btVector3 aabbHalfExtent = (aabbMax-aabbMin)* 0.5f;
|
||||
btVector3 aabbCenter = (aabbMax+aabbMin)* 0.5f;
|
||||
btVector3 source = rayFrom - aabbCenter;
|
||||
btVector3 target = rayTo - aabbCenter;
|
||||
int sourceOutcode = btOutcode(source,aabbHalfExtent);
|
||||
int targetOutcode = btOutcode(target,aabbHalfExtent);
|
||||
if ((sourceOutcode & targetOutcode) == 0x0)
|
||||
{
|
||||
btScalar lambda_enter = btScalar(0.0);
|
||||
btScalar lambda_exit = param;
|
||||
btVector3 r = target - source;
|
||||
int i;
|
||||
btScalar normSign = 1;
|
||||
btVector3 hitNormal(0,0,0);
|
||||
int bit=1;
|
||||
|
||||
for (int j=0;j<2;j++)
|
||||
{
|
||||
for (i = 0; i != 3; ++i)
|
||||
{
|
||||
if (sourceOutcode & bit)
|
||||
{
|
||||
btScalar lambda = (-source[i] - aabbHalfExtent[i]*normSign) / r[i];
|
||||
if (lambda_enter <= lambda)
|
||||
{
|
||||
lambda_enter = lambda;
|
||||
hitNormal.setValue(0,0,0);
|
||||
hitNormal[i] = normSign;
|
||||
}
|
||||
}
|
||||
else if (targetOutcode & bit)
|
||||
{
|
||||
btScalar lambda = (-source[i] - aabbHalfExtent[i]*normSign) / r[i];
|
||||
btSetMin(lambda_exit, lambda);
|
||||
}
|
||||
bit<<=1;
|
||||
}
|
||||
normSign = -1.f;
|
||||
}
|
||||
if (lambda_enter <= lambda_exit)
|
||||
{
|
||||
param = lambda_enter;
|
||||
normal = hitNormal;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -114,8 +114,8 @@ SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); }
|
||||
SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); }
|
||||
*/
|
||||
|
||||
SIMD_FORCE_INLINE int btSign(btScalar x) {
|
||||
return x < 0.0f ? -1 : x > 0.0f ? 1 : 0;
|
||||
SIMD_FORCE_INLINE int btIsNegative(btScalar x) {
|
||||
return x < 0.0f ? 1 : 0;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btScalar btRadians(btScalar x) { return x * SIMD_RADS_PER_DEG; }
|
||||
|
||||
@@ -16,6 +16,7 @@ subject to the following restrictions:
|
||||
|
||||
#ifndef SIMD_MINMAX_H
|
||||
#define SIMD_MINMAX_H
|
||||
#include "LinearMath/btScalar.h"
|
||||
|
||||
template <class T>
|
||||
SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b) {
|
||||
|
||||
Reference in New Issue
Block a user