Quantcast
Channel: Adobe Community : Popular Discussions - After Effects SDK
Viewing all articles
Browse latest Browse all 73444

Help with AE camera matrix >> Opengl Matrix?

$
0
0

I've been toying with the SDK for a few weeks now, I'm finally getting somewhere, but I've gotten to a point that I can't figure out. I'm trying to use the After Effects camera data to move around in my opengl scene. Here is the code I have

 

First I get the Camera Matrix.

 

 

-------------

//Variables...
    A_Matrix4            camMatrix;
   
    GLfloat                glMatrix[4][4];

    GLfloat                glMatInverted[16];

 

    GLfloat                glMatrix2[16];

 

 

...
    A_FpLong planeDist;


     ERR(suites.PFInterfaceSuite1()->AEGP_ConvertEffectToCompTime(in_data- >effect_ref,
                                                                     in_data->current_time,
                                                                     in_data->time_scale,
                                                                     &comp_timeT));
       
     ERR(suites.PFInterfaceSuite1()->AEGP_GetEffectCamera(in_data->effect_ ref,
                                                             &comp_timeT,
                                                             &camera_layerH));


    ERR(suites.CameraSuite2()->AEGP_GetDefaultCameraDistanceToImagePlane (compH, &planeDist));
   
    ERR(suites.PFInterfaceSuite1()->AEGP_GetEffectCameraMatrix( in_data->effect_ref,
                                                                &comp_timeT,
                                                                &matrix,
                                                                &planeDist,
                                                               (A_short*)in_data->width,
                                                               (A_short*)in_data->height));

 

 

.. Here's where it's most likely going wrong.. ..

 

            // AE Matrix
            /*
            
             0   1  2  3
             4   5  6  7
             8   9 10 11
             12 13 14 15
            
             OGL Matrix
            
             0    4    8    12
             1    5    9    13
             2    6    10    14
             3    7    11    15
             */

 

// First I convert to the opengl matrix format

 

            for (x = 0; x < 4; x++)
            {
                glMatrix[x][0] = matrix.mat[0][x];
                glMatrix[x][1] = matrix.mat[1][x];
                glMatrix[x][2] = matrix.mat[2][x];
                glMatrix[x][3] = matrix.mat[3][x];   
            }

//  Then I convert the matrix into a 1-d array of floats

                   
            int count=0;
            for (x = 0; x < 4; x++) // rows
            {
                glMatrix2[count]     = glMatrix[0][x];
                glMatrix2[count++] = glMatrix[1][x];
                glMatrix2[count++] = glMatrix[2][x];
                glMatrix2[count++] = glMatrix[3][x];   
               
                count++;  
            }

 

-------------

// I then invert the matrix using a function I borrowed from Mesa3d, it is at the bottom of this post for reference.

 

gluInvertMatrix ( glMatrix2, glMatInverted );

 

-------------

 

 

-------------

And then down in my drawing routine, when setting up my GL scene, I use the following

-------------


            //set the matrix modes
            glMatrixMode( GL_PROJECTION );
            glLoadIdentity();
           
            gluPerspective( 45.0, (GLdouble)widthL / heightL, 0.1, 100.0 );
           
            // Set up the frame-buffer object just like a window.
            glViewport( 0, 0, widthL, heightL );
            glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
           
            //spin using slider [TODO] as slider control
            glMatrixMode( GL_MODELVIEW );
            glLoadIdentity();
           
            glLoadMatrixf( glMatInverted ); // <---- I am loading in the matrix that I created from the ae camera here.

 

 

-------------

 

When I don't include the LoadMatrix call, everything is visible, but when I do, I see nothing, so my assumption is I am way off in my calculations somewhere, I'm hoping someone familiar with this can spot my obvious error.

 

I am debugging this and logging my matrix before and after conversion, and it is definately working, I don't *think* i'm losing data anywhere... Any help is greatly appreciated.

 

-Chris

 

 

 

 

 

 

 

-------------

 

 

bool gluInvertMatrix(GLfloat m[16], GLfloat invOut[16])
{
    GLfloat inv[16], det;
    int i;
   
    inv[0] =   m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15]
    + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10];
    inv[4] =  -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15]
    - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10];
    inv[8] =   m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15]
    + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9];
    inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14]
    - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9];
    inv[1] =  -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15]
    - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10];
    inv[5] =   m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15]
    + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10];
    inv[9] =  -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15]
    - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9];
    inv[13] =  m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14]
    + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9];
    inv[2] =   m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15]
    + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6];
    inv[6] =  -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15]
    - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6];
    inv[10] =  m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15]
    + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5];
    inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14]
    - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5];
    inv[3] =  -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11]
    - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6];
    inv[7] =   m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11]
    + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6];
    inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11]
    - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5];
    inv[15] =  m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10]
    + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5];
   
    det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12];
    if (det == 0)
        return false;
   
    det = 1.0 / det;
   
    for (i = 0; i < 16; i++)
        invOut[i] = inv[i] * det;
   
    return true;
}


Viewing all articles
Browse latest Browse all 73444

Trending Articles