sphere box test
This commit is contained in:
parent
f95555b9e1
commit
09e4d0379b
1 changed files with 2 additions and 2 deletions
|
|
@ -195,13 +195,13 @@ namespace Crafter {
|
||||||
|
|
||||||
export template<typename T>
|
export template<typename T>
|
||||||
constexpr bool IntersectionTestSphereOrientatedBox(Vector<T, 3, 0> spherePos, T sphereRadius, Vector<T, 3, 0> boxSize, MatrixRowMajor<T, 4, 3, 1> boxMat) {
|
constexpr bool IntersectionTestSphereOrientatedBox(Vector<T, 3, 0> spherePos, T sphereRadius, Vector<T, 3, 0> boxSize, MatrixRowMajor<T, 4, 3, 1> boxMat) {
|
||||||
Vector<T, 3, 0> d = spherePos - Vector<T, 3, 0>(boxMat[0][4], boxMat[1][4], boxMat[2][4]);
|
Vector<T, 3, 0> d = spherePos - Vector<T, 3, 0>(boxMat.m[0][4], boxMat.m[1][4], boxMat.m[2][4]);
|
||||||
|
|
||||||
T distSq = 0.0f;
|
T distSq = 0.0f;
|
||||||
|
|
||||||
for (std::uint32_t i = 0; i < 3; ++i)
|
for (std::uint32_t i = 0; i < 3; ++i)
|
||||||
{
|
{
|
||||||
Vector<T, 3, 0> axis(boxMat[0][i], boxMat[1][i], boxMat[2][i]);
|
Vector<T, 3, 0> axis(boxMat.m[0][i], boxMat.m[1][i], boxMat.m[2][i]);
|
||||||
T dist = Vector<T, 3, 0>::Dot(d, axis);
|
T dist = Vector<T, 3, 0>::Dot(d, axis);
|
||||||
T excess = std::fabs(dist) - boxSize.v[i];
|
T excess = std::fabs(dist) - boxSize.v[i];
|
||||||
excess = std::max(excess, 0.0f);
|
excess = std::max(excess, 0.0f);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue