Relocated AABB and Ray in Collision.h to their own files. Started implementation on OctTree.

This commit is contained in:
William Moberg
2015-12-03 17:03:27 +01:00
parent c698149bdd
commit 2f13f5da7a
8 changed files with 272 additions and 31 deletions
+24
View File
@@ -0,0 +1,24 @@
#ifndef AABB_h__
#define AABB_h__
#include "../GLM.h"
class AABB
{
public:
AABB() = default;
AABB(const glm::vec3& minPos, const glm::vec3& maxPos);
virtual ~AABB();
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;
};
#endif
+3 -23
View File
@@ -1,34 +1,14 @@
#ifndef Collision_h__
#define Collision_h__
#include "../GLM.h"
#include "Core/Ray.h"
#include "Core/AABB.h"
namespace Collision
{
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
+29
View File
@@ -1,5 +1,34 @@
#ifndef OctTree_h__
#define OctTree_h__
#include "Core/Collision.h"
class OctTree
{
public:
struct Output
{
float CollideDistance;
};
OctTree();
~OctTree();
//For the root OctTree, [octTreeBounds] should be a box containing the entire level.
OctTree(const AABB& octTreeBounds, int subDivisions);
void AddBox(const AABB& box);
void ClearBoxes();
//Returns true if the ray collides with something in the tree. Result is written to [data].
bool RayCollides(const Ray& ray, Output& data) const;
private:
OctTree* m_Children[8];
std::vector<AABB> m_ContainingBoxes;
//TODO: Do derived class from AABB with a bool Tested, falsify at
//start of Collision test, set on check, don't check if set already. Solves duplicate boxes in tree.
AABB m_Box;
bool rayCollides(const Ray& ray, Output& data, const OctTree* const tree) const;
inline bool hasChildren() const;
int childIndexContainingPoint(const glm::vec3& point) const;
};
#endif
+12
View File
@@ -0,0 +1,12 @@
#ifndef Ray_h__
#define Ray_h__
#include "../GLM.h"
struct Ray
{
glm::vec3 Origin;
glm::vec3 Direction;
};
#endif // Ray_h__