Public Group

# Strange Camera Problem

This topic is 2912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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!

##### Share on other sites
Your Up and Look-at vectors should be perpendicular. Try a Look-at of (0, -1, 0) and an Up of (0, 0, 1).

##### Share on other sites
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?

##### Share on other sites
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).

##### Share on other sites
Great, thanks for your help!

##### Share on other sites

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).

##### Share on other sites
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!)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 44