Mirroring the modelview matrix

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…

I don´t know how nehe does this, but he has a stencil-mirror demo. Maybe there you find what you mean:

Jan.

Thanks, but in the nehe tutorial the mirror lies in the xz plane.

But anyway I figured out how to solve my problem.

with the plane: aX + bY + cZ + D = 0
you should concatenate the model view matrix
with:

float m[16];

m[0] = 1-2aa;
m[1] = -2ba;
m[2] = -2ca;
m[3] = 0.0;
m[4] = -2ab;
m[5] = 1-2bb;
m[6] = -2cb;
m[7] = 0.0;
m[8] = -2ac;
m[9] = -2bc;
m[10]= 1-2cc;
m[11]= 0.0;
m[12] = -2ad;
m[13] = -2bd;
m[14]= -2cd;
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.

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?

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.

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.

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

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.