This project is an introduction to the beautiful world of Raytracing. Once completed you will be able to render simple Computer-Generated-Images and you will never be afraid of implementing mathematical formulas again.
I think now it's easier to both reading it and adding more functionalities, but I want you to read the changes to see if you can improve it further or if anything is not clear @Juan-aga. Main changes are:
The program exits earlier if the scene is badly formed, in previous versions of our program, the MLX window was always displayed and then closed.
Separate code for object parsing and object representation.
Sort functions inside files from more abstraction to less abstraction. For example, I have put the functions of the engine in the following order so we can read it from top to bottom:
render: there are a lot of thing going on in this function, calls raycast in order to render
raycast: calls hit_objects in order to know which object the ray hits
hit_objects: calculates object / ray intersection
ray_color: calculates the color, lighting and shading of a ray
ray_at: utility function to calculate the depth of a ray hit, a very concret thing
Implement the epsilon variable (smallest value bigger than 0) to compare instead of 0, because when working with doubles, there can be bugs when working with small precision.
Implement the quadratic equation struct to hold all the necessary variables and a function to calculate the quadratic solution: $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$
Fix the sphere formula.
vec3_unit function name is changed to vec3_normalize to better show what it does
I think now it's easier to both reading it and adding more functionalities, but I want you to read the changes to see if you can improve it further or if anything is not clear @Juan-aga. Main changes are:
render
: there are a lot of thing going on in this function, calls raycast in order to renderraycast
: calls hit_objects in order to know which object the ray hitshit_objects
: calculates object / ray intersectionray_color
: calculates the color, lighting and shading of a rayray_at
: utility function to calculate the depth of a ray hit, a very concret thingx = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$