我做基于帧动画中的OpenGL ES 2.0如何保留在OpenGL ES的动画位置2.0
我想的矩形由在X轴200个像素并且还通过双放大到翻译300帧( 2个单位)在前100帧。 例如,矩形中心点的初始值(第0帧)在屏幕上为100像素(即rectCenterX = 100) 在第100帧时,rectCenterX = 300(100 + 200)像素。此外,矩形尺寸是原始尺寸的两倍。
然后,动画矩形必须停留在接下来的100帧(没有任何动画)。即对于帧101至200,rectCenterX = 300像素。 在第101帧,rectCenterX = 300像素。矩形尺寸是原始尺寸的两倍。 在第200帧时,rectCenterX = 300像素。矩形尺寸是原始尺寸的两倍。
然后,我想要相同的动画矩形在X轴上翻译+200像素,并在最后100帧中缩小一半(0.5单位)。 在第300帧时,rectCenterX = 500像素。矩形大小再次为原始大小。
我正在使用简单的线性插值来计算每个帧的增量动画值。
总之,
Animation-Type Animation-Value Start-Frame End-Frame
1.Translate +200 0 100
2.Scale +2 0 100
3.Translate +200 201 300
4.Scale +0.5 201 300
伪码: 的并条机下面()被用于在循环300次(300帧)来执行。
float RectMVMatrix[4][4] = {1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
}; // identity matrix
int totalframes = 300;
float translate-delta; // interpolated translation value for each frame
float scale-delta; // interpolated scale value for each frame
// The usual code for draw is:
void drawFrame(int iCurrentFrame)
{
// mySetIdentity(RectMVMatrix); // comment this line to retain the animated position.
mytranslate(RectMVMatrix, translate-delta, X_AXIS); // to translate the mv matrix in x axis by translate-delta value
myscale(RectMVMatrix, scale-delta); // to scale the mv matrix by scale-delta value
... // opengl calls
glDrawArrays(...);
eglswapbuffers(...);
}
上面的代码对前100帧可以正常工作。为了在帧101到200期间保留动画矩形,我删除了“mySetIdentity(RectMVMatrix);”在上面的drawFrame()中。
现在在进入并条机()的第二框架,所述RectMVMatrix将具有第一帧的动画值
例如RectMVMatrix [4] [4] = {1.01,0,0,2, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; // 2个像素翻译和1.01单位在第一帧后缩放 这个RectMVMatrix用于第二帧中的mytranslate()。翻译功能将影响“RectMVMatrix [0] [0]”的值。因此翻译也会影响缩放值。
最终输出出错了。
如何在不影响当前ModelView矩阵的情况下保留动画位置?