public static double[,] lookAt(Vektor pos, Vektor target, Vektor up) { Vektor zaxis = pos - target; zaxis = zaxis.Normalise(); Vektor xaxis = Vektor.CrossProduct(up, zaxis); xaxis = xaxis.Normalise(); Vektor yaxis = Vektor.CrossProduct(zaxis, xaxis); double[,] orientation = { { xaxis.X, yaxis.X, zaxis.X, 0 }, { xaxis.Y, yaxis.Y, zaxis.Y, 0 }, { xaxis.Z, yaxis.Z, zaxis.Z, 0 }, { 0, 0, 0, 1 } }; double[,] translation = { { 1, 0, 0, -pos.X }, { 0, 1, 0, -pos.Y }, { 0, 0, 1, -pos.Z }, { 0, 0, 0, 1 } }; return(Matrix.MultiplyMatrix(orientation, translation)); }
public static double[,] PointAt(Vektor pos, Vektor target, Vektor up) { Vektor zaxis = pos - target; zaxis = zaxis.Normalise(); Vektor xaxis = Vektor.CrossProduct(up, zaxis); xaxis = xaxis.Normalise(); Vektor yaxis = Vektor.CrossProduct(zaxis, xaxis); double[,] matrix = { { xaxis.X, xaxis.Y, xaxis.Z, pos.X }, { yaxis.X, yaxis.Y, yaxis.Z, pos.Y }, { zaxis.X, zaxis.Y, zaxis.Z, pos.Z }, { 0, 0, 0, 1 } }; return(matrix); }