public void ApplyOrthographicCentered() { ViewMatrix = Matrix4.View(Position, LookAtPosition, UpPosition-Position); ProjectionMatrix = Matrix4.OrthographicCentered(ViewPort.Size.Width, ViewPort.Size.Height, Near, Far); TransformMatrix = ViewMatrix.Multiply(ProjectionMatrix); TransformInverseMatrix = TransformMatrix.Invert(); }
public void Apply() { ViewMatrix = Matrix4.View(Position, LookAtPosition, UpPosition-Position); ProjectionMatrix = Matrix4.Perspective(Fov, float.IsNaN(Aspect) ? ViewPort.AspectRatio : Aspect, Near, Far); TransformMatrix = ViewMatrix.Multiply(ProjectionMatrix); TransformInverseMatrix = TransformMatrix.Invert(); }
public static void UnProject(ref Vector4 vector, ref Matrix4 projectionMatrix, ref Matrix4 viewMatrix, int viewX, int viewY, int viewWidth, int viewHeight, out Vector4 result) { var viewProjInverse = viewMatrix.Multiply(projectionMatrix).Invert(); result = vector; result.X = (result.X - viewX) / viewWidth; result.Y = (result.Y - viewY) / viewHeight; result = (result * 2) - 1; result = result.Transform(viewProjInverse); float wDelta = 1 / result.W; result.X *= wDelta; result.Y *= wDelta; result.Z *= wDelta; }
public Vector4 UnProject(Matrix4 projectionMatrix, Matrix4 viewMatrix, int viewX, int viewY, int viewWidth, int viewHeight) { var viewProjInverse = viewMatrix.Multiply(projectionMatrix).Invert(); var result = this; result.X = (result.X - viewX) / viewWidth; result.Y = (result.Y - viewY) / viewHeight; result = (result * 2) - 1; result = result.Transform(viewProjInverse); float wDelta = 1 / result.W; result.X *= wDelta; result.Y *= wDelta; result.Z *= wDelta; return(result); }
public Vector4 UnProject(Matrix4 projectionMatrix, Matrix4 viewMatrix, int viewX, int viewY, int viewWidth, int viewHeight) { var viewProjInverse = viewMatrix.Multiply(projectionMatrix).Invert(); var result = this; result.X = (result.X - viewX) / viewWidth; result.Y = (result.Y - viewY) / viewHeight; result = (result * 2) - 1; result = result.Transform(viewProjInverse); float wDelta = 1 / result.W; result.X *= wDelta; result.Y *= wDelta; result.Z *= wDelta; return result; }