/// <summary> /// The camera is updated once per frame automatically by the renderer. /// </summary> public override void Update() { // Check if no target. if (Target == null) { return; } // Check if target last position is set. It isn't on the first frame. if (_targetLastPosition == Vector2.Zero) { _targetLastPosition = Target.Center; } // Get mouse location. Vector2 mouseLocation = ScreenToWorld(Engine.InputManager.GetMousePosition()); // Smooth between the mouse location and the target. float lx = MathExtension.Lerp(Target.Center.X, mouseLocation.X, MathExtension.Clamp(Speed * Engine.FrameTime, 0, CameraMaxDistance)); float ly = MathExtension.Lerp(Target.Center.Y, mouseLocation.Y, MathExtension.Clamp(Speed * Engine.FrameTime, 0, CameraMaxDistance)); Center = new Vector2(lx, ly); // Record position. _targetLastPosition = Target.Center; }
/// <summary> /// Performs linear interpolation of <see cref="Color" />. /// </summary> /// <param name="value1">Source <see cref="Color" />.</param> /// <param name="value2">Destination <see cref="Color" />.</param> /// <param name="amount">Interpolation factor.</param> /// <returns>Interpolated <see cref="Color" />.</returns> public static Color Lerp(Color value1, Color value2, float amount) { amount = MathExtension.Clamp(amount, 0, 1); return(new Color( (byte)MathExtension.Lerp(value1.R, value2.R, amount), (byte)MathExtension.Lerp(value1.G, value2.G, amount), (byte)MathExtension.Lerp(value1.B, value2.B, amount), (byte)MathExtension.Lerp(value1.A, value2.A, amount))); }
public override short Interpolate(short a, short b, float t) { return(MathExtension.Lerp(a, b, t)); }
public override int Interpolate(int a, int b, float t) { return(MathExtension.Lerp(a, b, t)); }
public override long Interpolate(long a, long b, float t) { return(MathExtension.Lerp(a, b, t)); }