Fixed wrong paths and added an outDistance to RayVsAABB.
This commit is contained in:
@@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
#include "Core/Ray.h"
|
#include "Core/Ray.h"
|
||||||
#include "Core/AABB.h"
|
#include "Core/AABB.h"
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace Collision
|
namespace Collision
|
||||||
{
|
{
|
||||||
|
|
||||||
bool RayAABBIntr(const Ray& ray, const AABB& box);
|
bool RayAABBIntr(const Ray& ray, const AABB& box);
|
||||||
bool RayVsAABB(const Ray& ray, const AABB& box);
|
bool RayVsAABB(const Ray& ray, const AABB& box);
|
||||||
|
bool RayVsAABB(const Ray& ray, const AABB& box, float& outDistance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -32,6 +32,12 @@ bool RayAABBIntr(const Ray& ray, const AABB& box)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool RayVsAABB(const Ray& ray, const AABB& box)
|
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;
|
glm::vec3 invdir = 1.0f / ray.Direction;
|
||||||
|
|
||||||
@@ -48,6 +54,7 @@ bool RayVsAABB(const Ray& ray, const AABB& box)
|
|||||||
if (tmax < 0 || tmin > tmax)
|
if (tmax < 0 || tmin > tmax)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
outDistance = (tmin > 0) ? tmin : tmax;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
using boost::unit_test_framework::test_suite;
|
using boost::unit_test_framework::test_suite;
|
||||||
using boost::unit_test_framework::test_case;
|
using boost::unit_test_framework::test_case;
|
||||||
#include <Engine\Core\Collision.h>
|
#include <Engine\Core\Collision.h>
|
||||||
|
#include "Engine/Core/AABB.h"
|
||||||
|
#include "Engine/Core/Ray.h"
|
||||||
#include <stdlib.h>//srand
|
#include <stdlib.h>//srand
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(collisionTests)
|
BOOST_AUTO_TEST_SUITE(collisionTests)
|
||||||
@@ -10,8 +12,8 @@ BOOST_AUTO_TEST_CASE(collisionTest)
|
|||||||
{
|
{
|
||||||
//fixed seed
|
//fixed seed
|
||||||
srand(2);
|
srand(2);
|
||||||
Collision::Ray ray;
|
Ray ray;
|
||||||
Collision::AABB someAABB;
|
AABB someAABB;
|
||||||
glm::vec3 minPos;
|
glm::vec3 minPos;
|
||||||
glm::vec3 maxPos;
|
glm::vec3 maxPos;
|
||||||
bool z;
|
bool z;
|
||||||
@@ -31,7 +33,7 @@ BOOST_AUTO_TEST_CASE(collisionTest)
|
|||||||
maxPos.y = rand() % 100;
|
maxPos.y = rand() % 100;
|
||||||
maxPos.z = rand() % 100;
|
maxPos.z = rand() % 100;
|
||||||
|
|
||||||
someAABB = Collision::AABB(minPos, maxPos);
|
someAABB = AABB(minPos, maxPos);
|
||||||
z = Collision::RayVsAABB(ray, someAABB);
|
z = Collision::RayVsAABB(ray, someAABB);
|
||||||
if (z) ++test;
|
if (z) ++test;
|
||||||
}
|
}
|
||||||
@@ -42,8 +44,8 @@ BOOST_AUTO_TEST_CASE(collisionTest2)
|
|||||||
{
|
{
|
||||||
//fixed seed
|
//fixed seed
|
||||||
srand(2);
|
srand(2);
|
||||||
Collision::Ray ray;
|
Ray ray;
|
||||||
Collision::AABB someAABB;
|
AABB someAABB;
|
||||||
glm::vec3 minPos;
|
glm::vec3 minPos;
|
||||||
glm::vec3 maxPos;
|
glm::vec3 maxPos;
|
||||||
bool z;
|
bool z;
|
||||||
@@ -63,7 +65,7 @@ BOOST_AUTO_TEST_CASE(collisionTest2)
|
|||||||
maxPos.y = rand() % 100;
|
maxPos.y = rand() % 100;
|
||||||
maxPos.z = rand() % 100;
|
maxPos.z = rand() % 100;
|
||||||
|
|
||||||
someAABB = Collision::AABB(minPos, maxPos);
|
someAABB = AABB(minPos, maxPos);
|
||||||
z = Collision::RayAABBIntr(ray, someAABB);
|
z = Collision::RayAABBIntr(ray, someAABB);
|
||||||
if (z) ++test;
|
if (z) ++test;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
using boost::unit_test_framework::test_suite;
|
using boost::unit_test_framework::test_suite;
|
||||||
using boost::unit_test_framework::test_case;
|
using boost::unit_test_framework::test_case;
|
||||||
#include "../wmem/MemPrototype/ObjectPool.h"
|
#include "Engine/Core/ObjectPool.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
struct S
|
struct S
|
||||||
|
|||||||
Reference in New Issue
Block a user