This is my third question in this raytracing work, but there has been progress: P So, I am implementing a C ++ ray tracer for my object-oriented programming class, and so far I have implemented monochromatic spheres and planes with support for reflection and mirror shading. This is an example of what I did:

Now I am trying to implement common polyhedrons. I use a modified version of this algorithm to calculate intersections with an arbitrary polyhedron from nFaces () faces, each of which is contained in the plane defined by Vec Polyhedron :: point (int face) and Vec Polyhedron :: normal (int face):
Vec Polyhedron::intersect(Vec o, Vec d)
{
int face = nFaces();
Vec ni(0,0,0), pi(0,0,0);
unit te = -1;
unit tl = -1;
unit t = 0;
unit N, D;
Vec v = d.normal();
int facein, faceout;
for(int i = 0; i < face; i++)
{
ni = normal(i);
pi = point(i);
N = ((pi - o)*ni);
D = v*ni;
if(D == 0 && N < 0)
return o;
if(D != 0)
{
t = N/D;
if(t > 0)
{
if(N < 0)
{
if(t > te){
te = t;
facein = i;
}
}else{
if((tl == -1) || (t < tl)){
tl = t;
faceout = i;
}
}
if((tl != -1) && (tl < te))
return o;
}
}
}
if(tl != -1)
{
if(te != -1)
{
v = v*te + o;
return (v + normal(facein)*0.000000000001);
}
v = v*tl + o;
return (v + normal(faceout)*0.000000000001);
}
return o;
}
, , ( Polyhedron, , Cuboid) . :

, . ?