|
|
发表于 2005-3-3 20:37:00
|
显示全部楼层
Re:怎么让骨骼运动更平滑?
基本上Max导出的Node的Transform Matrix可以用max sdk的decomp_affine(...)分拆成若干个部分,然后再对这些部分分别插值后,再合并成一个matrix,这样可以实现transform matrix的平滑过渡.如果Transform里不包括那种off axis scaling的话(可能就是楼上说的不在原点的rotate/scale吧),可以用Max的DecomposeMatrix(...)或者D3DX的D3DXMatrixDecompose(...)来拆矩阵.
一般可以要求美术提供没有复杂的Transform的动画(就是只包括Rotate,Scale,Translate),不过通用起见,我觉得还是用decomp_affine(...)比较合适,当然会有点慢.
以下引自max sdk的帮助,介绍decomp_affine(...)这个函数的:
Description:
This structure and the associated functions provide a way to decompose an arbitrary Matrix3 into its translation, rotation, and scale components.
To use these APIs put the following statement in your source file:
#include "decomp.h"
For a full discussion of this decomposition see Graphics Gems IV - Polar Matrix Decomposition by Ken Shoemake. ISBN 0-12-336155-9.
T F R U K U'
T - translation matrix
F - either an identity matrix or negative identity matrix
R - rotation defined by Quat q.
U - rotates you into the coordinates system where the scaling or stretching is done
K - scaling matrix
U' - inverse of u.
Structure:
typedef struct {
Point3 t;
The translation components.
Quat q;
The essential rotation.
Quat u;
The stretch rotation. This is the axis system of the scaling application.
Point3 k;
The stretch factors. These are the scale factors for x, y and z.
float f;
Sign of the determinant.
} AffineParts;
Functions:
Prototype:
void decomp_affine(Matrix3 A, AffineParts *parts);
Remarks:
This will decompose a matrix into the translation, rotation and scale components and store the results in the AffineParts structure passed. This will return correct results for off axis scale. This is a fairly computationally intensive iterative solution operation.
Parameters:
Matrix3 A
The input matrix to decompose.
AffineParts *parts
The result. See above.
Sample Code:
Note: If you want to rebuild a Matrix3 from the decomposed parts you get back from decomp_affine()the important thing is the order the parts are combined.
Consider the following matrices constructed from the various affine parts:
ptm = position component (t)
rtm = "essential" rotation (q)
srtm = "stretch" rotation (u)
stm = scale component (k)
ftm = the flip tm -> ScaleMatrix(Point3(ap.f,ap.f,ap.f));
Here's the correct way of reassembling the decomposed matrix:
Matrix3 srtm, rtm, ptm, stm, ftm;
ptm.IdentityMatrix();
ptm.SetTrans(ap.t);
ap.q.MakeMatrix(rtm);
ap.u.MakeMatrix(srtm);
stm = ScaleMatrix(ap.k);
mat = Inverse(srtm) * stm * srtm * rtm * ftm * ptm;
|
|