I am doing frame based animation for 300 frames in opengl es 2.0
I want a rectangle to translate by +200 pixels in X axis and also scaled up by double (2 units) in the first 100 frames
Then, the animated rectangle has to stay there for the next 100 frames.
Then, I want the same animated rectangle to translate by +200 pixels in X axis and also scaled down by half (0.5 units) in the last 100 frames.
I am using simple linear interpolation to calculate the delta-animation value for each frame.
Pseudo code:
The below drawFrame() is executed for 300 times (300 frames) in a loop.
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(...);
}
The above code will work fine for first 100 frames. in order to retain the animated rectangle during the frames 101 to 200, i removed the "mySetIdentity(RectMVMatrix);" in the above drawFrame().
Now on entering the drawFrame() for the 2nd frame, the RectMVMatrix will have the animated value of first frame
e.g. RectMVMatrix[4][4] = { 1.01, 0, 0, 2,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};// 2 pixels translation and 1.01 units scaling after first frame
This RectMVMatrix is used for mytranslate() in 2nd frame. The translate function will affect the value of "RectMVMatrix[0][0]". Thus translation affects the scaling values also.
Eventually output is getting wrong.
How to retain the animated position without affecting the current ModelView matrix?