Skip to main content
GameDev.net gamedev.net
🔒 Locked

lights

Started by wforl Jun 28, 2007 at 4:53 AM 0 replies 900+ views
Original Post
wforl
wforl
How come that when you want to move the origin in the negative y axis you do this glTranslatef(0, -5, 0); yet when you want to set up a light in the negative y axis the code is GLfloat lightDir[] = {0.0, 1.0, 0.0, 0.0}; glLightfv(GL_LIGHT0, GL_POSITION, lightdir); i mean, to me, this code says, there is a light that is infenitly far away, and is looking up, the positive y direction, as y1.0 is looking up, and y-1.0 is looking down. yet in my book, the author says that this code sets up a directional light pointing in the negative y axis. He also explains that the default position for a light is 0,0,1,0, which is a directional light pointing down the negative axis. which is a light pointing away from us, but again how is setting 0,0,1,0 looking down the negative axis, i understand it as it should be 0,0,-1,0. do lights work backwoods or somthing?
Brother Bob
Brother Bob
The homogenous coordinate (x, y, z, w) corresponds to a point in non-homogenous space at (x/w, y/w, z/w).

Now, place a light at (0, 1, 0, 1), which is the point (0, 1, 0). Now, place the light at (0, 1, 0, 0.1) and the light end up at point (0, 10, 0) instead. Keep decreasing w, say to 0.01, and you get the light at (0, 100, 0). As w approaches 0, the light position approaches (0, +Inf, 0). A light at (0, +Inf, 0) emits lighit along the negative Y-axis only, since it's located far away along the positive Y-axis.

In other words, (0, 1, 0, 0) is the position of the light, or in the w=0 case a vector pointing from the origin towards the light. The light itself is travelling in the opposite direction.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.