📄 mgcxforminterp.cpp
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement. The various license agreements may be found at
// the Magic Software web site. This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf
#include "MgcXFormInterp.h"
//----------------------------------------------------------------------------
void MgcXFormInterp (const MgcMatrix3& rkM0, const MgcVector3& rkT0,
const MgcMatrix3& rkM1, const MgcVector3& rkT1, MgcReal fTime,
MgcMatrix3& rkM, MgcVector3& rkT)
{
if ( fTime <= 0.0 )
{
rkM = rkM0;
rkT = rkT0;
return;
}
if ( fTime >= 1.0 )
{
rkM = rkM1;
rkT = rkT1;
return;
}
// factor M0 = L0*S0*R0
MgcMatrix3 kL0, kR0;
MgcVector3 kS0;
rkM0.SingularValueDecomposition(kL0,kS0,kR0);
// compute quaternions for L0 and R0
MgcQuaternion kQL0, kQR0;
kQL0.FromRotationMatrix(kL0);
kQR0.FromRotationMatrix(kR0);
// factor M1 = L1*S1*R1
MgcMatrix3 kL1, kR1;
MgcVector3 kS1;
rkM1.SingularValueDecomposition(kL1,kS1,kR1);
// compute quaternions for L1 and R1
MgcQuaternion kQL1, kQR1;
kQL1.FromRotationMatrix(kL1);
kQR1.FromRotationMatrix(kR1);
// compute M = L*S*R
MgcMatrix3 kL, kR;
MgcVector3 kS;
// spherical linear interpolation of quaternions for L and R
MgcQuaternion kQL = MgcQuaternion::Slerp(fTime,kQL0,kQL1);
MgcQuaternion kQR = MgcQuaternion::Slerp(fTime,kQR0,kQR1);
kQL.ToRotationMatrix(kL);
kQR.ToRotationMatrix(kR);
// generalized geometric means, S = S0^{1-t}*S1^t
MgcReal fOMTime = 1.0 - fTime;
kS[0] = MgcMath::Pow(MgcMath::Abs(kS0[0]),fOMTime) *
MgcMath::Pow(MgcMath::Abs(kS1[0]),fTime);
kS[1] = MgcMath::Pow(MgcMath::Abs(kS0[1]),fOMTime) *
MgcMath::Pow(MgcMath::Abs(kS1[1]),fTime);
kS[2] = MgcMath::Pow(MgcMath::Abs(kS0[2]),fOMTime) *
MgcMath::Pow(MgcMath::Abs(kS1[2]),fTime);
// compute the product M = L*S*R
rkM.SingularValueComposition(kL,kS,kR);
// linearly interpolate T = (1-t)*T0+t*T1
rkT = fOMTime*rkT0 + fTime*rkT1;
}
//----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -