Skyz912

03-05-2011, 06:25 PM

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_viewMat rix[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.

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_viewMat rix[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.