OBB OBB test
This commit is contained in:
parent
00acab154b
commit
55a319a6ac
4 changed files with 137 additions and 35 deletions
|
|
@ -4,25 +4,56 @@ import std;
|
|||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
// // Test Ray-OrientedBox intersection
|
||||
// Vector<float, 3, 0> boxPos(0.0f, 0.0f, 0.0f);
|
||||
// Vector<float, 3, 0> boxSize(2.0f, 2.0f, 2.0f);
|
||||
// Vector<float, 3, 0> boxRot(0.0f, 0.0f, 0.0f); // No rotation
|
||||
// Vector<float, 3, 0> rayOrigin(0.0f, 0.0f, -5.0f);
|
||||
// Vector<float, 3, 0> rayDir(0.0f, 0.0f, 1.0f);
|
||||
|
||||
// float hitDistance = IntersectionTestRayOrientedBox(boxPos, boxSize, boxRot, rayOrigin, rayDir);
|
||||
|
||||
// if (hitDistance < std::numeric_limits<float>::max()) {
|
||||
// // Hit occurred
|
||||
// std::cout << "Ray-OrientedBox intersection at distance: " << hitDistance << std::endl;
|
||||
// } else {
|
||||
// // No hit
|
||||
// std::cout << "No intersection with Ray-OrientedBox" << std::endl;
|
||||
// }
|
||||
|
||||
// return 0;
|
||||
// Intersection Test
|
||||
|
||||
// Define Box A (size and matrix for transformation)
|
||||
Vector<float, 3, 0> sizeA(1.0f, 1.0f, 1.0f); // Box A size
|
||||
MatrixRowMajor<float, 4, 3, 1> boxA;
|
||||
boxA.m[0][0] = 1.0f; boxA.m[1][0] = 0.0f; boxA.m[2][0] = 0.0f;
|
||||
boxA.m[1][0] = 0.0f; boxA.m[1][1] = 1.0f; boxA.m[2][1] = 0.0f;
|
||||
boxA.m[2][0] = 0.0f; boxA.m[1][2] = 0.0f; boxA.m[2][2] = 1.0f;
|
||||
|
||||
// Define Box B (size and matrix for transformation)
|
||||
Vector<float, 3, 0> sizeB(1.0f, 1.0f, 1.0f); // Box B size
|
||||
MatrixRowMajor<float, 4, 3, 1> boxB;
|
||||
boxB.m[0][0] = 1.0f; boxB.m[1][0] = 0.0f; boxB.m[2][0] = 0.0f;
|
||||
boxB.m[1][0] = 0.0f; boxB.m[1][1] = 1.0f; boxB.m[2][1] = 0.0f;
|
||||
boxB.m[2][0] = 0.0f; boxB.m[1][2] = 0.0f; boxB.m[2][2] = 1.0f;
|
||||
|
||||
// Apply a small translation to box B (so that they overlap)
|
||||
boxB.m[0][3] = 0.5f;
|
||||
boxB.m[1][3] = 0.5f;
|
||||
boxB.m[2][3] = 0.0f;
|
||||
|
||||
// Check if the boxes intersect (they should, as they're overlapping)
|
||||
bool result = IntersectionTestOrientedBoxOrientedBox(sizeA, boxA, sizeB, boxB);
|
||||
std::cout << result << std::endl;
|
||||
|
||||
|
||||
std::cout << (Vector<float, 3, 0>(5, 0, 0) == Vector<float, 3, 0>(5,0,1)) << std::endl;
|
||||
// Miss Test
|
||||
|
||||
// Define Box A (size and matrix for transformation)
|
||||
Vector<float, 3, 0> sizeC(1.0f, 1.0f, 1.0f); // Box C size
|
||||
MatrixRowMajor<float, 4, 3, 1> boxC;
|
||||
boxC.m[0][0] = 1.0f; boxC.m[1][0] = 0.0f; boxC.m[2][0] = 0.0f;
|
||||
boxC.m[1][0] = 0.0f; boxC.m[1][1] = 1.0f; boxC.m[2][1] = 0.0f;
|
||||
boxC.m[2][0] = 0.0f; boxC.m[1][2] = 0.0f; boxC.m[2][2] = 1.0f;
|
||||
|
||||
// Define Box D (size and matrix for transformation)
|
||||
Vector<float, 3, 0> sizeD(1.0f, 1.0f, 1.0f); // Box D size
|
||||
MatrixRowMajor<float, 4, 3, 1> boxD;
|
||||
boxD.m[0][0] = 1.0f; boxD.m[1][0] = 0.0f; boxD.m[2][0] = 0.0f;
|
||||
boxD.m[1][0] = 0.0f; boxD.m[1][1] = 1.0f; boxD.m[2][1] = 0.0f;
|
||||
boxD.m[2][0] = 0.0f; boxD.m[1][2] = 0.0f; boxD.m[2][2] = 1.0f;
|
||||
|
||||
// Apply a large translation to box D (so that they do not intersect)
|
||||
boxD.m[0][3] = 3.0f;
|
||||
boxD.m[1][3] = 3.0f;
|
||||
boxD.m[2][3] = 0.0f;
|
||||
|
||||
// Check if the boxes do not intersect (they shouldn't, as they are far apart)
|
||||
bool missResult = IntersectionTestOrientedBoxOrientedBox(sizeC, boxC, sizeD, boxD);
|
||||
std::cout << missResult << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue