Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Pixel_Outlaw on December 22, 2008

Title: Setting an angular light in OpenGL.
Post by: Pixel_Outlaw on December 22, 2008

I know how to set a light in OpenGL but I cannot quite figure out how to set a directional vector for it.

I whipped this up in AutoCAD to show what I mean. The view here is isometric to show how the light rises above the canvas then points back down at an angle. I've checked on line documentation but find it a bit confusing. Now I could be wrong but I think AutoCAD uses OpenGL to render in this old version so hopefully the effects will be transferable.

Title: Re: Setting an angular light in OpenGL.
Post by: hellfire on December 22, 2008
For directional lights you simply set the 4th component of the light's position to zero which will set it infinitely far away.
Title: Re: Setting an angular light in OpenGL.
Post by: Pixel_Outlaw on December 22, 2008
Wouldn't the lights have no direction if they were infinitely far away?

The light I need should rise above the drawing area and shine back down on the drawing. The drawing is what I want even though it was done in a drafting program. It is isometric to show how the light is positioned. By default the lights make everything appear fully lit because I assume the default view is parallel to the light source.
Title: Re: Setting an angular light in OpenGL.
Post by: hellfire on December 23, 2008
Even if it's at infinity you can still tell the direction (just like the sun), so all light-rays are parallel which is exactly what you want.
See here (http://jerome.jouvie.free.fr/OpenGl/Tutorials/Tutorial13.php) and have a look at homogenous coordinates (http://en.wikipedia.org/wiki/Homogeneous_coordinates).
Title: Re: Setting an angular light in OpenGL.
Post by: Pixel_Outlaw on December 23, 2008
GREAT thanks!

Have some karma.