I’m implementing a renderer that handles every translation- / view- / model- / projection-matrix (I don’t use glRotate / glTranslate etc.).
I have placed several blue objects along the positive z-axis and some red objects on the positive x-axis (So I should be able to see the red objects to my left and the blue ones straight ahead using identity rotation on my camera). It is right-hand-orientation, right?
The problem is that I have to turn 180 deg around the y-axis to see my objects. It appears as the identity rotation is looking in -z.
I’m constructing my View matrix by taking the inverse of the cameras matrix [Rot Tr] and then I put it in a array column-wise and pass it to my shader.
For the objects (World matrix) I just pass the matrix [Rot Tr] column-wise to the shader. Should I negate the translation?
The projection matrix is for now constructed in the vertex shader as I am working my way through. As you can se below I’m doing
position = proj*view*model*gl_Vertex;
At the moment I use gl_Vertex (I use glutSolidCube after loading identity matrix as my scene objects).
uniform mat4 view;
uniform mat4 model;
varying vec4 pos;
void main()
{
pos = gl_Vertex;
float aspect = 1.0;
float fovy = 1.5;
float f = 1.0 / tan(fovy * 0.5);
float near = 1.0;
float far = 100.0;
float tt = 1.0 / (near - far);
mat4 proj = mat4(f/aspect, 0.0, 0.0, 0.0,
0.0, f, 0.0, 0.0,
0.0, 0.0, (near+far)*tt, -1.0,
0.0, 0.0, 2.0*near*far*tt, 0.0);
gl_Position = proj * view * model * pos;
}
In my fragment shader I set the color = pos so that I can see the color of the axis and the colors appears correct. I think the objects are correctly placed in the scene but with Identity matrix as rotation I’m still looking the opposite way.
What could I have missed? Am I passing the correct matrices in a correct manner?
A right-handed coordinate system always looks down the -Z axis. If +X goes right, and +Y goes up (which is how all of OpenGL works), and the view is aligned to the Z axis, then +Z must go towards the viewer. If the view was looking down the +Z axis, then the space would be left-handed.