Simulating Rear View Mirror

I am working with OpenGL and MFC on Driving Simulators from last 2.5 years. Now is a requirement to simulate Rear View Mirror. What is the technique involved in this concept?

i think (but only think) that you may use the stencil buffer.

This is OpenGL coding: advanced forum. Please, don’t fill it with questions that can be easyly answered on beginners forum.

Using the stencil buffer is one option. Basically you have to draw the reflection of the scene from the viewpoint of the mirror. You have two options. Draw the mirror/reflection first, then change the camera to what it should be (looking out the car) and draw the rest of the scene but not the mirror itself and don’t clear the color buffer inbetween, just the z and perhaps stencil. If you want to draw the scene first (the second method), draw the scene and draw the mirror with stencil writes (mask out just the mirror). Then draw the reflection allowing frame buffer writes only when the stencil passes (drawing only where the mirror is).

The first saves using the stencil buffer but the latter can actually be faster because the stencil saves writing. Although if the mirror is very large relative to the screen, that is, the stencil test passes most of the time, then its basically the same as the first method.

Originally posted by Zak McKrakem:
This is OpenGL coding: advanced forum. Please, don’t fill it with questions that can be easyly answered on beginners forum.

Read the description of the beginners forum … "If you are just beginning to code with OpenGL, post your questions here "

He has indicated that he has been using OpenGL no less than 2.5 years and this is not quite a beginning topic anyhow.

Zak, this question is entirely appropriate for this forum. Answer the question if you want but don’t clutter the forum criticizing people for asking questions.

Devulon, you don’t draw the scene from the mirror, you draw the scene from the eye position reflected in the mirror and draw from the same place as the normal scene’s eye position, or you can do a modelview reflection through the plane of the mirror(best option IMHO). Make sure you reverse the face winding. Use glCullFace for this. You may also need a glClipPlane through the plane of the mirror.

It’s not clear if the mirror is in the 3D scene or if it’s just a mirror viewport in the framebuffer, this could be really simple to implement if the mirror itself isn’t transformed in the scene. It’s just a viewport and glScissor operation and redraw the scene with an axis aligned reflection and cullface reversal.

Could you explain a bit more about what you are trying to do SAIKUMAR, that way we can better advise you. Is this just a single channel mirror to be displayed on a different screen, is at a fixed overlay on an existing 3D scene, or is it a 3D mirror in a virtual world which correctly reflects the scene?

[This message has been edited by dorbie (edited 02-20-2002).]

If you do a web search on “portal engine” you’ll learn all you need about this. The mirror would be your “portal” in this case.