View Full Version : Mirror Effect
08-26-2008, 06:03 PM
Hi there, I am trying to create a mirror, the problem is the mirror lies on a z value of -2 and I can't change it for various reasons. So I can't use glscale, I need to use a translation and a rotation, but I cannot figure out how to do this. I can create a mirror but the distance becomes inverted. E.g close items to the mirror are at the back in the reflected image.
Here is an image to illustrate the problem.
08-27-2008, 12:42 AM
I don't quit follow you with your current post...
Refine your problem/question please.
What's the input (you have to have a mirror at z=-2 and ..)?
What's the output (what you want to get)?
08-27-2008, 03:20 AM
Hey, ok i will try.
Basically I want to create a mirror in the middle plane. The mirror image is restricted to the plane through a stencil buffer, and the plane behind the mirror doesn't actually exist I just put it in the diagram as an example to show what I want displayed in the mirror.
So I need to, through a rotation and a translation, move the scene into the mirror, e.g I could rotate it 180 in the y axis, then translate it on the x axis, but then things on the LHS of the plane would be on the RHS Of the mirror which is wrong.
I also forgot to mention that the origin is in the middle of the scene plane
08-27-2008, 09:25 AM
have you tried this
Either way, you should be able to use glscale and still get a great result, just make sure your translations are in the right order and orientation.
08-27-2008, 11:52 PM
thanks for that. Yeh i think could actually go transform +2 then scale by -1.0 then transform -2. But I'm not allowed I have to do a rotation somewhere I think.
08-28-2008, 01:04 AM
No, you dont want to rotate anything.
None of the X or Y coordinates change when you do a reflection, any rotation will make the reflection the wrong way around or upside down.
You need to add 2 to every Z coordinate first so that the mirror is at Z=0 and every real object has a positive Z coordinate.
Then you simply change the sign of the Z coordinate to reflect everything to the other side of the mirror.
Znew = 0 - Zold
So combining the offset and the reflection gives us:
Znew = 0 - ( Zold + 2 ) = 0 - Zold - 2
The transform +2, scale -1.0 you mentioned should do exactly this.
The second transform by -2 shifts everything back to the original world coordinates before you do the camera/view transform.
Effectivly this does:
Znew = 0 - Zold - 2 - 2
Which simplifies to:
Znew = 0 - Zold - 4
So a scale by -1.0 then a transform by -4 does the exact same thing.
glScalef(1.0f, 1.0f, -1.0f);
glTranslatef(0.0f, 0.0f, -4.0f);
What do you mean by "I'm not allowed" ?
08-28-2008, 01:35 AM
Yeh I realise now that I can do that, but it is for an assignment, thats what I meaaaan :p Kind of annoying theres so many ways that this can be done, but the lecturer wants us to rotate it on somehow. I'm baffled.
08-28-2008, 04:05 AM
Using negative scaling lead to the inversion of the normal. :p
The good news is that you can do same procedure with a 'pi' rotation around the Y axis. :)
So you have to translate your object to the origin, rotate it and then translate it in the mirrored (Zmirror + (Zold - Zmirror) * 2)
08-28-2008, 04:17 AM
The glScale -1.0 "is" the reflection, so you have to have that.
To do the reflection we only need the mirror at Z=0, it doesn't matter which way it is facing, so the translations can be replaced with a 180 degree rotation around a point halfway between the mirror and the origin, ie. at (0,0,-1).
But any rotation has to be reversed or everything ends up the wrong way around.
So if you do the Rotation (which puts mirror at z=0 but reverses all axis directions), then Scale -1.0, then rotate again (mirror goes back to the original position and axes are back to normal) you should get what you want.
08-28-2008, 08:05 PM
wow thanks for the input guys. I have to head away for a few days, but when i'm back Ill try it and let you know. Cheers!
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.