Hi,
In my editors I always try to keep the camera movements as smooth as possible. Now I try to get this done by interpolating the ViewMatrix. I want that my Camera should follow my mouse interactions with a small delay (don't know how to explain in english).
So finally I have an ViewMatrix (will be used for rendering) and ViewMatrixTo (the target matrix he should fade to).
My first idea was to simply interpolate each component of the matrix with a function like this:
Public Shared Sub ApproachTo(ByRef Value As Single, ByVal ValueTo As Single, ByVal Delay As Single, Optional MinDiff As Single = 0.01!)
Value = (Delay * (Value - ValueTo)) + ValueTo
If Math.Abs(ValueTo - Value) < MinDiff Then Value = ValueTo
End Sub
Public Shared Sub ApproachMatrix(ByRef MatIn As Matrix, ByVal MatrixTo As Matrix, ByVal Delay As Single)
For c As Integer = 0 To 3
For r As Integer = 0 To 3
ApproachTo(MatIn.Item(c, r), MatrixTo.Item(c, r), Delay, 0.00001)
Next
Next
End Sub
This is working, but it produces distortions because I think its a linear interpolation and the rotation/position components needs to be interpolated in a spherical way? I already found some slerp functions on quaternions and vectors but I don't really have a "factor", I only have a CurrMatrix and ToMatrix and every frame he should approach this matrix.