sphere box test
This commit is contained in:
parent
4f7645dc4f
commit
b868e31cb3
2 changed files with 20 additions and 52 deletions
|
|
@ -192,4 +192,22 @@ namespace Crafter {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
Vector<T, 3, 0> d = spherePos - Vector<T, 3, 0>(boxMat[4][0], boxMat[4][1], boxMat[4][2]);
|
||||
|
||||
T distSq = 0.0f;
|
||||
|
||||
for (std::uint32_t i = 0; i < 3; ++i)
|
||||
{
|
||||
Vector<T, 3, 0> axis(boxMat[i][0], boxMat[i][1], boxMat[i][2]);
|
||||
T dist = Vector<T, 3, 0>::Dot(d, axis);
|
||||
T excess = std::fabs(dist) - boxSize.v[i];
|
||||
excess = std::max(excess, 0.0f);
|
||||
distSq += excess * excess;
|
||||
}
|
||||
|
||||
return distSq <= sphereRadius * sphereRadius;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue