1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3 * Sphere-AABB overlap test, based on Jim Arvo's code.
4 * \param center [in] box center
5 * \param extents [in] box extents
6 * \return TRUE on overlap
8 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9 inline_ BOOL
SphereCollider::SphereAABBOverlap(const Point
& center
, const Point
& extents
)
16 //find the square of the distance
17 //from the sphere to the box
19 for(udword i
=0;i
<3;i
++)
21 float tmp
= mCenter
[i
] - center
[i
];
22 float s
= tmp
+ extents
[i
];
35 // float tmp = mCenter.x - center.x;
36 // float s = tmp + extents.x;
40 tmp
= mCenter
.x
- center
.x
;
46 if(d
>mRadius2
) return FALSE
;
54 if(d
>mRadius2
) return FALSE
;
58 tmp
= mCenter
.y
- center
.y
;
64 if(d
>mRadius2
) return FALSE
;
72 if(d
>mRadius2
) return FALSE
;
76 tmp
= mCenter
.z
- center
.z
;
82 if(d
>mRadius2
) return FALSE
;
90 if(d
>mRadius2
) return FALSE
;
96 // Point Min = center - extents;
97 // Point Max = center + extents;
101 //find the square of the distance
102 //from the sphere to the box
103 for(udword i
=0;i
<3;i
++)
105 float Min
= center
[i
] - extents
[i
];
107 // if(mCenter[i]<Min[i])
110 // float s = mCenter[i] - Min[i];
111 float s
= mCenter
[i
] - Min
;
116 float Max
= center
[i
] + extents
[i
];
118 // if(mCenter[i]>Max[i])
121 float s
= mCenter
[i
] - Max
;
127 return d
<= mRadius2
;