"Fade" - interpolation of a ViewMatrix

Started by
2 comments, last by haegarr 8 years, 9 months ago

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.

Advertisement

The factor is in fact the time that elapses between the start and end of the camera movement, probably fit by a kind of adaptation curve to give a smooth starting and finishing.

The view matrix consists of a rotational and a translational part, the former perhaps layered by a scaling. The rotational part need to fulfill 6 conditions (as matrix they are 9 numbers for 3 degrees of freedom, so need to have 6 constraints): each column/row vector must be of unit length, and they must be pairwise orthogonal. If this isn't true, then the observed distortions appear. Your simple linear interpolation does not preserve the constraints, because it interpolates each element in isolation.

The matrices can be interpolated (see e.g. the belonging paper von Dave Eberly on it geometrictools.com website), but for now it seems me too difficult stuff from a mathematical point of view. My suggestion is to interpolate positions and orientations separately. Do you have the particular parts separate, or do you need to decompose the matrix first? Do you need to consider scaling for the view matrix?

BTW, you probably want to interpolate the view matrix here, not the model-view matrix.

Yes I have the Position (vec) and Rotation (quaternion) available but its also not easy to "fade" them synchronous. I think what I want is called WeightedAverage Interpolation:

http://sol.gfxile.net/interpolation/

or here

http://www.gizma.com/easing/

Of course breaking this down on a easy-to-use "ApprochMatrix" function would be ideal, because this can be used also for other cool stuff.

Easing is a way to adapt the interpolation factor to a wanted velocity profile. It is not exactly the interpolation itself.

If you have the positions given as start and as target position vectors, then apply a lerp interpolation. The progress of the interpolation goes from 0 to 1 within the time interval you choose. The progress value is then fed into the adaption curve (e.g. an ease-in-out curve or whatever) and the resulting output is used as interpolation factor of a lerp function. Similarly, if you have the orientations given as start and target quaternions, then apply either a slerp ("spherical lerp") or perhaps a nlerp ("normalized lerp") for interpolation. Use the same progress value as above, but you can adapt it by another curve if you want. Then convert the resulting quaternion into a rotation matrix and concatenate it with the translation matrix from the interpolated position.

This topic is closed to new replies.

Advertisement