Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Variant A (Working for Start > End and Start < End)
- protected virtual void LerpTransformLinear(Vector2 startpos, Vector2 endpos,
- float startzoom, float endzoom, float ammount)
- {
- // set private Position field to lerp between the Start Position and the End Position of the given Ammount.
- m_position = Vector2.Lerp(startpos, endpos, ammount);
- // set private Zoom field to lerp between the Start Zoom and the End Zoom of the given Ammount.
- m_zoom = MathHelper.Lerp(startzoom, endzoom, ammount);
- // Set private Matrix field to a new Matrix of the private Position, the private Zoom and the private Viewport size.
- m_transform = CreateTransform(m_position, m_zoom, new Vector2(Viewport.Width, Viewport.Height));
- }
- // Variant B (Working for Start > End, but not Start < End)
- public static void LerpTransformLinear(out Matrix matrix, Vector2 viewsize,
- Vector2 startpos, Vector2 endpos,
- float startzoom, float endzoom, float ammount)
- {
- // Create Position from a lerp between the Start Position and the End Position of the given Ammount.
- Vector2 position = Vector2.Lerp(startpos, endpos, ammount);
- // Create Zoom from a lerp between the Start Zoom and the End Zoom of the given Ammount.
- float zoom = MathHelper.Lerp(startzoom, endzoom, ammount);
- // Set given Matrix to a new Matrix of the created Position, the created Zoom and the given Viewport size.
- matrix = CreateTransform(position, zoom, viewsize);
- }
- public static Matrix CreateTransform(Vector2 position, float zoom, Vector2 size)
- {
- // return a new Matrix of the given Position, Zoom, and Viewport Size.
- return Matrix.CreateTranslation(new Vector3(-position.X, -position.Y, 0f)) *
- Matrix.CreateScale(new Vector3(zoom, zoom, 1f)) *
- Matrix.CreateTranslation(new Vector3(size.X / 2f, size.Y / 2f, 0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement