only reflections
This commit is contained in:
@@ -17,12 +17,14 @@ vec3 collisionPointSphere(ray *lightray, sphere *object)
|
|||||||
if (discriminant < 0) return collisionPoint;
|
if (discriminant < 0) return collisionPoint;
|
||||||
if (discriminant > 0) {
|
if (discriminant > 0) {
|
||||||
double S = (-b - sqrt(discriminant)) / (2 * a);
|
double S = (-b - sqrt(discriminant)) / (2 * a);
|
||||||
|
if (S < 0) return collisionPoint;
|
||||||
collisionPoint.x = S * lightray->direction.x + lightray->origin.x;
|
collisionPoint.x = S * lightray->direction.x + lightray->origin.x;
|
||||||
collisionPoint.y = S * lightray->direction.y + lightray->origin.y;
|
collisionPoint.y = S * lightray->direction.y + lightray->origin.y;
|
||||||
collisionPoint.z = S * lightray->direction.z + lightray->origin.z;
|
collisionPoint.z = S * lightray->direction.z + lightray->origin.z;
|
||||||
return collisionPoint;
|
return collisionPoint;
|
||||||
}
|
}
|
||||||
double S = (-b)/(2*a);
|
double S = (-b)/(2*a);
|
||||||
|
if (S < 0) return collisionPoint;
|
||||||
collisionPoint.x = S * lightray->direction.x + lightray->origin.x;
|
collisionPoint.x = S * lightray->direction.x + lightray->origin.x;
|
||||||
collisionPoint.y = S * lightray->direction.y + lightray->origin.y;
|
collisionPoint.y = S * lightray->direction.y + lightray->origin.y;
|
||||||
collisionPoint.z = S * lightray->direction.z + lightray->origin.z;
|
collisionPoint.z = S * lightray->direction.z + lightray->origin.z;
|
||||||
|
|||||||
+3
-4
@@ -37,15 +37,14 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
|||||||
lightray->origin = nearestCollisionPoint;
|
lightray->origin = nearestCollisionPoint;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sphereNormal = (vec3){0,0,0};
|
sphereNormal = (vec3){1,1,1};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nearestSphere != nullptr)
|
|
||||||
{
|
|
||||||
//pixel.r = -vec3Product(sphereNormal, lightray->direction);
|
//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};
|
pixel = (RGBA){1 - 0.5 *( sphereNormal.x + 1), 1 - 0.5 * (sphereNormal.y +1), 1 -0.5* (sphereNormal.z + 1),1};
|
||||||
}
|
|
||||||
free(spheresHitList);
|
free(spheresHitList);
|
||||||
return pixel;
|
return pixel;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user