20
#include "btTransform.h"
20
21
#include "btVector3.h"
21
#include "btSimdMinMax.h"
24
#define btMin(a,b) ((a < b ? a : b))
25
#define btMax(a,b) ((a > b ? a : b))
24
SIMD_FORCE_INLINE void AabbExpand (btVector3& aabbMin,
26
const btVector3& expansionMin,
27
const btVector3& expansionMax)
29
aabbMin = aabbMin + expansionMin;
30
aabbMax = aabbMax + expansionMax;
28
34
/// conservative test for overlap between two aabbs
76
SIMD_FORCE_INLINE bool btRayAabb2(const btVector3& rayFrom,
77
const btVector3& rayInvDirection,
78
const unsigned int raySign[3],
79
const btVector3 bounds[2],
84
btScalar tmax, tymin, tymax, tzmin, tzmax;
85
tmin = (bounds[raySign[0]][0] - rayFrom[0]) * rayInvDirection[0];
86
tmax = (bounds[1-raySign[0]][0] - rayFrom[0]) * rayInvDirection[0];
87
tymin = (bounds[raySign[1]][1] - rayFrom[1]) * rayInvDirection[1];
88
tymax = (bounds[1-raySign[1]][1] - rayFrom[1]) * rayInvDirection[1];
90
if ( (tmin > tymax) || (tymin > tmax) )
99
tzmin = (bounds[raySign[2]][2] - rayFrom[2]) * rayInvDirection[2];
100
tzmax = (bounds[1-raySign[2]][2] - rayFrom[2]) * rayInvDirection[2];
102
if ( (tmin > tzmax) || (tzmin > tmax) )
108
return ( (tmin < lambda_max) && (tmax > lambda_min) );
70
111
SIMD_FORCE_INLINE bool btRayAabb(const btVector3& rayFrom,
71
112
const btVector3& rayTo,
72
113
const btVector3& aabbMin,
168
SIMD_FORCE_INLINE void btTransformAabb(const btVector3& halfExtents, btScalar margin,const btTransform& t,btVector3& aabbMinOut,btVector3& aabbMaxOut)
170
btVector3 halfExtentsWithMargin = halfExtents+btVector3(margin,margin,margin);
171
btMatrix3x3 abs_b = t.getBasis().absolute();
172
btVector3 center = t.getOrigin();
173
btVector3 extent = btVector3(abs_b[0].dot(halfExtentsWithMargin),
174
abs_b[1].dot(halfExtentsWithMargin),
175
abs_b[2].dot(halfExtentsWithMargin));
176
aabbMinOut = center - extent;
177
aabbMaxOut = center + extent;
181
SIMD_FORCE_INLINE void btTransformAabb(const btVector3& localAabbMin,const btVector3& localAabbMax, btScalar margin,const btTransform& trans,btVector3& aabbMinOut,btVector3& aabbMaxOut)
183
btAssert(localAabbMin.getX() <= localAabbMax.getX());
184
btAssert(localAabbMin.getY() <= localAabbMax.getY());
185
btAssert(localAabbMin.getZ() <= localAabbMax.getZ());
186
btVector3 localHalfExtents = btScalar(0.5)*(localAabbMax-localAabbMin);
187
localHalfExtents+=btVector3(margin,margin,margin);
189
btVector3 localCenter = btScalar(0.5)*(localAabbMax+localAabbMin);
190
btMatrix3x3 abs_b = trans.getBasis().absolute();
191
btVector3 center = trans(localCenter);
192
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
193
abs_b[1].dot(localHalfExtents),
194
abs_b[2].dot(localHalfExtents));
195
aabbMinOut = center-extent;
196
aabbMaxOut = center+extent;