Sign in to follow this  
riruilo

glLight + Direction + GL_POSITION: Can you explain me this?

Recommended Posts

riruilo    218
Hi all! I don't understand this: "The initial position is (0, 0, 1, 0); thus, the initial light source is directional, parallel to, and in the direction of the -z axis." From http://linux.die.net/man/3/gllightfv My question is: Why 0,0,1,0 and not 0,0,-1,0 if default direction is -z? Thanks for help.

Share this post


Link to post
Share on other sites
Brother Bob    10344
Look up homogenous coordinates. Basically, a coordinate (x, y, z, w) in 4D homogenous space is equal to (x/w, y/w, z/w) in 3D space. When w=1, you have the 3D subspace of 4D homogenous space which corresponds to 3D space. That is, the point is located at (x/1, y/1, z/1).

Now see what happens as w approaches 0. For w=0.1, the point is (10*x, 10*y, 10*z). For w=0.001, the point is (1000*x, 1000*y, 1000*z). As w approaches 0, the point (x/w, y/w, z/w) approaches a point at infinity in the direction from the origin towards (x, y, z).

Therefore, a light positioned at (0, 0, 1, 0) is located an infinite distance from the origin in the direction (0, 0, 1), which means the light is shining in the direction (0, 0, -1) from infinity towards the origin.

In short, when specifying directional lights, the vector is not the direction of the light. It is the direction towards the light source from the origin.

Share this post


Link to post
Share on other sites
riruilo    218
Quote:
Original post by Brother Bob
Look up homogenous coordinates. Basically, a coordinate (x, y, z, w) in 4D homogenous space is equal to (x/w, y/w, z/w) in 3D space. When w=1, you have the 3D subspace of 4D homogenous space which corresponds to 3D space. That is, the point is located at (x/1, y/1, z/1).

Now see what happens as w approaches 0. For w=0.1, the point is (10*x, 10*y, 10*z). For w=0.001, the point is (1000*x, 1000*y, 1000*z). As w approaches 0, the point (x/w, y/w, z/w) approaches a point at infinity in the direction from the origin towards (x, y, z).

Therefore, a light positioned at (0, 0, 1, 0) is located an infinite distance from the origin in the direction (0, 0, 1), which means the light is shining in the direction (0, 0, -1) from infinity towards the origin.

In short, when specifying directional lights, the vector is not the direction of the light. It is the direction towards the light source from the origin.


Very interesting. Thanks a lot.
I guess this works not only for directional lights, but for spot light.

However, spot lights have two directions: Light direction and spot direction.

Is also GL_SPOT_DIRECTION affected by what you said?

Thanks a lot.

Share this post


Link to post
Share on other sites
Brother Bob    10344
No, spotlights have a position and a direction. Position is the same as the other lights. The direction of the spotlight is a direction vector pointing in the direction the spotlight is aimed.

Share this post


Link to post
Share on other sites
riruilo    218
Quote:
Original post by Brother Bob
No, spotlights have a position and a direction. Position is the same as the other lights. The direction of the spotlight is a direction vector pointing in the direction the spotlight is aimed.


Yes, you are right another time.

Thanks a lot for your help.

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