# Thread: light direction

1. ## light direction

Sorry I am new to opengl and have this embarrasing question:

How do we position in opengl a light 50 degrees above the viewer and 70 degrees to its right?

2. ## Re: light direction

Originally posted by mikemor:
Sorry I am new to opengl and have this embarrasing question:

How do we position in opengl a light 50 degrees above the viewer and 70 degrees to its right?

You read the sections appropriate in the opengl redbook... (it's everywhere) look in the section of Viewing and Lighting...

3. ## Re: light direction

Thanks. I have looked in the red book and I know that I should use glLightfv() with the direction of the light relatively to the viewer as the arguments. What I dont know is what does it mean
"a light 50 degrees above the viewer and
70 degrees to its right"
i.e. how do I translate this info into a direction to be fed to glLightfv?

thanks

4. ## Re: light direction

I think thats where the maths stuff comes in. It sounds like you can imagine a triangle and using Pythagoras Theorem and/or sine and cosine calculations you can figure out the xyz position of the light... well theoretically. Not too hot on this maths stuff for graphics yet. Having to hook out my old maths books again

Perhaps someone else can confirm this... I sure hope I was right saying this stuff

Tina

5. ## Re: light direction

Thanks. Yes, I think you are right that I need to solve some sort of triangle but I am not sure what exactly is the triangle. Does anybody?
Thanks

6. ## Re: light direction

Math is the number one thing you need to know if you are going to do 3D graphics.

I am thinking that 50 degrees above is as if the viewer was facing the sun and it was at an angle above him at 50 degrees. Which gives up a hight of the light.

Then the 70 degrees to the right, means the sun is move to the right, but still at the 50 degree hight.

I don't have my code handy, to write it.
But any good algebra book with have the cos/sin functions to find it.

Originally posted by mikemor:
Thanks. Yes, I think you are right that I need to solve some sort of triangle but I am not sure what exactly is the triangle. Does anybody?
Thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•