"Eye direction" Vector

Hello, people!

I have a question of math. I don’t know how I should call that, but I’ll try to explain my problem as clearly as possible.

I have a scene drawn. Let’s assume it’s an infinite plane, with normal vector (0,1,0) in the origin.

Now, I have numerous (hundreds) billboards above this floor. The texture to be drawn in the billboard depends on the direction of the camera relative to the billboard. I have 8 textures for each billboard (N, NE, E, SE, S, SW, W, NW), and, according to the angle with the “billboard direction vector” and the “camera vector”, I’ll decide wich one to draw, such as:

If the camera is N (0,0,1) and the billboard direction is N, I’ll draw the texture “N”, but if the billboard direction is “S”, I’ll draw the texture “S”.
If the camera is S (0,0,-1) and the billboard direction is “N”, I’ll draw the texture “S”.

My question is, How do I know, using the OpenGL functions, how to determine the direction the camera is facing.

Thanks everyone!

  • Sergio

It is a convention derived from the screen coordinate system. Matrix adjustments then transform this default convention.

The convention is… drumroll…

The plane of the screen is +x horizontally to the right and +y vertically upwards. +z sticks out from the screen towards the viewer.

So unless you transform the viewing matrix very deliberately to undo this, the ‘horizontal plane’ is x, z and +y is pointing up.

By default (with identity matrices) the camera is at (0,0,0) and looks along (0,0,-1) into the screen.

So basically, you want to display a different texture depending on which way the camera is facing.

Following up on what dorbie said, the vector from the eye through the center of your screen is (0,0,-1) in eyespace (assuming on-axis frustum). Transform by inverse modelview to get to object space. Assuming there’s no distinction between object space and world space in your app, then you just snap this vector to one of your magic vectors: (0,0,1), (0,1,0), etc. to determine which texture to display.

Vary for your app as desired. For instance, if you do billboarding using turn to eyepoint as opposed to turn to viewvector, compute the eye vector using the center of your specific billboard in eyespace. If there’s a distinction between world and eye space in your app, only use the inv viewing rather than modelview for the back transform.

local viewer