I am building a minimal opengl viewer and I am puzzled by what I see : the camera see the (test) object that is behind her. the front and back of the camera looks reverted. I am wondering what could cause this kind of behavior.
I think this is a matrix issue but I don't see what's wrong.
(this is in the classic opengl coordinate space, -z going into the screen)
The test object is in
(0,0,0), The camera is located at
(0,0,10) and lookat
(0,0,0) ; its up is
(0,1,0). I use a lookAt functions to compute the camera world coordinates, matrix, inverse it and pass it to a shader. There I do a simple
gl_Position = proj * view * vec4(position, 1.0) ;
the near and far plane are at 1.0 and 1000.0 respectively. (Changing them doesn't seems to affect the result described below)
At start, I don't see anything but If I move away from the object, I finally see it.
I see the object when my camera is located at
(-0.020208, 0.0302687, 1.62084), looking at
(-0.0126727, 0.0227334, 5.93824) which means it's looking away from the object...(The up vector staying the same.)
As I said, this is likely a matrix issue but I have checked quite extensively the chaining, and I don't see what could cause this. So any idea is welcome.
The near and far plane are at 1.0 and 1000.0 respectively. (Changing them doesn't seems to affect the result described below)
The matrix are created via pyrr and cgkit (python libraries). the starting matrixes are :
In : proj = pyrr.matrix44.create_perspective_projection_matrix(30.0, 8/6.0, 1.0, 100.0) Out: array([[ 2.79903811, 0. , 0. , 0. ], [ 0. , 3.73205081, 0. , 0. ], [ 0. , 0. , -1.02020202, -1. ], [ 0. , 0. , -2.02020202, 0. ]]) In : vm = mat4.lookAt(pos, target, up).inverse() In : vm Out: [-1, -0, 0, -0] [-0, 1, -0, 0] [0, -0, -1, 10] [-0, 0, -0, 1]