• Advertisement

• ### Popular Now

• 13
• 15
• 19
• 27
• 9
• Advertisement
• Advertisement
• Advertisement

# Object disappears using glm::lookAt when eye and center vectors have 2 coords in common?

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

This seems quite strange to me, and I can't understand why it would be happening.

Last night I was trying to display a series of triangle strips as a flat plane, using a tutorial as reference. I couldn't figure out why nothing was showing up in the end, but today it started to work after I changed the eye position of the camera slightly.

My code was like this:

glm::vec3 planePos( 0.0f, 0.0f, 0.0f );
glm::mat4 viewMat = glm::lookAt( glm::vec3( 0, 40, 0 ), glm::vec3( 0, 0, 0 ), glm::vec3( 0.0f, 1.0f, 0.0f ) );
glm::mat4 modelToCam = glm::translate( glm::mat4( 1.0f ), planePos );


And nothing was showing up, but changing the first vector of lookAt to even glm::vec3( 0.1f, 40, 0 ) makes it display fine. -0.1f works too, and the pattern I've noticed is that it seems that nothing appears if the eye (first) and center (second) vectors have 2 coordinates in common.

I tried changing the tutorial code and the same thing seems to happen.

I'm imagining a camera 40 units above the origin, staring down at the origin, and I can't figure out what could be problematic about that. The tutorial doing the same makes me think it's not just me doing something dumb somewhere else in the code (I had thought about near clipping planes etc. for a moment...).

The position of the plane also seems to make no difference, it all seems to be about how the eye and center vectors relate to each other.

Am I missing something obvious? Or is this some weird special case when dealing with matrices?

#### Share this post

##### Share on other sites
Advertisement

Your up-vector (the third parameter) must not be collinear with your forward vector (target - eye). It should be (0, 0, 1) or one of the many other possibilities. If you modify just one of the coordinates you did, glm::lookAt can orthogonalize the whole thing but that is mathematically impossible like you wrote it.

#### Share this post

##### Share on other sites

I see... interesting, I had no idea. Given my intention to have a perfectly overhead camera, I guess I'll change it to the Z coord.

Did some Googling and this seems to explain things further...

http://stackoverflow.com/questions/10635947/what-exactly-is-the-up-vector-in-opengls-lookat-function

Never really knew what the up vector was for before. Now it makes some sense. Thanks.

#### Share this post

##### Share on other sites

• Advertisement