0
votes

I'm trying to mathematically follow the coordinates of my ModelView matrix (and some other matrices) in my program after I've applied various transformations. I'd like to get the program to output these coordinates, but I can't quite get there.

modelViewMatrix = GLKMatrix4MakeTranslation(-1.5f, 1.25f, -4.0f);
modelViewMatrix = GLKMatrix4Scale(modelViewMatrix, 2.75, 2, 0);

GLfloat MVMatrix[16];    
if (not_printed) {
    glGetFloatv(GL_MODELVIEW_MATRIX, MVMatrix);
    for (int i=0; i<16; i++) {
        printf("%f ", MVMatrix[i]);
    }
}
not_printed = 0;

The output from this is simply a sequence of 16 0.0 values (e.g. 0.0, 0.0, ..., 0.0).

How do I get the values of my matrix to output to the console? Thanks!

1

1 Answers

1
votes

First of all, GLK is unrelated to the OpenGL matrix stack, it creates its own matrix rather than multiplying OpenGL's "current" matrix.

The other thing that I find particularly strange here is that GL_MODELVIEW_MATRIX is even defined in an OpenGL ES 2.0 context, this is non-standard behavior. OpenGL ES 2.0 does not have current color, current matrix, etc... it stripped that stuff away when it mandated exclusive use of the programmable pipeline.

What you want to do, instead, is this:

modelViewMatrix = GLKMatrix4MakeTranslation(-1.5f, 1.25f, -4.0f);
modelViewMatrix = GLKMatrix4Scale(modelViewMatrix, 2.75, 2, 0);

if (not_printed) {
    for (int i=0; i<16; i++) {
        printf("%f ", modelViewMatrix.m [i]);
    }
    printf ("\n");
}
not_printed = 0;