how to retain the animated position in opengl es 2.0 <p>I am doing frame based animation for 300 frames in opengl es 2.0</p> <p>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. For example, the initial value (frame 0) of the rectangle's centre point is at 100 pixels (i.e. rectCenterX = 100) on the screen; At 100th frame, rectCenterX = 300 (100 + 200) pixels. Also the rect size is doubled the original size.</p> <p>Then, the animated rectangle has to stay there for the next 100 frames (without any animation). i.e. the rectCenterX = 300 pixels for frames 101 to 200. At 101st frame, rectCenterX = 300 pixels. the rect size is double the original size. At 200th frame, rectCenterX = 300 pixels. the rect size is double the original size.</p> <p>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. At 300th frame, rectCenterX = 500 pixels.the rect size is again as the original size.</p> <p>I am using simple linear interpolation to calculate the delta-animation value for each frame.</p> <p>In short,</p> <pre><code>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 </code></pre> <p>Pseudo code: The below drawFrame() is executed for 300 times (300 frames) in a loop.</p> <pre><code>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(...); } </code></pre> <p>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().</p> <p>Now on entering the drawFrame() for the 2nd frame, the RectMVMatrix will have the animated value of first frame</p> <p>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.</p> <p>Eventually output is getting wrong.</p> <p>How to retain the animated position without affecting the current ModelView matrix?</p>