When the plane is set to (NX,NY,NZ,D), the column main sequence reflection matrix with this planar mirror is as follows:
The derivation is as follows:
One, the expression of the platform:
, over point P, the plane of the normal vector n, can be expressed as:
Np+d=0
where D is the forward distance from the plane to the origin point. If the plane faces the origin, D is positive and D is negative if the plane is back to the origin point.
So the plane can be represented as a four-dimensional vector (nx,ny,nz,d).
Two, Reflection matrix derivation:
The plane is np+d=0,q for any point, Q ' is the projection of Q on the plane, Q ' is the symmetric point of Q about the plane, has the following relationship:
R=q-p
A= (RN) n
B=r-a
C=-a
Q ' =p+b
Q ' =q ' +c
Np+d=0
The combination of all the above, to:
Q ' =q-2 (qn+d) n
Written in the form of components, namely:
Q ' X=qx-2 (qx*nx+qy*ny+qz*nz+d) *nx
Q ' Y=qy-2 (qx*nx+qy*ny+qz*nz+d) *ny
Q ' Z=qz-2 (qx*nx+qy*ny+qz*nz+d) *nz
Organized by:
Q ' X=qx (1-2nx*nx) +qy ( -2NY*NX) +qz ( -2NZ*NX) -2d*nx
Q ' Y=qx ( -2nx*ny) +qy (1-2ny*ny) +qz ( -2nz*ny) -2d*ny
Q ' Z=qx ( -2NX*NZ) +qy ( -2NY*NZ) +qz (1-2NZ*NZ) -2d*nz
Written in matrix form:
This will get the reflection matrix.
The Water.cs in Unity Standard assets has the following section to calculate the reflection matrix code, consistent with the results above:
Calculates reflection matrix around the given plane
static void Calculatereflectionmatrix (ref matrix4x4 Reflectionmat, Vector4 plane)
{
REFLECTIONMAT.M00 = (1F-2F * plane[0] * plane[0]);
REFLECTIONMAT.M01 = (-2F * plane[0] * plane[1]);
REFLECTIONMAT.M02 = (-2F * plane[0] * plane[2]);
Reflectionmat.m03 = (-2F * plane[3] * plane[0]);
REFLECTIONMAT.M10 = (-2F * plane[1] * plane[0]);
REFLECTIONMAT.M11 = (1F-2F * plane[1] * plane[1]);
REFLECTIONMAT.M12 = (-2F * plane[1] * plane[2]);
Reflectionmat.m13 = (-2F * plane[3] * plane[1]);
REFLECTIONMAT.M20 = (-2F * plane[2] * plane[0]);
Reflectionmat.m21 = (-2F * plane[2] * plane[1]);
REFLECTIONMAT.M22 = (1F-2F * plane[2] * plane[2]);
REFLECTIONMAT.M23 = (-2F * plane[3] * plane[2]);
REFLECTIONMAT.M30 = 0F;
REFLECTIONMAT.M31 = 0F;
Reflectionmat.m32 = 0F;
Reflectionmat.m33 = 1F;
}
Reference: http://www.euclideanspace.com/maths/geometry/affine/reflection/matrix/
Reflection matrix (reflection matrix) derivation