# Problem with D3DXMatrixReflect

Currently I am trying to reflect a sky sphere into a flat piece of geometry which is acting as water. The sphere is very small, it follows the camera on all 3 axis and the z-buffer is turned off so it appears behind everything else.

Can someone please tell me how I can reflect the world matrix on a xz plane. And should I the plane be the water height or the camera height.

Thank you.

-

Given a general plane with equation `A*x + B*y + C*z + D = 0`, the reflection matrix for this plane is:

``````1 - 2*A*A,    -2*A*B,    -2*A*C, 0,
-2*B*A, 1 - 2*B*B,    -2*B*C, 0,
-2*C*A,    -2*C*B, 1 - 2*C*C, 0,
-2*A*D,    -2*B*D,    -2*C*D, 1
``````

This is for OpenGL, so you might need to transpose the matrix for DirectX or something. Unfortunately I can't find any sources for the formula.

For your simpler case with xz-plane, a simpler matrix is enough. The following matrix mirrors in y-direction with y given as the plane height.

``````1,  0, 0, 0,
0, -1, 0, 0,
0,  0, 1, 0,
0,-2y, 0, 1
``````

Again you might need to transpose the matrix or switch -2y to 2y.

-