From 948f6d5de74d967f931fee04b737989930268b57 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Mon, 14 Dec 2015 17:53:11 +0100 Subject: [PATCH 1/3] RayVsModel & RayVsAABB comparison continued --- src/Engine/Core/Collision.cpp | 3 ++- src/Tests/CollisionTest.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Engine/Core/Collision.cpp b/src/Engine/Core/Collision.cpp index 44875aa4..f5381c08 100644 --- a/src/Engine/Core/Collision.cpp +++ b/src/Engine/Core/Collision.cpp @@ -119,11 +119,12 @@ bool RayVsModel(const Ray& ray, glm::vec3 e2 = modelVertices[modelIndices[++i]].Position - v0; //v2 - v0 glm::vec3 m = ray.Origin - v0; glm::vec3 MxE1 = glm::cross(m, e1); - glm::vec3 DxE2 = glm::cross(ray.Direction, e2); + glm::vec3 DxE2 = glm::cross(ray.Direction, e2);//pVec float DetInv = glm::dot(e1, DxE2); if (std::abs(DetInv) < FLT_EPSILON) { continue; } + DetInv = 1.0f / DetInv; float dist = glm::dot(e2, MxE1) * DetInv; if (dist >= outDistance) { continue; diff --git a/src/Tests/CollisionTest.cpp b/src/Tests/CollisionTest.cpp index 497812a3..3395d505 100644 --- a/src/Tests/CollisionTest.cpp +++ b/src/Tests/CollisionTest.cpp @@ -127,7 +127,8 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) maxPos = glm::vec3(0.5f, 0.5f, 0.5f); someAABB = AABB(minPos, maxPos); ResourceManager::RegisterType("RawModel"); - auto unitBox = ResourceManager::Load("Models/Core/UnitBox.obj"); + //auto unitBox = ResourceManager::Load("Models/Core/UnitBox.obj"); + auto unitBox = ResourceManager::Load("Models/Core/UnitCube.obj"); BOOST_CHECK(unitBox != nullptr); for (size_t i = 0; i < 1000000; i++) From 8e431c8edd2f0c04b45a1a53940d0201356b1ba6 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 15 Dec 2015 11:07:09 +0100 Subject: [PATCH 2/3] RayVsModel && RayVsAABB tests added and working. Also adjusted RayVsModel,RayVsAABB with deltas when values are very close to each other (floatingprecision problems) --- src/Engine/Core/Collision.cpp | 287 +++++++++++++++++----------------- src/Tests/CollisionTest.cpp | 86 +++++++++- 2 files changed, 225 insertions(+), 148 deletions(-) diff --git a/src/Engine/Core/Collision.cpp b/src/Engine/Core/Collision.cpp index f5381c08..151a7a28 100644 --- a/src/Engine/Core/Collision.cpp +++ b/src/Engine/Core/Collision.cpp @@ -6,153 +6,160 @@ namespace Collision { -bool RayAABBIntr(const Ray& ray, const AABB& box) -{ - glm::vec3 w = 75.0f * ray.Direction; - glm::vec3 v = glm::abs(w); - glm::vec3 c = ray.Origin - box.Center() + w; - glm::vec3 half = box.HalfSize(); - - if (abs(c.x) > v.x + half.x) { - return false; - } - if (abs(c.y) > v.y + half.y) { - return false; - } - if (abs(c.z) > v.z + half.z) { - return false; - } + //note: this one hasnt been delta adjusted like RayVsAABB has + bool RayAABBIntr(const Ray& ray, const AABB& box) + { + glm::vec3 w = 75.0f * ray.Direction; + glm::vec3 v = glm::abs(w); + glm::vec3 c = ray.Origin - box.Center() + w; + glm::vec3 half = box.HalfSize(); - if (abs(c.y*w.z - c.z*w.y) > half.y*v.z + half.z*v.y) { - return false; - } - if (abs(c.x*w.z - c.z*w.x) > half.x*v.z + half.z*v.x) { - return false; - } - return !(abs(c.x*w.y - c.y*w.x) > half.x*v.y + half.y*v.x); -} - -bool RayVsAABB(const Ray& ray, const AABB& box) -{ - float dummy; - return RayVsAABB(ray, box, dummy); -} - -bool RayVsAABB(const Ray& ray, const AABB& box, float& outDistance) -{ - glm::vec3 invdir = 1.0f / ray.Direction; - - float t1 = (box.MinCorner().x - ray.Origin.x)*invdir.x; - float t2 = (box.MaxCorner().x - ray.Origin.x)*invdir.x; - float t3 = (box.MinCorner().y - ray.Origin.y)*invdir.y; - float t4 = (box.MaxCorner().y - ray.Origin.y)*invdir.y; - float t5 = (box.MinCorner().z - ray.Origin.z)*invdir.z; - float t6 = (box.MaxCorner().z - ray.Origin.z)*invdir.z; - - float tmin = std::max(std::max(std::min(t1, t2), std::min(t3, t4)), std::min(t5, t6)); - float tmax = std::min(std::min(std::max(t1, t2), std::max(t3, t4)), std::max(t5, t6)); - - if (tmax < 0 || tmin > tmax) - return false; - - outDistance = (tmin > 0) ? tmin : tmax; - return true; -} - -bool AABBVsAABB(const AABB& a, const AABB& b) -{ - const glm::vec3& aCenter = a.Center(); - const glm::vec3& bCenter = b.Center(); - const glm::vec3& aHSize = a.HalfSize(); - const glm::vec3& bHSize = b.HalfSize(); - //Test will probably exit because of the X and Z axes more often, so test them first. - if (abs(aCenter[0] - bCenter[0]) > (aHSize[0] + bHSize[0])) { - return false; - } - if (abs(aCenter[2] - bCenter[2]) > (aHSize[2] + bHSize[2])) { - return false; - } - return (abs(aCenter[1] - bCenter[1]) <= (aHSize[1] + bHSize[1])); -} - -bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, - const std::vector& modelIndices) -{ - for (int i = 0; i < modelIndices.size(); ++i) { - glm::vec3 v0 = modelVertices[modelIndices[i]].Position; - glm::vec3 e1 = modelVertices[modelIndices[++i]].Position - v0; //v1 - v0 - glm::vec3 e2 = modelVertices[modelIndices[++i]].Position - v0; //v2 - v0 - glm::vec3 m = ray.Origin - v0; - glm::vec3 MxE1 = glm::cross(m, e1); - glm::vec3 DxE2 = glm::cross(ray.Direction, e2); - float DetInv = glm::dot(e1, DxE2); - if (std::abs(DetInv) < FLT_EPSILON) { - continue; + if (abs(c.x) > v.x + half.x) { + return false; } - DetInv = 1.0f / DetInv; - float u = glm::dot(m, DxE2) * DetInv; - float v = glm::dot(ray.Direction, MxE1) * DetInv; - if (u < 0 || v < 0 || 1 < u + v) { - continue; + if (abs(c.y) > v.y + half.y) { + return false; } - //Here, u and v are positive, u+v <= 1, and if distance is positive - triangle is hit. - if (0 <= glm::dot(e2, MxE1) * DetInv) { - return true; + if (abs(c.z) > v.z + half.z) { + return false; } + + if (abs(c.y*w.z - c.z*w.y) > half.y*v.z + half.z*v.y) { + return false; + } + if (abs(c.x*w.z - c.z*w.x) > half.x*v.z + half.z*v.x) { + return false; + } + return !(abs(c.x*w.y - c.y*w.x) > half.x*v.y + half.y*v.x); } - return false; -} -bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, - const std::vector& modelIndices, - float& outDistance, - float& outUCoord, - float& outVCoord) -{ - outDistance = INFINITY; - bool hit = false; - for (int i = 0; i < modelIndices.size(); ++i) { - glm::vec3 v0 = modelVertices[modelIndices[i]].Position; - glm::vec3 e1 = modelVertices[modelIndices[++i]].Position - v0; //v1 - v0 - glm::vec3 e2 = modelVertices[modelIndices[++i]].Position - v0; //v2 - v0 - glm::vec3 m = ray.Origin - v0; - glm::vec3 MxE1 = glm::cross(m, e1); - glm::vec3 DxE2 = glm::cross(ray.Direction, e2);//pVec - float DetInv = glm::dot(e1, DxE2); - if (std::abs(DetInv) < FLT_EPSILON) { - continue; - } - DetInv = 1.0f / DetInv; - float dist = glm::dot(e2, MxE1) * DetInv; - if (dist >= outDistance) { - continue; - } - float u = glm::dot(m, DxE2) * DetInv; - float v = glm::dot(ray.Direction, MxE1) * DetInv; - //If u and v are positive, u+v <= 1, dist is positive, and less than closest. - if (0 <= u && 0 <= v && u + v <= 1 && 0 <= dist) { - outDistance = dist; - outUCoord = u; - outVCoord = v; - hit = true; - } + bool RayVsAABB(const Ray& ray, const AABB& box) + { + float dummy; + return RayVsAABB(ray, box, dummy); } - return hit; -} -bool RayVsModel(const Ray& ray, - const std::vector& modelVertices, - const std::vector& modelIndices, - glm::vec3& outHitPosition) -{ - float u; - float v; - float dist; - bool hit = RayVsModel(ray, modelVertices, modelIndices, dist, u, v); - outHitPosition = ray.Origin + dist * ray.Direction; - return hit; -} + bool RayVsAABB(const Ray& ray, const AABB& box, float& outDistance) + { + glm::vec3 invdir = 1.0f / ray.Direction; + + float t1 = (box.MinCorner().x - ray.Origin.x)*invdir.x; + float t2 = (box.MaxCorner().x - ray.Origin.x)*invdir.x; + float t3 = (box.MinCorner().y - ray.Origin.y)*invdir.y; + float t4 = (box.MaxCorner().y - ray.Origin.y)*invdir.y; + float t5 = (box.MinCorner().z - ray.Origin.z)*invdir.z; + float t6 = (box.MaxCorner().z - ray.Origin.z)*invdir.z; + + float tmin = std::max(std::max(std::min(t1, t2), std::min(t3, t4)), std::min(t5, t6)); + float tmax = std::min(std::min(std::max(t1, t2), std::max(t3, t4)), std::max(t5, t6)); + + //if (tmax < 0 || tmin > tmax) + //if tmin,tmax are almost the same (i.e. hitting exactly in the corner) then tmin might be slightly + //greater than tmax becuase of floating-precision problems. fixed by adding a small delta to tmax + if (tmax < 0 || tmin>(tmax + 0.0001f)) + return false; + + outDistance = (tmin > 0) ? tmin : tmax; + return true; + } + + bool AABBVsAABB(const AABB& a, const AABB& b) + { + const glm::vec3& aCenter = a.Center(); + const glm::vec3& bCenter = b.Center(); + const glm::vec3& aHSize = a.HalfSize(); + const glm::vec3& bHSize = b.HalfSize(); + //Test will probably exit because of the X and Z axes more often, so test them first. + if (abs(aCenter[0] - bCenter[0]) > (aHSize[0] + bHSize[0])) { + return false; + } + if (abs(aCenter[2] - bCenter[2]) > (aHSize[2] + bHSize[2])) { + return false; + } + return (abs(aCenter[1] - bCenter[1]) <= (aHSize[1] + bHSize[1])); + } + + bool RayVsModel(const Ray& ray, + const std::vector& modelVertices, + const std::vector& modelIndices) + { + for (int i = 0; i < modelIndices.size(); ++i) { + glm::vec3 v0 = modelVertices[modelIndices[i]].Position; + glm::vec3 e1 = modelVertices[modelIndices[++i]].Position - v0; //v1 - v0 + glm::vec3 e2 = modelVertices[modelIndices[++i]].Position - v0; //v2 - v0 + glm::vec3 m = ray.Origin - v0; + glm::vec3 MxE1 = glm::cross(m, e1); + glm::vec3 DxE2 = glm::cross(ray.Direction, e2); + float DetInv = glm::dot(e1, DxE2); + if (std::abs(DetInv) < FLT_EPSILON) { + continue; + } + DetInv = 1.0f / DetInv; + float u = glm::dot(m, DxE2) * DetInv; + float v = glm::dot(ray.Direction, MxE1) * DetInv; + //u,v can be very close to 0 but still negative sometimes. added a deltafactor to compensate for that problem + if ((u + 0.001f) < 0 || (v + 0.001f) < 0 || 1 < u + v) { + continue; + } + //Here, u and v are positive, u+v <= 1, and if distance is positive - triangle is hit. + if (0 <= glm::dot(e2, MxE1) * DetInv) { + return true; + } + } + return false; + } + + bool RayVsModel(const Ray& ray, + const std::vector& modelVertices, + const std::vector& modelIndices, + float& outDistance, + float& outUCoord, + float& outVCoord) + { + outDistance = INFINITY; + bool hit = false; + for (int i = 0; i < modelIndices.size(); ++i) { + glm::vec3 v0 = modelVertices[modelIndices[i]].Position; + glm::vec3 e1 = modelVertices[modelIndices[++i]].Position - v0; //v1 - v0 + glm::vec3 e2 = modelVertices[modelIndices[++i]].Position - v0; //v2 - v0 + glm::vec3 m = ray.Origin - v0; + glm::vec3 MxE1 = glm::cross(m, e1); + glm::vec3 DxE2 = glm::cross(ray.Direction, e2);//pVec + float DetInv = glm::dot(e1, DxE2); + if (std::abs(DetInv) < FLT_EPSILON) { + continue; + } + DetInv = 1.0f / DetInv; + float dist = glm::dot(e2, MxE1) * DetInv; + if (dist >= outDistance) { + continue; + } + float u = glm::dot(m, DxE2) * DetInv; + float v = glm::dot(ray.Direction, MxE1) * DetInv; + + //u,v can be very close to 0 but still negative sometimes. added a deltafactor to compensate for that problem + //If u and v are positive, u+v <= 1, dist is positive, and less than closest. + if (0 <= (u + 0.001f) && 0 <= (v + 0.001f) && u + v <= 1 && 0 <= dist) { + outDistance = dist; + outUCoord = u; + outVCoord = v; + hit = true; + } + } + return hit; + } + + bool RayVsModel(const Ray& ray, + const std::vector& modelVertices, + const std::vector& modelIndices, + glm::vec3& outHitPosition) + { + float u; + float v; + float dist; + bool hit = RayVsModel(ray, modelVertices, modelIndices, dist, u, v); + outHitPosition = ray.Origin + dist * ray.Direction; + return hit; + } } diff --git a/src/Tests/CollisionTest.cpp b/src/Tests/CollisionTest.cpp index 3395d505..d5f7e0ed 100644 --- a/src/Tests/CollisionTest.cpp +++ b/src/Tests/CollisionTest.cpp @@ -96,13 +96,12 @@ BOOST_AUTO_TEST_CASE(collisionTest2) BOOST_AUTO_TEST_CASE(rayVsModelTest) { - //simple test + //simple box test Ray ray; ray.Origin = glm::vec3(-50, 0, 0); - //ray.Direction = glm::vec3(-1, 0, 0); ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); - //inte model, det kräver renderar grejs tydligen + //using a rawmodel here, else we have to init the renderingsystem ResourceManager::RegisterType("RawModel"); auto unitBox = ResourceManager::Load("Models/Core/UnitBox.obj"); BOOST_CHECK(unitBox != nullptr); @@ -115,19 +114,24 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest) BOOST_AUTO_TEST_CASE(rayVsModelTest2) { - //advanced test, based on ray vs AABB - srand(7676762); + //advanced test, this will check so rayVSAABB and rayVsModel(with boxmodel) gives the same result (hit/miss) + //testing with different seeds +// srand(7676762); +// srand(7676462); +// srand(7462); + srand(72); Ray ray; AABB someAABB; glm::vec3 minPos; glm::vec3 maxPos; bool z; int test = 0; + //min/max is the same as the rawmodels boundaries ofcourse minPos = glm::vec3(-0.5f, -0.5f, -0.5f); maxPos = glm::vec3(0.5f, 0.5f, 0.5f); someAABB = AABB(minPos, maxPos); + //using a rawmodel here, else we have to init the renderingsystem ResourceManager::RegisterType("RawModel"); - //auto unitBox = ResourceManager::Load("Models/Core/UnitBox.obj"); auto unitBox = ResourceManager::Load("Models/Core/UnitCube.obj"); BOOST_CHECK(unitBox != nullptr); @@ -142,6 +146,9 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) ray.Origin /= 100; ray.Origin = glm::vec3(-2, 0, 0); ray.Direction /= 100; + //if we normalize the ray.direction when its 0,0,0 then we get nan,nan,nan - thus we have this check to prevent that + if (ray.Direction.x < 0.0001f && ray.Direction.y < 0.0001f && ray.Direction.z < 0.0001f) + continue; ray.Direction = glm::normalize(ray.Direction); z = Collision::RayVsAABB(ray, someAABB); @@ -149,7 +156,7 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) //hit bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); if (!hit) { - hit = hit; + //if rayvsaabb hit but rayvvmodel didnt hit, we get to here glm::vec3 outtttttttt; hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices, outtttttttt); hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); @@ -159,13 +166,21 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) } BOOST_CHECK(hit); } + ////breakpoint test + //if (!z) { + // z = z; + //} // bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + ////breakpoint test + //if (!hit) { + // hit = hit; + //} if (hit) { //hit z = Collision::RayVsAABB(ray, someAABB); if (!z) { - z = z; + //if rayvsmodel hit but rayvsaabb didnt hit then we get to here z = Collision::RayVsAABB(ray, someAABB); glm::vec3 outtttttttt; hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices, outtttttttt); @@ -180,7 +195,62 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) } } +BOOST_AUTO_TEST_CASE(rayVsModelTest3) +{ + //simple test + Ray ray; + ray.Origin = glm::vec3(-50, 0, 0); + //ray.Direction = glm::vec3(-1, 0, 0); + ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); + //using a rawmodel here, else we have to init the renderingsystem + ResourceManager::RegisterType("RawModel"); + auto unitBox = ResourceManager::Load("Models/Core/UnitSphere.obj"); + BOOST_CHECK(unitBox != nullptr); + bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(hit); + ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); + hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(!hit); +} + +BOOST_AUTO_TEST_CASE(rayVsModelTest4) +{ + //simple test + + Ray ray; + ray.Origin = glm::vec3(-50, 0, 0); + //ray.Direction = glm::vec3(-1, 0, 0); + ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); + //using a rawmodel here, else we have to init the renderingsystem + ResourceManager::RegisterType("RawModel"); + auto unitBox = ResourceManager::Load("Models/Core/UnitCylinder.obj"); + BOOST_CHECK(unitBox != nullptr); + bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(hit); + ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); + hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(!hit); +} + +BOOST_AUTO_TEST_CASE(rayVsModelTest5) +{ + //simple test + + Ray ray; + ray.Origin = glm::vec3(-50, 0, 0); + //ray.Direction = glm::vec3(-1, 0, 0); + ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); + //using a rawmodel here, else we have to init the renderingsystem + ResourceManager::RegisterType("RawModel"); + auto unitBox = ResourceManager::Load("Models/Core/UnitRaptor.obj"); + BOOST_CHECK(unitBox != nullptr); + bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(hit); + ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); + hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(!hit); +} BOOST_AUTO_TEST_CASE(octTest) { glm::vec3 mini = glm::vec3(-1, -1, -1); From 454ed0032b45e391fd3803ec3b6dee682db77e36 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Tue, 15 Dec 2015 14:01:49 +0100 Subject: [PATCH 3/3] Refactored some RayVsModel tests --- src/Tests/CollisionTest.cpp | 77 ++++++++++--------------------------- 1 file changed, 21 insertions(+), 56 deletions(-) diff --git a/src/Tests/CollisionTest.cpp b/src/Tests/CollisionTest.cpp index eb048a79..82e2e800 100644 --- a/src/Tests/CollisionTest.cpp +++ b/src/Tests/CollisionTest.cpp @@ -10,6 +10,7 @@ using boost::unit_test_framework::test_case; #include "Engine/Core/OctTree.h" //vs model #include +#include //ray vs model #include "Engine\Core\ResourceManager.h" @@ -23,6 +24,22 @@ using boost::unit_test_framework::test_case; //#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) //#define new DEBUG_CLIENTBLOCK +void RayTest(std::string fileName) { + //simple box test + Ray ray; + ray.Origin = glm::vec3(-50, 0, 0); + ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); + //using a rawmodel here, else we have to init the renderingsystem + ResourceManager::RegisterType("RawModel"); + auto unitBox = ResourceManager::Load(fileName); + BOOST_CHECK(unitBox != nullptr); + bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(hit); + ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); + hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); + BOOST_CHECK(!hit); +} + BOOST_AUTO_TEST_SUITE(collisionTests) BOOST_AUTO_TEST_CASE(collisionTest) @@ -97,19 +114,7 @@ BOOST_AUTO_TEST_CASE(collisionTest2) BOOST_AUTO_TEST_CASE(rayVsModelTest) { //simple box test - - Ray ray; - ray.Origin = glm::vec3(-50, 0, 0); - ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); - //using a rawmodel here, else we have to init the renderingsystem - ResourceManager::RegisterType("RawModel"); - auto unitBox = ResourceManager::Load("Models/Core/UnitBox.obj"); - BOOST_CHECK(unitBox != nullptr); - bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(hit); - ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); - hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(!hit); + RayTest("Models/Core/UnitBox.obj"); } BOOST_AUTO_TEST_CASE(rayVsModelTest2) @@ -194,62 +199,22 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) } } - BOOST_AUTO_TEST_CASE(rayVsModelTest3) { //simple test - - Ray ray; - ray.Origin = glm::vec3(-50, 0, 0); - //ray.Direction = glm::vec3(-1, 0, 0); - ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); - //using a rawmodel here, else we have to init the renderingsystem - ResourceManager::RegisterType("RawModel"); - auto unitBox = ResourceManager::Load("Models/Core/UnitSphere.obj"); - BOOST_CHECK(unitBox != nullptr); - bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(hit); - ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); - hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(!hit); + RayTest("Models/Core/UnitSphere.obj"); } BOOST_AUTO_TEST_CASE(rayVsModelTest4) { //simple test - - Ray ray; - ray.Origin = glm::vec3(-50, 0, 0); - //ray.Direction = glm::vec3(-1, 0, 0); - ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); - //using a rawmodel here, else we have to init the renderingsystem - ResourceManager::RegisterType("RawModel"); - auto unitBox = ResourceManager::Load("Models/Core/UnitCylinder.obj"); - BOOST_CHECK(unitBox != nullptr); - bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(hit); - ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); - hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(!hit); + RayTest("Models/Core/UnitCylinder.obj"); } BOOST_AUTO_TEST_CASE(rayVsModelTest5) { //simple test - - Ray ray; - ray.Origin = glm::vec3(-50, 0, 0); - //ray.Direction = glm::vec3(-1, 0, 0); - ray.Direction = glm::normalize(glm::vec3(1, 0, 0)); - //using a rawmodel here, else we have to init the renderingsystem - ResourceManager::RegisterType("RawModel"); - auto unitBox = ResourceManager::Load("Models/Core/UnitRaptor.obj"); - BOOST_CHECK(unitBox != nullptr); - bool hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(hit); - ray.Direction = glm::normalize(glm::vec3(-1, 0, 0)); - hit = Collision::RayVsModel(ray, unitBox->m_Vertices, unitBox->m_Indices); - BOOST_CHECK(!hit); + RayTest("Models/Core/UnitRaptor.obj"); } BOOST_AUTO_TEST_CASE(octTest) {