Code clean up and refactoring.

This commit is contained in:
2016-12-26 15:41:29 -04:00
parent 876ecc14cc
commit 2d437f07bc
10 changed files with 183 additions and 85 deletions

View File

@@ -2,7 +2,10 @@
#include "sphere.hpp"
bool Sphere::intersect(Ray & r, float & t) const {
using glm::normalize;
bool Sphere::intersect(Ray & r, float & t, vec3 & n) const {
vec3 i;
float d;
float a = (r.m_direction.x * r.m_direction.x) +
@@ -23,7 +26,11 @@ bool Sphere::intersect(Ray & r, float & t) const {
d = (b * b) - (4 * a * c);
t = (-b - sqrt(d)) / (2 * a);
if (d >= 0.0f) {
t = (-b - sqrt(d)) / (2 * a);
i = vec3(r.m_origin + (t * r.m_direction));
n = normalize(vec3((i - m_center) / m_radius));
}
return d >= 0.0f;
}