internal static Vector3d Unproject(Viewport viewport, Vector3d source, Matrixd projection, Matrixd view, Matrixd world) { //return new Vector3d(viewport.Unproject(source.ToVector3(), projection.toMatrix(), view.toMatrix(), world.toMatrix())); Matrixd matrix = Matrixd.Invert(Matrixd.Multiply(Matrixd.Multiply(world, view), projection)); Vector3d source2 = new Vector3d(0, 0, 0); source2.X = (((source.X - viewport.X) / (viewport.Width)) * 2f) - 1f; source2.Y = -((((source.Y - viewport.Y) / (viewport.Height)) * 2f) - 1f); source2.Z = (source.Z - viewport.MinDepth) / (viewport.MaxDepth - viewport.MinDepth); Vector3d vector = Vector3d.Transform(source2, matrix); double a = (((source2.X * matrix.M14) + (source2.Y * matrix.M24)) + (source2.Z * matrix.M34)) + matrix.M44; if (!WithinEpsilon(a, 1f)) { vector.X = vector.X / a; vector.Y = vector.Y / a; vector.Z = vector.Z / a; } return(vector); }
public static Matrixd operator *(Matrixd matrix1, Matrixd matrix2) { return(Matrixd.Multiply(matrix1, matrix2)); }