I'm working on a small ray tracing project in my free time and I'm currently implementing boolean operations for spheres.
My code is setup to calculate the intersection points of each of the spheres with any given ray and spit out the correct points to be rendered to the screen based on the type of boolean operation being performed (Union, Difference or Intersection).
I haven't been at it for too long, but so far I have the code for the Intersection running nicely:
v3df
and v2df
are 3d and 2d float vectors respectively.
s1t
and s2t
are the intersection points for each of the spheres with a ray.
if(s1t.x == 0 && s1t.y == 0 || s2t.x == 0 && s2t.y == 0)
return v2df();
if(min(s1t.x, s1t.y) > max(s2t.x, s2t.y) || min(s2t.x, s2t.y) > max(s1t.x, s1t.y))
return v2df();
std::vector<float> values = { s1t.x, s1t.y, s2t.x, s2t.y };
std::sort(values.begin(), values.end());
v2df res(values[2], values[1]);
return res;
This produces the following output with variable spheres:
Now I would like to implement the normals for said intersection, and my basic idea would be to take the normals of each of the corresponding spheres where their geometry shows, but I'm at a loss for how to implement this.
here's the method stub I would like to use:
v3df GetNormal(v3df point) {
return v3df();
}