2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
#ifndef B3_AABB_H
|
|
|
|
#define B3_AABB_H
|
|
|
|
|
|
|
|
#include "Bullet3Common/shared/b3Float4.h"
|
|
|
|
#include "Bullet3Common/shared/b3Mat3x3.h"
|
|
|
|
|
|
|
|
typedef struct b3Aabb b3Aabb_t;
|
|
|
|
|
|
|
|
struct b3Aabb
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
union {
|
2017-08-01 12:30:58 +00:00
|
|
|
float m_min[4];
|
|
|
|
b3Float4 m_minVec;
|
|
|
|
int m_minIndices[4];
|
|
|
|
};
|
2019-01-03 13:26:51 +00:00
|
|
|
union {
|
|
|
|
float m_max[4];
|
2017-08-01 12:30:58 +00:00
|
|
|
b3Float4 m_maxVec;
|
|
|
|
int m_signedMaxIndices[4];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
inline void b3TransformAabb2(b3Float4ConstArg localAabbMin, b3Float4ConstArg localAabbMax, float margin,
|
|
|
|
b3Float4ConstArg pos,
|
|
|
|
b3QuatConstArg orn,
|
|
|
|
b3Float4* aabbMinOut, b3Float4* aabbMaxOut)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Float4 localHalfExtents = 0.5f * (localAabbMax - localAabbMin);
|
|
|
|
localHalfExtents += b3MakeFloat4(margin, margin, margin, 0.f);
|
|
|
|
b3Float4 localCenter = 0.5f * (localAabbMax + localAabbMin);
|
|
|
|
b3Mat3x3 m;
|
|
|
|
m = b3QuatGetRotationMatrix(orn);
|
|
|
|
b3Mat3x3 abs_b = b3AbsoluteMat3x3(m);
|
|
|
|
b3Float4 center = b3TransformPoint(localCenter, pos, orn);
|
|
|
|
|
|
|
|
b3Float4 extent = b3MakeFloat4(b3Dot3F4(localHalfExtents, b3GetRow(abs_b, 0)),
|
|
|
|
b3Dot3F4(localHalfExtents, b3GetRow(abs_b, 1)),
|
|
|
|
b3Dot3F4(localHalfExtents, b3GetRow(abs_b, 2)),
|
|
|
|
0.f);
|
|
|
|
*aabbMinOut = center - extent;
|
|
|
|
*aabbMaxOut = center + extent;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// conservative test for overlap between two aabbs
|
2019-01-03 13:26:51 +00:00
|
|
|
inline bool b3TestAabbAgainstAabb(b3Float4ConstArg aabbMin1, b3Float4ConstArg aabbMax1,
|
|
|
|
b3Float4ConstArg aabbMin2, b3Float4ConstArg aabbMax2)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
bool overlap = true;
|
|
|
|
overlap = (aabbMin1.x > aabbMax2.x || aabbMax1.x < aabbMin2.x) ? false : overlap;
|
|
|
|
overlap = (aabbMin1.z > aabbMax2.z || aabbMax1.z < aabbMin2.z) ? false : overlap;
|
|
|
|
overlap = (aabbMin1.y > aabbMax2.y || aabbMax1.y < aabbMin2.y) ? false : overlap;
|
|
|
|
return overlap;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //B3_AABB_H
|