diff --git a/Collision.c b/Collision.c index d3df9d5..5fcd321 100644 --- a/Collision.c +++ b/Collision.c @@ -17,12 +17,14 @@ vec3 collisionPointSphere(ray *lightray, sphere *object) if (discriminant < 0) return collisionPoint; if (discriminant > 0) { double S = (-b - sqrt(discriminant)) / (2 * a); + if (S < 0) return collisionPoint; collisionPoint.x = S * lightray->direction.x + lightray->origin.x; collisionPoint.y = S * lightray->direction.y + lightray->origin.y; collisionPoint.z = S * lightray->direction.z + lightray->origin.z; return collisionPoint; } double S = (-b)/(2*a); + if (S < 0) return collisionPoint; collisionPoint.x = S * lightray->direction.x + lightray->origin.x; collisionPoint.y = S * lightray->direction.y + lightray->origin.y; collisionPoint.z = S * lightray->direction.z + lightray->origin.z; diff --git a/raytrace.c b/raytrace.c index 7b1818f..889d7ef 100644 --- a/raytrace.c +++ b/raytrace.c @@ -37,15 +37,14 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) { lightray->origin = nearestCollisionPoint; } else { - sphereNormal = (vec3){0,0,0}; + sphereNormal = (vec3){1,1,1}; } } - if (nearestSphere != nullptr) - { + //pixel.r = -vec3Product(sphereNormal, lightray->direction); pixel = (RGBA){1 - 0.5 *( sphereNormal.x + 1), 1 - 0.5 * (sphereNormal.y +1), 1 -0.5* (sphereNormal.z + 1),1}; - } + free(spheresHitList); return pixel; diff --git a/test.png b/test.png index 116c575..99add92 100644 Binary files a/test.png and b/test.png differ