Skip to main content
Markdown formatting of separators
Source Link
 

=========================================== II got the solution... Thanks to Sergio.

 

======================================== II maintained this 'RectMVMatrix'"RectMVMatrix" value, if there is no animation for the current frame (e.g. 101th frame onwards).

Thanks, Arun AC

=========================================== I got the solution... Thanks to Sergio.

======================================== I maintained this 'RectMVMatrix' value, if there is no animation for the current frame (e.g. 101th frame onwards).

Thanks, Arun AC

 

I got the solution... Thanks to Sergio.

 

I maintained this "RectMVMatrix" value, if there is no animation for the current frame (e.g. 101th frame onwards).

update with answer.
Source Link
Arun AC
  • 125
  • 5

=========================================== 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

=========================================== 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

code
Source Link
Arun AC
  • 125
  • 5
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(...);
}
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(...);
}
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(...);
}
Source Link
Arun AC
  • 125
  • 5
Loading