Merge branch 'OctTree' of github.com:teamfisk/TacticalZ into OctTree
# Conflicts: # include/Engine/Core/Collision.h # src/Engine/Core/Collision.cpp
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "Core/Collision.h"
|
||||
#include "Engine/GLM.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace Collision
|
||||
{
|
||||
@@ -30,4 +31,24 @@ bool RayAABBIntr(const Ray& ray, const AABB& box)
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user