Advertisement
Guest User

Untitled

a guest
Jan 6th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. // Variant A (Working for Start > End and Start < End)
  2. protected virtual void LerpTransformLinear(Vector2 startpos, Vector2 endpos,
  3.                                            float startzoom, float endzoom, float ammount)
  4. {
  5.    // set private Position field to lerp between the Start Position and the End Position of the given Ammount.
  6.    m_position = Vector2.Lerp(startpos, endpos, ammount);
  7.    // set private Zoom field to lerp between the Start Zoom and the End Zoom of the given Ammount.
  8.    m_zoom = MathHelper.Lerp(startzoom, endzoom, ammount);
  9.  
  10.    // Set private Matrix field to a new Matrix of the private Position, the private Zoom and the private Viewport size.
  11.    m_transform = CreateTransform(m_position, m_zoom, new Vector2(Viewport.Width, Viewport.Height));
  12. }
  13.  
  14. // Variant B (Working for Start > End, but not Start < End)
  15. public static void LerpTransformLinear(out Matrix matrix, Vector2 viewsize,
  16.                                        Vector2 startpos, Vector2 endpos,
  17.                                        float startzoom, float endzoom, float ammount)
  18. {
  19.    // Create Position from a lerp between the Start Position and the End Position of the given Ammount.
  20.    Vector2 position = Vector2.Lerp(startpos, endpos, ammount);
  21.    // Create Zoom from a lerp between the Start Zoom and the End Zoom of the given Ammount.
  22.    float zoom = MathHelper.Lerp(startzoom, endzoom, ammount);
  23.    
  24.    // Set given Matrix to a new Matrix of the created Position, the created Zoom and the given Viewport size.
  25.    matrix = CreateTransform(position, zoom, viewsize);
  26. }
  27.  
  28. public static Matrix CreateTransform(Vector2 position, float zoom, Vector2 size)
  29. {
  30.    // return a new Matrix of the given Position, Zoom, and Viewport Size.
  31.    return Matrix.CreateTranslation(new Vector3(-position.X, -position.Y, 0f)) *
  32.                   Matrix.CreateScale(new Vector3(zoom, zoom, 1f)) *
  33.                   Matrix.CreateTranslation(new Vector3(size.X / 2f, size.Y / 2f, 0));
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement