public Vector3 Unproject(Vector3 source, Matrix projection, Matrix view, Matrix world) { Vector3 position = new Vector3(); Matrix matrix = Matrix.Invert(Matrix.Multiply(Matrix.Multiply(world, view), projection)); position.X = (((source.X - this.X) / ((float) this.Width)) * 2f) - 1f; position.Y = -((((source.Y - this.Y) / ((float) this.Height)) * 2f) - 1f); position.Z = (source.Z - this.MinDepth) / (this.MaxDepth - this.MinDepth); position = Vector3.Transform(position, matrix); float a = (((source.X * matrix.M14) + (source.Y * matrix.M24)) + (source.Z * matrix.M34)) + matrix.M44; if (!WithinEpsilon(a, 1f)) { position = (Vector3) (position / a); } return position; }