Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Matrix translation

Started by jad_salloum Jan 17, 2007 at 7:54 AM 2 replies 600+ views
Original Post
jad_salloum
jad_salloum
hi guys, i have 2 different matrixes i need to move between them by a scalar which changes between 0 --> 1 . how could this be done ?? in vectors it is done like this : vecOut = Vector3.Subtract( vector2,vector1 ) * Scalar + vector1 what could it be for matrixs ?? thanks
Zakwayda
Zakwayda
Quote:
Original post by jad_salloum
vecOut = Vector3.Subtract( vector2,vector1 ) * Scalar + vector1
You can do the same with matrices (the term is 'linear interpolation', or 'lerp'). However, depending on what the matrices represent, the results may or may not be meaningful.

What is the interpolation for?
jad_salloum
jad_salloum
Quote:
Original post by jyk
What is the interpolation for?


i have multiple animations for a character so to move from 1 to another i have to make blending between the bones matrixes ( current bone matrix and desired bone matrix )
is this the correct way to do that ?
Milkshake
Milkshake
For small enough rotations, it is possible to interpolate the rotation part of the matrix ... but it's a hack, and you'll have to renormalise the rotation elements after doing it, which will break horrifically if you have any scaling. The problem with this is that linear interpolation won't preserve the magnitude of the source and target vectors when interpolating between them - as the name suggests, it's a strictly linear interpolation.

What most skeletal animation systems use is a vector for position, and a quaternion for the orientation. They then interpolate the vector exactly as you demonstrated in the original posting, and SLERP (spherical linear interpolation) the quaternions to give a nice smooth intermediate result for rotation. The "spherical" part of the interpolation interpolates around the unit sphere preserving the normalisation on your rotation vector. The quaternion is then converted into the matrix rotation coefficients.

There's gobs of source code out there for matrix <-> quaternion conversion, and also for SLERPing quaterions.

Good luck!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.