PDA

View Full Version : Mirroring the modelview matrix



Catman
04-16-2003, 04:13 AM
Hi there! I've done a lot of search on this topic, but I did not find any good papers or tutorials dealing with this problem... I'd like to implement arbitrary facing stencil mirrors. For this I need to mirror the modelview matrix to the mirror plane. How do I do this? I'd really appreciate any help...

Jan
04-17-2003, 03:22 AM
I donīt know how nehe does this, but he has a stencil-mirror demo. Maybe there you find what you mean:

nehe.gamedev.net

Jan.

Catman
04-21-2003, 11:20 PM
Thanks, but in the nehe tutorial the mirror lies in the xz plane.

But anyway I figured out how to solve my problem. http://www.opengl.org/discussion_boards/ubb/smile.gif

errno
04-21-2003, 11:50 PM
with the plane: aX + bY + cZ + D = 0
you should concatenate the model view matrix
with:

float m[16];

m[0] = 1-2*a*a;
m[1] = -2*b*a;
m[2] = -2*c*a;
m[3] = 0.0;
m[4] = -2*a*b;
m[5] = 1-2*b*b;
m[6] = -2*c*b;
m[7] = 0.0;
m[8] = -2*a*c;
m[9] = -2*b*c;
m[10]= 1-2*c*c;
m[11]= 0.0;
m[12] = -2*a*d;
m[13] = -2*b*d;
m[14]= -2*c*d;
m[15]= 1.0;

you don't need to swap columns and lines
to use this matrix with opengl.

the plane equation may be aX+bY+cZ=d, i
don't remember.

Catman
04-23-2003, 01:11 AM
Here's my soulution:

Rotate until the mirror's plane lies in the xz plane
glScale(0.0,-1.0,0.0)
Rotate back to the original position
Render mirrored image

Is this correct?

AdrianD
04-23-2003, 05:10 AM
Originally posted by Catman:
[...]
Is this correct?

you mean: glScale(1,-1,1);
otherwise you scale xz by factor 0.

...but you knew this allready, and this was just a typo, right ?

btw. when you do mirroring, don't forget, to reverse the polygon backface culling direction.

errno
04-23-2003, 05:14 AM
i don't think that your solution work.
there are an infinity of rotation that make the mirror in the xz plane (concatenate with rotation around Oy), but i don't think there are an infinity of transformation that mirror the scene.

i may be wrong, but i think that rotation+scale+rotation don't work.

JustHanging
04-23-2003, 09:25 AM
Yeah, your solution doesn't work, the reason is that when you rotate the object you also rotate it's coordinate system and scaling will take place in it's local coordinates, so it doesn't matter which orientation the object is at... I'm sure there's a way to fix it by rearranging the transformations, but I'd just stick to the matrix yoyo gave you.

-Ilkka

Catman
04-23-2003, 03:43 PM
Yea, now that I think about it you are rigth. I think I'll just use yoyo's method. I think it is also easier to implement because in my solution you would have to find out rotation angles from the mirror's normal vector... Thank all of you. http://www.opengl.org/discussion_boards/ubb/smile.gif