本文整理汇总了C++中Matrix3f::lerp方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix3f::lerp方法的具体用法?C++ Matrix3f::lerp怎么用?C++ Matrix3f::lerp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix3f
的用法示例。
在下文中一共展示了Matrix3f::lerp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: interpolateMatrix
//.........这里部分代码省略.........
double timeKeyOne;
double timeKeyTwo;
currentTime=(renderer->currentTime-startTime) + inPoint;
//currentTime=currentTime*100.0;
currentTime=(int)currentTime/100;
currentTime=currentTime*100;
currentTime*=timeScale;
//currentTime=startTime+1;
//currentTime++;
//move forward if we are at end of key
while (currentTime> keyFrames[currentKeyMatrix+1]->timeKey ){
currentKeyMatrix++;
if ((uint)currentKeyMatrix+1 >= keyFrames.size()){
if (bLooping){
currentKeyMatrix=0;
startTime=renderer->currentTime;
currentTime=0.0;
//cout << "looped keyframes size: " << keyFrames.size() << endl;
//return;
}else if (bMerge){
if (mergeDirection > 0.0){
mergeDirection=-1.0 * mergeDirection;
mergeFactor=1.0f;
}
currentKeyMatrix=keyFrames.size()-2;
fadeOut(keyFrames.size()-1);
return;
}else{
bFinishedMatrix=true;
return;
}
}
}
//cout << "key: " << currentKeyMatrix << " max Keys: " << (*timeKeys).size() << endl;
//if we are at the end of all keys, we're finished!
//get the two closest interpolation points
timeKeyOne=keyFrames[currentKeyMatrix]->timeKey;
timeKeyTwo=keyFrames[currentKeyMatrix+1]->timeKey;
//get the time difference
double timeDifference=timeKeyTwo-timeKeyOne;
//map time difference to 0.0 - 1.0
double keyTime=currentTime-timeKeyOne; //-> current Position, in the beginning 0.0;
float relativeTime=(float) (keyTime/timeDifference); //-> will go from 0.0 to 1.0 between the keys
SkeletalActor* skel=(SkeletalActor*)moveActor;
for (uint i=0;i<skel->bones.size();i++){
matrixOne=keyFrames[currentKeyMatrix]->boneMatrices[skel->bones[i]->name];
matrixTwo=keyFrames[currentKeyMatrix+1]->boneMatrices[skel->bones[i]->name];
//ease in - ease out
float x=relativeTime*2.0f;
float y=0.0f;
if (x< 1)
y=x*x;
else
y=2-( (x-2) * (x-2) );
y=y* 0.5;
if (bLinear)
y=relativeTime;
//interpolate between them
//resultingMatrix=matrixOne.lerp(relativeTime,matrixTwo); //calculate resulting position
rotationOne=getRotationMatrix(matrixOne);
rotationTwo=getRotationMatrix(matrixTwo);
resultingRotation=rotationOne.lerp(y,rotationTwo);
resultingMatrix=matrixOne.lerp(y,matrixTwo); //calculate resulting position
if (bMerge && mergeFactor < 1.0 && mergeFactor > 0.0){
Matrix3f sourceMatrix=getRotationMatrix(skel->bones[i]->transformMatrix);
resultingRotation = sourceMatrix.lerp(mergeFactor,resultingRotation);
}
//normalize rotations!
resultingRotation=normalizeRotations(resultingRotation);
//apply rotation
skel->bones[i]->transformMatrix.setRotation(resultingRotation);
}
}
示例2: interpolateTransform
void InterpolationHelper::interpolateTransform(){
Matrix4f transformOne, transformTwo;
Matrix4f resultingTransform;
Matrix3f rotationOne;
Matrix3f rotationTwo;
Matrix3f resultingRotation;
double timeKeyOne;
double timeKeyTwo;
currentTime=renderer->currentTime-startTime;
//move forward if we are at end of key
while (currentTime> keyFrames[currentKeyTransform+1]->timeKey ){
//if (currentTime> keyFrames[currentKey+1]->timeKey ){
currentKeyTransform++;
if (currentKeyTransform+1 >= (int)keyFrames.size()){
bFinishedTransform=true;
return;
}
}
timeKeyOne=keyFrames[currentKeyTransform]->timeKey;
timeKeyTwo=keyFrames[currentKeyTransform+1]->timeKey;
//get the time difference
double timeDifference=timeKeyTwo-timeKeyOne;
//map time difference to 0.0 - 1.0
double keyTime=currentTime-timeKeyOne; //-> current Position, in the beginning 0.0;
float relativeTime=(float) (keyTime/timeDifference); //-> will go from 0.0 to 1.0 between the keys
/*
relativeTime=relativeTime*100.0;
relativeTime=(int)relativeTime/30;
relativeTime=relativeTime*0.3;
*/
if (bAdditive){
transformOne=moveActor->transformMatrix; //
relativeTime*=relativeTime; //
}else{
transformOne=keyFrames[currentKeyTransform]->transformKey;
}
transformTwo=keyFrames[currentKeyTransform+1]->transformKey;
float x=relativeTime*2.0f;
float y=0.0f;
if (x< 1)
y=x*x;
else
y=2-( (x-2) * (x-2) );
y=y* 0.5;
if (bLinear)
y=relativeTime;
rotationOne=getRotationMatrix(transformOne);
rotationTwo=getRotationMatrix(transformTwo);
resultingRotation=rotationOne.lerp(y,rotationTwo);
//interpolate between them
resultingTransform=transformOne.lerp(y,transformTwo); //calculate resulting position
//normalize rotations!
resultingRotation=normalizeRotations(resultingRotation);
resultingTransform.setRotation(resultingRotation);
//apply resulting position
if (bRelative){
//apply rotation
moveActor->transformMatrix=baseTransform* resultingTransform;
}
else{
//apply rotation
moveActor->transformMatrix=resultingTransform;
}
}