Added Ray, AABB structs, and basic rayVsAABB test function.
This commit is contained in:
@@ -1,9 +1,34 @@
|
|||||||
#ifndef Collision_h__
|
#ifndef Collision_h__
|
||||||
#define Collision_h__
|
#define Collision_h__
|
||||||
|
|
||||||
|
#include "../GLM.h"
|
||||||
|
|
||||||
namespace Collision
|
namespace Collision
|
||||||
{
|
{
|
||||||
//bool RayAABBIntr(float3 origin, float3 direction, float3 center, float3 h);
|
struct Ray
|
||||||
|
{
|
||||||
|
glm::vec3 Origin;
|
||||||
|
glm::vec3 Direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AABB
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AABB() = default;
|
||||||
|
AABB(const glm::vec3& minPos, const glm::vec3& maxPos);
|
||||||
|
|
||||||
|
const glm::vec3& MinCorner() const { return m_MinCorner; }
|
||||||
|
const glm::vec3& MaxCorner() const { return m_MaxCorner; }
|
||||||
|
const glm::vec3& Center() const { return m_Center; }
|
||||||
|
const glm::vec3& HalfSize() const { return m_HalfSize; }
|
||||||
|
private:
|
||||||
|
glm::vec3 m_MinCorner;
|
||||||
|
glm::vec3 m_MaxCorner;
|
||||||
|
glm::vec3 m_Center;
|
||||||
|
glm::vec3 m_HalfSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool RayAABBIntr(const Ray& ray, const AABB& box);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,27 +1,39 @@
|
|||||||
|
#include "Core\Collision.h"
|
||||||
|
|
||||||
namespace Collision
|
namespace Collision
|
||||||
{
|
{
|
||||||
|
|
||||||
/*bool RayAABBIntr(float3 origin, float3 direction, float3 center, float3 h)
|
AABB::AABB(const glm::vec3& minPos, const glm::vec3& maxPos)
|
||||||
|
: m_MinCorner(minPos)
|
||||||
|
, m_MaxCorner(maxPos)
|
||||||
|
, m_Center(0.5f * (maxPos + minPos))
|
||||||
|
, m_HalfSize(0.5f * (maxPos - minPos))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool RayAABBIntr(const Ray& ray, const AABB& box)
|
||||||
{
|
{
|
||||||
float3 w = 75.0f * direction;
|
glm::vec3 w = 75.0f * ray.Direction;
|
||||||
float3 v = abs(w);
|
glm::vec3 v = glm::abs(w);
|
||||||
float3 c = origin - center + 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;
|
||||||
|
}
|
||||||
|
|
||||||
//This is better if we hit often, do comparisons simultanously.
|
if (abs(c.y*w.z - c.z*w.y) > half.y*v.z + half.z*v.y) {
|
||||||
//if (any(abs(c) > v + h))
|
return false;
|
||||||
// return false;
|
}
|
||||||
//
|
if (abs(c.x*w.z - c.z*w.x) > half.x*v.z + half.z*v.x) {
|
||||||
//return !(any(abs(c.yxx*w.zzy - c.zzy*w.yxx) > h.yxx*v.zzy + h.zzy*v.yxx));
|
return false;
|
||||||
|
}
|
||||||
//This is better if we miss often, reject test and exit early.
|
return !(abs(c.x*w.y - c.y*w.x) > half.x*v.y + half.y*v.x);
|
||||||
if (abs(c.x) > v.x + h.x) return false;
|
}
|
||||||
if (abs(c.y) > v.y + h.y) return false;
|
|
||||||
if (abs(c.z) > v.z + h.z) return false;
|
|
||||||
|
|
||||||
if (abs(c.y*w.z - c.z*w.y) > h.y*v.z + h.z*v.y) return false;
|
|
||||||
if (abs(c.x*w.z - c.z*w.x) > h.x*v.z + h.z*v.x) return false;
|
|
||||||
return !(abs(c.x*w.y - c.y*w.x) > h.x*v.y + h.y*v.x);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-2
@@ -86,8 +86,7 @@ T* ClassType::PublicMemberFunction(bool value)
|
|||||||
|
|
||||||
if (m_PrivateMember2->PublicMember == 1) {
|
if (m_PrivateMember2->PublicMember == 1) {
|
||||||
return new T();
|
return new T();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user