鏡面反射是以鏡面作為反射平面,實物與反射物到反射平面的距離相等盐欺,實物與反射物方向相反,所以仅醇,反射矩陣由反射平面確定冗美,根據(jù)反射平面先推導出反射位置,再進行旋轉(zhuǎn)即可得到反射矩陣析二。
反射位置:
b00c349b033b5bb56e0f044b31d3d539b700bc67.jpg
aca3033b5bb5c9eabd2b2756d239b6003bf3b367.jpg
反射方向:
9b035bb5c9ea15ce9f36c4bcb1003af33b87b267.jpg
c38dc9ea15ce36d37fdca7853df33a87e850b167.jpg
第二點是根據(jù)投影向量獲得
U_proj_on_V_readme.JPG
n向量是單位向量所以投影向量公式的分母可以去掉粉洼。
M1M2即得到反射矩陣。
static Matrix4x4 CalculateReflectionMatrix (Matrix4x4 reflectionMat, Vector4 plane)
{
reflectionMat.m00 = (1.0F - 2.0Fplane[0]plane[0]);
reflectionMat.m01 = ( - 2.0Fplane[0]plane[1]);
reflectionMat.m02 = ( - 2.0Fplane[0]plane[2]);
reflectionMat.m03 = ( - 2.0Fplane[3]*plane[0]);
reflectionMat.m10 = ( - 2.0F*plane[1]*plane[0]);
reflectionMat.m11 = (1.0F - 2.0F*plane[1]*plane[1]);
reflectionMat.m12 = ( - 2.0F*plane[1]*plane[2]);
reflectionMat.m13 = ( - 2.0F*plane[3]*plane[1]);
reflectionMat.m20 = ( - 2.0F*plane[2]*plane[0]);
reflectionMat.m21 = ( - 2.0F*plane[2]*plane[1]);
reflectionMat.m22 = (1.0F - 2.0F*plane[2]*plane[2]);
reflectionMat.m23 = ( - 2.0F*plane[3]*plane[2]);
reflectionMat.m30 = 0.0F;
reflectionMat.m31 = 0.0F;
reflectionMat.m32 = 0.0F;
reflectionMat.m33 = 1.0F;
return reflectionMat;
}
其中代碼中4維數(shù)組plane存的是點法線式平面方程的參數(shù)甲抖。