reflection on arbitrary plane?


i am new to this board, any help or hints with this problem would be very much appreciated:

i’ve been reading through several articles on opengl reflection and i seem only to find something about reflection on any of the XY, XZ, YZ planes using something like:


now i can transform any model by the inverse of the mirror transformation matrix (putting the reflection plane back to the origin), do the reflection and rotate it back to it’s original position.

But, if it was possible, it would be much more comfortable to just use one reflection matrix. i’ve used a shadow projection matrix and it seems to me that if you can project any point to any arbitrary plane in space, it should also be possible to do the same with reflection.

P’ (the original point)
P’’ (the reflected point)
n (the normal vector of my reflection plane)

P’ -> P’’ should be P’+x*n
(x would be twice the distance between my original point and the plane)

is there a way to resolve that to a matrix ?(should have paid attention in school)

thanks a lot…

[This message has been edited by h______f (edited 01-05-2001).]

you can make a reflection using glScalef at any plane i.e glScalef(0.5,0.1,-0.799); , although it gets difficult with clipping and stenciling etc. I’m not sure if that is what you mean.

Here’s the code for generation of matrix(Delphi).

matr1 : matr44 =
///translated and rotated to the center of mirror
IP := asSpoint(ASPOINT(MaTR[3,0],MATR[3,1],MATR[3,2]));//store current translation
matr[3,0] := 0;
matr[3,1] := 0;
matr[3,2] := 0;
xform(aspoint(0,0,1),matr,NRM);//NRM- normal for current rotation
k := 2dot3(ip,nrm);
matr[0,0] := (1-2
matr[1,1] := (1-2sqr(nrm[1]));
matr[2,2] := (1-2
matr[0,1] := -2*nrm[0]nrm[1];
matr[1,0] := matr[0,1];
matr[0,2] := -2
matr[2,0] := matr[0,2];
matr[2,1] := -2
matr[1,2] := matr[2,1];
matr[3,0] := Ip[0];
matr[3,1] := Ip[1];
matr[3,2] := Ip[2];

[This message has been edited by RandyU (edited 01-05-2001).]

I didn’t try RandyU’s matrix but I think this one will work too (please tell me if it didn’t):

Well, suppose that the plane’s equation is:

ax + by + c*z + d = 0

and that a, b and c are normalized Then you form the following vectors:

j = (a, b, c)
I = (b-c, c-a, a-b)
i = I/|I| (where |I| is the length of I)
k = i X j (where X is the cross product)
D = d*j

Then you form a two matrices from the 3 vectors i, j and k:


| ix iy iz 0|
| jx jy jz 0|
| kx ky kz 0|
| 0 0 0 0|

RT = Transpose® (RT is the same as R but with replacing the columns by the rows)

Now you do this:

glTranslate(-Dx, -Dy, -Dz);
glTranslate(Dx, Dy, Dz);