This function returns a texture matrix that will aim the texture to the midpoint between the active camera and the given reference camera or light.
888 {
889
891
893 Vector3 vLook, camUp, camLook;
895 Matrix invCamMtx = cam.
_matrix;
896
898 camLook._x = -m34[8];
899 camLook._y = -m34[9];
900 camLook._z = -m34[10];
901
902 if (refLight >= 0)
903 {
904 Vector3 lgtLook = GetLightLook(node, refLight, invCamMtx, v, frame, out bool specEnabled);
905
906
907 if (!specEnabled)
908 {
909 vLook = GetHalfAngle(camLook, lgtLook);
910 }
911 else
912 {
913 vLook = -lgtLook;
914 }
915
916 if (Math.Abs(vLook._x) < 0.000001f &&
917 Math.Abs(vLook._z) < 0.000001f)
918 {
919 camUp._x = camUp._y = 0.0f;
920 if (vLook._y <= 0.0f)
921 {
922
923 camUp._z = -1.0f;
924 }
925 else
926 {
927
928 camUp._z = 1.0f;
929 }
930 }
931 else
932 {
933 camUp._x = camUp._z = 0.0f;
934 camUp._y = 1.0f;
935 }
936 }
937 else if (refCam >= 0)
938 {
940
942 {
944 }
945 else
946 {
948 }
949
951
952
954 camUp._x = lgtCam[4];
955 camUp._y = lgtCam[5];
956 camUp._z = lgtCam[6];
957 Vector3 lgtLook = new Vector3(-lgtCam[8], -lgtCam[9], -lgtCam[10]);
958
959 vLook = GetHalfAngle(camLook, lgtLook);
960 }
961 else
962 {
963 return (Matrix) finalMtx;
964 }
965
966 vLook.Normalize();
967 Vector3 vRight, vUp;
968
969 vUp = (vRight = vLook.Cross(camUp).Normalize()).Cross(vLook);
971 vRight._x, vRight._y, vRight._z, 0.0f,
972 vUp._x, vUp._y, vUp._z, 0.0f,
973 vLook._x, vLook._y, vLook._z, 0.0f);
974
975 m34 = (
Matrix34) ((Matrix) m34 * invCamMtx);
976 m34[3] = 0.0f;
977 m34[7] = 0.0f;
978 m34[11] = 0.0f;
979
980 return (Matrix) (finalMtx * m34);
981 }