Beispiel #1
0
void CCSetViewMatrix()
{
    CCMatrix &modelViewMatrix = CCCameraBase::currentCamera->pushedMatrix[CCCameraBase::currentCamera->currentPush];
    static CCMatrix modelViewProjectionMatrix;
    modelViewProjectionMatrix = modelViewMatrix;
    if( gUseProjectionMatrix )
    {
        CCMatrixMultiply( modelViewProjectionMatrix, modelViewMatrix, CCCameraBase::currentCamera->getProjectionMatrix() );
    }
    
    const GLint *uniforms = gEngine->renderer->getShader()->uniforms;
    GLUniformMatrix4fv( uniforms[UNIFORM_MODELVIEWPROJECTIONMATRIX], 1, GL_FALSE, modelViewProjectionMatrix.m );
    
    if( uniforms[UNIFORM_MODELVIEWMATRIX] != -1 )
    {
        GLUniformMatrix4fv( uniforms[UNIFORM_MODELVIEWMATRIX], 1, GL_FALSE, modelViewMatrix.m );
    }
    
    if( uniforms[UNIFORM_MODELNORMALMATRIX] != -1 )
    {
        static CCMatrix inverseModelViewMatrix;
        static CCMatrix modelNormalMatrix;
        CCMatrixInverse( inverseModelViewMatrix, modelViewMatrix );
        CCMatrixTranspose( modelNormalMatrix, inverseModelViewMatrix );
        GLUniformMatrix4fv( uniforms[UNIFORM_MODELNORMALMATRIX], 1, GL_FALSE, modelNormalMatrix.m );
    }
}
Beispiel #2
0
void CCSetModelViewProjectionMatrix()
{
	const CCMatrix &viewMatrix = CCCameraBase::CurrentCamera->getViewMatrix();
    const CCMatrix &modelMatrix = CCCameraBase::CurrentCamera->pushedMatrix[CCCameraBase::CurrentCamera->currentPush];
    if( gRenderer->openGL2() )
    {
        const CCMatrix &projectionMatrix = CCCameraBase::CurrentCamera->getProjectionMatrix();

        const GLint *uniforms = gRenderer->getShader()->uniforms;
        gRenderer->GLUniformMatrix4fv( uniforms[UNIFORM_PROJECTIONMATRIX], 1, GL_FALSE, projectionMatrix.m );
        gRenderer->GLUniformMatrix4fv( uniforms[UNIFORM_VIEWMATRIX], 1, GL_FALSE, viewMatrix.m );
        gRenderer->GLUniformMatrix4fv( uniforms[UNIFORM_MODELMATRIX], 1, GL_FALSE, modelMatrix.m );

        if( uniforms[UNIFORM_MODELNORMALMATRIX] != -1 )
        {
            static CCMatrix modelViewMatrix;
            modelViewMatrix = viewMatrix;
            CCMatrixMultiply( modelViewMatrix, modelMatrix, modelViewMatrix );

            static CCMatrix inverseModelViewMatrix;
            static CCMatrix modelNormalMatrix;
            CCMatrixInverse( inverseModelViewMatrix, modelViewMatrix );
            CCMatrixTranspose( modelNormalMatrix, inverseModelViewMatrix );
            gRenderer->GLUniformMatrix4fv( uniforms[UNIFORM_MODELNORMALMATRIX], 1, GL_FALSE, modelNormalMatrix.m );
        }
    }
    else
    {
#ifdef IOS
        static CCMatrix modelViewMatrix;
		modelViewMatrix = viewMatrix;
		CCMatrixMultiply( modelViewMatrix, modelMatrix, modelViewMatrix );
        glLoadMatrixf( modelViewMatrix.data() );
#endif
    }
}