Code clean up and refactoring.
This commit is contained in:
11
sphere.cpp
11
sphere.cpp
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user