Sign in to follow this  
radom

OpenGL confused with opengl direction vectors

Recommended Posts

Hi guys. I'm a programmer trying to learn opengl. But some basic concept is confusing me. For example, let's take this command... GLfloat spot_direction[] = { -1.0, -1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction); That is a command that I copied from the "opengl red book". They say, that spot_direction parameter passed to the glLight*() will tell opengl the direction of the spot light. When I try to imagine it, spot_light direction is just one point in the x, y, z, w plane. And I'm wondering how a single point can be used as a direction. I feel like I can use that point and say "it is pointing to a zillion directions". Anywayz, I was getting confused by the so called direction vectors and sort of things. They give x, y, z points and say it is pointing "this way". I would appreciate any explanation ... Thanks in advance

Share this post


Link to post
Share on other sites
Besides the fact that those light stuff is deprecated anyway ...

A spot light knows of a hard angular limitation named "spot cutoff":
Quote:
from manpage
GL_SPOT_DIRECTION
params contains three integer or floating-point values that specify the direction of the light in homogeneous object coordinates. Both integer and floating-point values are mapped directly. Neither integer nor floating-point values are clamped.

The spot direction is transformed by the inverse of the modelview matrix when glLight is called (just as if it were a normal), and it is stored in eye coordinates. It is significant only when GL_SPOT_CUTOFF is not 180, which it is initially. The initial direction is (0, 0, -1).
And later:
Quote:
from manpage
GL_SPOT_CUTOFF
params is a single integer or floating-point value that specifies the maximum spread angle of a light source. Integer and floating-point values are mapped directly. Only values in the range [0,90] and the special value 180 are accepted. If the angle between the direction of the light and the direction from the light to the vertex being lighted is greater than the spot cutoff angle, the light is completely masked. ...

Hence radiation isn't ever homogeneous and hence a direction is needed in some cases.

Share this post


Link to post
Share on other sites
It's the Point vs Vector thing. {-1.0, -1.0, 0.0} is interpeted as a vector, starting at {0, 0, 0} and ending at {-1.0, -1.0, 0.0}, which gives you a direction.

Share this post


Link to post
Share on other sites
As HuntsMan said, it is a basic concept: a point defines a direction if you take the vector from <0,0,0> to that point.

I would suggest reading about vector & matrix algebra, the concept of "space" or "basis" and rotation/translation/scale order importance before using OpenGL because if you don´t, you´ll be soon doing things that you don´t fully understand. And debugging code that you can´t understand is a pain in the ass.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this