Hi!
I realized that my last post was very unclear, so let’s try to explain it clearly:

I need to implement constant shading without using GL functions. So, I need a light (lx,ly,lz) and a polygon somewhere.
The formula to get the new color of that polygon with the position of the light is --> NEW_COLOR = COLOR_poly * [(vN/ | |vN| | ).(vL/ | |vL| |) where | |vN| | is the norm of the vector and . the dot product, vN the vector of the polygon and vL the vector to the light. My question is: how do I get vN and vL? I will really appreciate your help!

Originally posted by fandecine:
[b]Hi!
I realized that my last post was very unclear, so let’s try to explain it clearly:

I need to implement constant shading without using GL functions. So, I need a light (lx,ly,lz) and a polygon somewhere.
The formula to get the new color of that polygon with the position of the light is –> NEW_COLOR = COLOR_poly * [(vN/ | |vN| | ).(vL/ | |vL| |) where | |vN| | is the norm of the vector and . the dot product, vN the vector of the polygon and vL the vector to the light. My question is: how do I get vN and vL? I will really appreciate your help![/b]

OK, second try. Looks like vN should be the normal of the polygon (only one normal so it looks like flat shading). vN is perpendicular to the polygon, so think about the cross product. Now you have vN. You have or can easily calculate the position of your polygon as vector (px,py,pz) and your light position as a vector (lx,ly,lz). vL is the vector from (px,py,pz) to (lx,ly,lz). Easy enough to calculate. This should do your homework

Ok for vN but what are px,py & pz? Any points from the polygon?

Originally posted by fandecine:
Ok for vN but what are px,py & pz? Any points from the polygon?

Your lighting calculation uses the angle between vN and vL to calculate the new color of the polygon. Of course this angle depends on which point on the polygon you chose for (px,py,pz). Why don’t you just write the code and try it for different (px,py,pz) and light positions?
Hint: You should try the vertices of your polygon for (px,py,pz) and perhaps the middle point of it would be clever to try, too.

Hi Satan! I really appreciate your hints but it seems that you know how to calculate it. It may be easy for you but not for me. Since I already found out how to calculate the vector vN (with your help), why don’t you just tell me how to calculate vL? My project is build up on this first step (only difficult step for me) and I am stuck right now.
Thanks!

Originally posted by fandecine:
Hi Satan! I really appreciate your hints but it seems that you know how to calculate it. It may be easy for you but not for me. Since I already found out how to calculate the vector vN (with your help), why don’t you just tell me how to calculate vL? My project is build up on this first step (only difficult step for me) and I am stuck right now.
Thanks!

I don’t really know anything. I just tell you what I would do given the same task.
Take the middle point of your poly for the vector vP=(px,py,pz). With vLP=(lx,ly,lz) your light position vLP=vP+vL <=> vL=vLP-vP. That should do the trick.

Hi Satan!
I have a last question:
How can you calculate the middle point of the poly (for the vector vP) when there are 5-6 or even 7 vertices?
Thanks.
LD

the midpoint of the poly is just the sum of all the vertices divided by the total number of vertices.