Strange Camera Problem

Started by
5 comments, last by ApochPiQ 12 years, 5 months ago
Hiya,

I've got a skybox working with OpenGL, but I'm having a strange problem. When I set the camera looking front, back, left or right the skybox draws properly. If I set the camera looking straight up or down however, the skybox isn't drawn. I've got a feeling this is because OpenGL can't decide how to orient the camera, but I'm not sure.

The code I'm using to set the camera is:

gluLookAt(
0.0f, 0.0f, 0.0f, // Position
0.0f, -1.0f, 0.0f, // Look At
0.0f, 1.0f, 0.0f); // Up


Given the the 'up' and 'look at' vectors are opposites, I guess there could be any number of ways of orienting the camera.. possibly.

Can anyone help with this?

Many thanks!
Advertisement
Your Up and Look-at vectors should be perpendicular. Try a Look-at of (0, -1, 0) and an Up of (0, 0, 1).

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanks, that works :)

My mistake - I thought the up vector was relative to the scene, not the camera. Is it expected to recalculate this every frame?
Yes - Up defines the "upwards" direction from the perspective of the viewer (camera). You could rotate the Up vector (so long as it remains perpendicular to Look-at) to accomplish a "roll" effect (in the traditional pitch/yaw/roll sense of the word).

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Great, thanks for your help!

Yes - Up defines the "upwards" direction from the perspective of the viewer (camera). You could rotate the Up vector (so long as it remains perpendicular to Look-at) to accomplish a "roll" effect (in the traditional pitch/yaw/roll sense of the word).


He is using gluLookAt, which will orthonormalized his camera axes for him in the generated matrix, however, (0, -1, 0) x (0, 1, 0) is obviously (0, 0, 0). So yes, the Up vector supplied to gluLookAt cannot be parallel to the vector formed by (lookAt - eyePosition).
Ah, good to know. I haven't touched OpenGL in many years, and my freshest memory of building view matrices is from doing it by hand where you need to ensure the vectors are normalized and orthogonal :-)

(Shows how often I write graphics code, heh!)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement