**1**

# How to smooth animation with matrixes

###
#1
Members - Reputation: **152**

Posted 23 August 2012 - 09:34 PM

[source lang="cpp"] mat4 targetMatrix = glm::inverse( currentCamera->camTarget->getCoreTransform().getMatrix() ); //camera matrix is the camera's offset targetMatrix = currentCamera->camMatrix * targetMatrix; //get the difference between the new target matrix, and the current view matrix mat4 difMatrix = targetMatrix - viewMatrix; //only move a percentage of the total distance. //this will automatically ease out the movement difMatrix /= 4; viewMatrix += difMatrix; iGLEngine->viewMatrix->setMatrix( viewMatrix );[/source]

The problem is, when the object rotates very quickly the scene starts to warp and stretch. The amount of stretching is directly connected to the rotation speed. Anyone know why? Or, even better, another way to animate a transition from one matrix (the current view matrix) to another (the target view matrix) ?

###
#2
Members - Reputation: **1737**

Posted 24 August 2012 - 12:32 AM

You might consider splitting your camera motion into its position and rotation. If you represent your rotation as a quaternion, you may use http://en.wikipedia.org/wiki/Slerp to interpolate nicely between your cameras' quaternions. After interpolation of rotation and translation you construct a new combined matrix by converting the quaternion to a rotation matrix and multiplying it with your translation matrix (be advised though, that there are some nice tricks to speed up multiplying a (pure) rotation matrix with a (pure) translation matrix).

Hope that helps.

**Edited by rnlf, 24 August 2012 - 03:02 AM.**

###
#3
Members - Reputation: **1737**

Posted 24 August 2012 - 03:08 AM

###
#4
Members - Reputation: **152**

Posted 24 August 2012 - 04:12 AM

By the way, your simple approach to smoothing out the camera by just going fixed quarter-of-the-total-distance steps is depending on your framerate.

True. The updateViewMatrix function (that contains the above code) takes in a frameTime variable, but I had yet to integrate it here, since the current code still needs fixed. Definitely good advice