===========================================
I got the solution... Thanks to Sergio.
I created separate matrices for translation and scaling. e.g.CurrentTranslateMatrix[4][4], CurrentScaleMatrix[4][4].
Then for every frame,
I reset 'CurrentTranslateMatrix' to identity and call mytranslate( CurrentTranslateMatrix, translate-delta, X_AXIS) function.
I reset 'CurrentScaleMatrix' to identity and call myscale(CurrentScaleMatrix, scale-delta) function.
Then, I multiplied these 'CurrentTranslateMatrix' and 'CurrentScaleMatrix' to get the final 'RectMVMatrix' Matrix for the frame.
Pseudo Code:
float RectMVMatrix[4][4] = {0};
float CurrentTranslateMatrix[4][4] = {0};
float CurrentScaleMatrix[4][4] = {0};
int iTotalFrames = 300;
int iAnimationFrames = 100;
int iTranslate_X = 200.0f; // in pixels
float fScale_X = 2.0f;
float scaleDelta;
float translateDelta_X;
void DrawRect(int iTotalFrames)
{
mySetIdentity(RectMVMatrix);
for (int i = 0; i< iTotalFrames; i++)
{
DrawFrame(int iCurrentFrame);
}
}
void getInterpolatedValue(int iStartFrame, int iEndFrame, int iTotalFrame, int iCurrentFrame, float *scaleDelta, float *translateDelta_X)
{
float fDelta = float ( (iCurrentFrame - iStartFrame) / (iEndFrame - iStartFrame))
float fStartX = 0.0f;
float fEndX = ConvertPixelsToOpenGLUnit(iTranslate_X);
*translateDelta_X = fStartX + fDelta * (fEndX - fStartX);
float fStartScaleX = 1.0f;
float fEndScaleX = fScale_X;
*scaleDelta = fStartScaleX + fDelta * (fEndScaleX - fStartScaleX);
}
void DrawFrame(int iCurrentFrame)
{
getInterpolatedValue(0, iAnimationFrames, iTotalFrames, iCurrentFrame, &scaleDelta, &translateDelta_X)
mySetIdentity(CurrentTranslateMatrix);
myTranslate(RectMVMatrix, translateDelta_X, X_AXIS); // to translate the mv matrix in x axis by translate-delta value
mySetIdentity(CurrentScaleMatrix);
myScale(RectMVMatrix, scaleDelta); // to scale the mv matrix by scale-delta value
myMultiplyMatrix(RectMVMatrix, CurrentTranslateMatrix, CurrentScaleMatrix);// RectMVMatrix = CurrentTranslateMatrix*CurrentScaleMatrix;
... // opengl calls
glDrawArrays(...);
eglswapbuffers(...);
}
========================================
I maintained this 'RectMVMatrix' value, if there is no animation for the current frame (e.g. 101th frame onwards).
Thanks,
Arun AC