Greetings,
It’s me, with my camera again!
I’m currently trying to write a simple Method to give my camera some move and zoom animation. I just give it a target Position, a target Zoom value and the speed that I want for the animation.
public void AnimateTransformTo(Vector2 position, float zoom, float speed, bool linear = true)
Then My Camera does the Job by updating the Transform each frame until Position and Zoom are reached. I do this by simply doing Vector2.Lerp with the Position and MathHelpler.Lerp() with the Zoom. After that I update the Transform of my Camera.
protected virtual void LerpTransformLinear(Vector2 startpos, Vector2 endpos,
float startzoom, float endzoom, float ammount)
This is the local definition of the Method I wrote to Lerp my Transform. And it is working fine.
However I somehow think it would be nice to have this method not only public but also static.
public static void TransformLinear(out Matrix matrix, Vector2 viewsize,
Vector2 startpos, Vector2 endpos, float startzoom, float endzoom,
float ammount)
But this one, for some reason, is only working correctly in one direction.
I signed the Method to start my animation with two clickable objects in my game. One of them zooming in and focusing other objects in the game. And the other returns to the initial position and zoom.
Now with the local Method I get a smooth animated zoom in, when clicking the first button. And when I click the second button I get a smooth animated zoom out.
But If I do this with the static Method I can only zoom in smooth. When I want to zoom out, I instantly get to the end of the animation. Wich basicly means that I don’t have a animation.
Funny thing: I’ve added Events to the camera to keep track of the camera’s status. I get a message when the animation starts and another one when the animation ends. The local approach comletes the zoom out in the same time in wich the static approach. So visually the animation doesn’t really happen, but technically it does? The Events are telling me so atleast.
As it is, I probably don’t really need the static approach. But anyway, I really would like to know why this thing I wrote is not working. So I would be happy if you can tell me what any of you thinks about this.
Code of the two Methods:
https://pastebin.com/26TfCPXg
Code of Update() and AnimateTransformTo():
https://pastebin.com/KTiSBSEA