some problems with an OpenGL camera system

Hello,

I am having some issues with an OpenGL camera system that I found.

The problem I am experiencing is that, I cannot figure out how to make the Zaxis up/down. I was told normally in opengl, Yaxis is up/down. I suspect that it has to do with the viewMatrix in the lookAt function::

public void lookAt(Vector3 eye, Vector3 target, Vector3 up)
{
m_eye = eye;
m_target = target;

        m_zAxis = eye - target;
        m_zAxis.Normalize();

        m_viewDir = -m_zAxis;

        m_xAxis = up.CrossProduct(m_zAxis);
        m_xAxis.Normalize();

        m_yAxis = m_zAxis.CrossProduct(m_xAxis);
        m_yAxis.Normalize();

        m_viewMatrix[0, 0] = m_xAxis.x;
        m_viewMatrix[1, 0] = m_xAxis.y;
        m_viewMatrix[2, 0] = m_xAxis.z;
        m_viewMatrix[3, 0] = -m_xAxis.DotProduct(eye);

        m_viewMatrix[0, 1] = m_yAxis.x;
        m_viewMatrix[1, 1] = m_yAxis.y;
        m_viewMatrix[2, 1] = m_yAxis.z;
        m_viewMatrix[3, 1] = -m_yAxis.DotProduct(eye);

        m_viewMatrix[0, 2] = m_zAxis.x;
        m_viewMatrix[1, 2] = m_zAxis.y;
        m_viewMatrix[2, 2] = m_zAxis.z;
        m_viewMatrix[3, 2] = -m_zAxis.DotProduct(eye);

        // Extract the pitch angle from the view matrix.
        m_accumPitchDegrees = VCMath.radiansToDegrees((float)Math.Asin(m_viewMatrix[1, 2]));

        m_orientation.fromMatrix(m_viewMatrix);
        updateViewMatrix();
    }

My reasoning for this is: If you look down at something flat, X= left/right, Y = forward/backward and Z = up/down. I would like to keep this orientation when I setup my 3d view.

I got the pitch angles correct by using m_viewMatrix[1, 1] instead of [1, 2], but I am having trouble figuring out the rest.

The problem I am experiencing is that, I cannot figure out how to make the Zaxis up/down. I was told normally in opengl, Yaxis is up/down. I suspect that it has to do with the viewMatrix in the lookAt function::

I’m not sure I understand what the problem is exactly. If you want the y-axis to be vertical, then pass the y-axis as the up vector to the ‘lookAt’ function.

the problem is that it seems to be stuck in “y-axis is up” mode no matter what I pass as up; (1,0,0), (0,1,0) or (0,0,1). I am calling the function like this :

glc.Cam.lookAt(new Vector3(0, -256, 256), new Vector3(0, 0, 0), new Vector3(0, 0, 1));

(0,1,0) & (0,0,1) seem to have the same effect.

I suspect that the lookAt() function is flawed in some way, but I cannot figure out where or how to fix it.

Anyone know what is going on?

At first glance, lookAt function doesn’t look good. Z vector is the opposite direction that it’s normally is but is crossed with the up vector with good direction.

It also looks like the last line of the matrix is missing.

Really hard to say more like this. Couldn’t you try gluLookAt or implement your own lookAt function ?

I think I should mention that this is for a game level editor so there are 4 viewports per document. One 3d view and three ortho views are present (default layout).

hmm… I tried gluLookAt, but it did nothing – Probably because there are multiple GL viewports.

What do you mean:
“It also looks like the last line of the matrix is missing.”

I mean there should have 4 lines in a 4*4 matrix. But maybe it has already been set to identity matrix before ?

UPDATE::
A friend hinted at me that it might be the way the camera rotates, so I checked into that. I found out it was rotating the world around the Y axis. I changed that to Z axis and now the camera works perfect.
I don’t know why I didn’t see that, but I do now.

Thanks for your time anyway!