View Full Version : Math question about vectors. Please HELP

fandecine

11-28-2002, 11:08 AM

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!

satan

11-28-2002, 01:25 PM

Originally posted by fandecine:

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!

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 http://www.opengl.org/discussion_boards/ubb/smile.gif

fandecine

11-28-2002, 03:24 PM

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

satan

11-28-2002, 08:53 PM

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.

fandecine

11-29-2002, 07:22 AM

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!

satan

11-29-2002, 10:49 AM

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.

fandecine

11-30-2002, 07:02 AM

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

ioquan

11-30-2002, 10:51 PM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.