Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

update :

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 [44]: proj = pyrr.matrix44.create_perspective_projection_matrix(30.0, 8/6.0, 1.0, 100.0)
Out[44]: 
array([[ 2.79903811,  0.        ,  0.        ,  0.        ],
       [ 0.        ,  3.73205081,  0.        ,  0.        ],
       [ 0.        ,  0.        , -1.02020202, -1.        ],
       [ 0.        ,  0.        , -2.02020202,  0.        ]])

In [46]: vm = mat4.lookAt(pos, target, up).inverse()

In [47]: vm
Out[47]: 
[-1, -0, 0, -0]
[-0, 1, -0, 0]
[0, -0, -1, 10]
[-0, 0, -0, 1]
share|improve this question
1  
What are the near and far clip planes on your perspective matrix? Tweak these values, and see what changes. –  Will Sep 15 '13 at 14:16
    
Thank you for the idea. The near plane is at 1.0 and the far place at 1000.0. Sadly, changing them doesn't change anything. I've put them at 1.0 and 10.0 without any diffrences. –  Lionel Barret Sep 15 '13 at 14:19
1  
You should include how you're creating your matrices. –  Byte56 Sep 15 '13 at 14:48
1  
My knee-jerk reactions: 1. gluLookAt gives you a matrix which does not need to be inverted. 2. OpenGL "looks down" Z –  MickLH Sep 15 '13 at 15:33
1  
Why do you do the .inverse() part ? –  Valmond Sep 16 '13 at 9:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.