Made Ray into a class with checks so the direction will always be normalized.

This commit is contained in:
William Moberg
2015-12-17 13:41:34 +01:00
parent 03d5f0dd67
commit 5160a45b44
8 changed files with 66 additions and 57 deletions
+4
View File
@@ -1,6 +1,10 @@
#ifndef Collision_h__
#define Collision_h__
//NOTE: Collision.h needs to be #included before <GLFW/glfw3.h>,
//because Collision #includes "RawModel.h", which has "Texture.h", which has "OpenGL.h" which must be #included first
//or you will get "fatal error C1189: #error: gl.h included before glew.h"
#include <vector>
#include "Core/Ray.h"
+1 -1
View File
@@ -3,7 +3,7 @@
#include "Core/AABB.h"
struct Ray;
class Ray;
class OctTree
{
+22 -3
View File
@@ -2,11 +2,30 @@
#define Ray_h__
#include "../GLM.h"
#include "Common.h"
struct Ray
class Ray
{
glm::vec3 Origin;
glm::vec3 Direction;
public:
Ray(const glm::vec3& origin, const glm::vec3& dir)
: m_Origin(origin)
, m_Direction(glm::normalize(dir))
{
IF_DEBUG_IS(true) {
if (glm::any(glm::isnan(m_Direction))) {
LOG_WARNING("Ray Direction was set to the zero-vector, expect unknown side effects and/or crashes.");
}
}
}
const glm::vec3& Origin() const { return m_Origin; }
const glm::vec3& Direction() const { return m_Direction; }
//Sets the ray origin at parameter.
void SetOrigin(const glm::vec3& origin) { m_Origin = origin; }
//Normalizes the parameter and sets direction to it.
void SetDirection(const glm::vec3& direction) { m_Direction = glm::normalize(direction); }
private:
glm::vec3 m_Origin;
glm::vec3 m_Direction;
};
#endif // Ray_h__