Sign in to follow this  
netsach

Mirrored rear view

Recommended Posts

I have searched the forum about mirror effect, and found many things about it but none of them answered my specific case. First thing is that my mirror is not an object in the world, i just want a rear view in a secondary viewport (ie, upper part of the screen is the rear view viewport, the lower part is the front viewport). What i am doing, as you may guess, is render the front view to the lower part, then set the camera in the oposite direction and render to the upper viewport. And yes, the left and right directions are inverted. And i do not want that. I ask despite the many posts about the topic out there, because the rear view is not a mirror in the scene and there must be a clever way to simply redraw the rear view in a special way to the secondary viewport. I could do a render to texture and render the fliped quad to the viewport, but if i could avoid it i'd be happy. A solution was to call gluPerspective using a positive fovy and a negative aspect (so the fovx 'appears' negative). This inverts the left and right successfully, but on the other side, i have lost some polygons during the scene draw and the texture coordinates are screwed. And furthermore, it is not documented so this may be an unpredictable result. I tried the glScale trick (same results, and same poly/texture errors), i do not understand much about scissor and stencil buffer (but i am willing to learn). Any idea ? And if all else fails, i'll use render to texture... :) netsach

Share this post


Link to post
Share on other sites
Well, sorry i ate some server memory and grabbed your attention, because i solved my problem.

I understood the problem when i saw that when looking on the front side, the texture coordinates were screwed up, but after walking through the walls, i saw that on the rear face the textures were ok !

So the glScalef/glFrontView combo solved it : i simply set to back facing polygons for rear view (here is the pseudo code for those who may have the same problems) :

- set viewport for front view
- matrixmode(projection), load identity
- set perspective for front view
- matrixmode(modelview), load identity
- glulookat(eye direction) or translate/rotate
- glfrontface(CCW)
- draw front view

- set viewport for rear view
- matrixmode(projection), load identity
- set perspective for rear view
- matrixmode(modelview), load identity
- glScalef(-1,1,1) to invert left and right
- glulookat(opposite eye direction) or translate/rotate
- glfrontface(CW)
- draw rear view

That's it !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this