Recursive reflection: Base on the recursive algorithm in unit 10 section 2 objec
ID: 3862253 • Letter: R
Question
Recursive reflection:
Base on the recursive algorithm in unit 10 section 2 objective 3 (shown below), implement a recursive routine in the program of unit 11 section 2 objective 1 (shown below) to produce a similar reflective effect. The minimum requirement is to rewrite the method render() of the program to implement the recursive ray tracing algorithm.
The implemented recursive method should cast a ray from the ray source to the scene. The ray may either hit the wall (a non-reflective surface here) or hit the floor (a reflective surface here). If it hits the wall, the method can terminate the recursion and return the local color of the wall. If the ray hits the floor, the method should (recursively) invoke itself with the reflection ray, and calculate and return the mixed color as demonstrated in the original render() routine. You may hard-code the inclusion test or you may implement your own method to support the inclusion. Also you may need to hard-code the normal vector of the wall and the floor. Feel free to change the program to suit your needs.
Recursive algorithm in unit 10 section 2 objective 3 (pseudocode):
Program of unit 11 section 2 objective 1 (the one needed to be modified to implement recursive ray tracing):
Please post a different answer than the following, as it is incorrect:
// create stencil mask
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glColorMask(0, 0, 0, 0);
glBegin(GL_QUADS);
glNormal3f(1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(a.x, a.y, a.z);
glVertex3f(b.x, b.y, b.z);
glVertex3f(c.x, c.y, c.z);
glVertex3f(d.x, d.y, d.z);
glEnd();
// draw mirrored scene
glColorMask(1, 1, 1, 1);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, p);
dmFlipFaces();
glPushMatrix();
glMultMatrixf(m);
glClear(GL_DEPTH_BUFFER_BIT);
Scene->Render();
glPopMatrix();
dmFlipFaces();
glDisable(GL_CLIP_PLANE0);
glDisable(GL_STENCIL_TEST);
MirrorRecursion--;