Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# more on normals

This topic is 6479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

hi, this piece of code below which i got from SirKnight on his post reply on calculation normals, dot product..., is supposed to get the normal of each polygon on my screen:
  for (i=0;i
what i have is a 3x3 points on the screen setup as: 0 1 2 3 4 5 6 7 8 and i''m drawing triangle strips from 0 to 3 to 1 to 4 to draw polygons.. this draws right, tho the normals dont work right. unfortunately, this only properly calculates the normal (from what i can tell), of only half the terrain map. can anyone shed some light (excuse the pun) on this? thanks, Scott "If you try and don''t succeed, destroy all evidence that you tried."

#### Share this post

##### Share on other sites
Advertisement
What you are doing is that you''re probably using the Points not the vector of the the points between the points... (you need at least 3 points!

1.) Calculate 2 vectors between the 3 points

A = facecorner 1;
B = facecorner 2;
C = facecorner 3;

vector1 = C - A;
vector2 = B - A;

now, vector1 and vector2 are 2 vectors that are in the plane of the face. use those 2 to calculate the normal with the cross product just as SirKnight told you... btw it''s not called dot product, it''s called cross product... the dot product is a number, the cross product a vector.

(dot - product: number = vector1.x * vector2x + vector1.y * vector2.y + vector1.z * vector2.z;
if the cross produkt is 0 the 2 vectors are perpendicular... ok?

hope that helped...
cya,
Phil

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

RAW!

#### Share this post

##### Share on other sites
hey,

actually, when i wrote dot product, i just meant that it was in the title of the post i got from the calculating normals post but anyways, i tried out the pseudo code u gave me and incorporated it into my code and this is what i got out of it:

now, does that look right using the follow light setup?

  GLfloat LightAmbient[]= { 1.0f, 1.0f, 1.0f, 1.0f };GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };GLfloat LightPosition[]= { 0.0f, 2.0f, 0.0f, 1.0f }; 

thanks for the help.
Scott

"If you try and don't succeed, destroy all evidence that you tried."

Edited by - wojtos on March 17, 2001 4:12:27 PM

#### Share this post

##### Share on other sites
I tried this normals thing too (made the other post about it) and I used the coordinates of the quads to calculate the normals. Are these the vectors you are talking about or am I doin'' it wrong?

#### Share this post

##### Share on other sites
i think this will work using quads also, bud instead of point 3, assuming the quad is setup like so;

1 2
3 4

because two triangls making a quad are all on the same plane are
they not? anyways i dont know if this is right, but what i did to figure out the vectors is:

vector1.x = point3.x - point1.x
vector1.y = point3.y - point1.y
vector1.z = point3.z - point1.z

vector2.x = point2.x - point1.x
vector2.y = point2.y - point1.y
vector2.z = point2.z - point1.z

that got me the two vectors to use in the cross product.

Scott

"If you try and don''t succeed, destroy all evidence that you tried."

#### Share this post

##### Share on other sites
Make sure you normalize the normal to get an accurate lighting result aswell..

l = sqrt(normal.x * normal.x + normal.y * normal.y + normal.z *
normal.z);

normal.x /= l;
normal.y /= l;
normal.z /= l;

newbie2001

#### Share this post

##### Share on other sites
cool, thanks for the tip... i tried it, and i think it helped.. but what does normalizing a normal mean?

scott

"If you try and don''t succeed, destroy all evidence that you tried."

#### Share this post

##### Share on other sites
well, let's say you have a small and a very large plane, then the normal for the large plane will be much larger than for the small plane (further away from the plane)
example:

small plane: (seen horizontal)
   N   | -----  

Large plane:
           N           |           |           |           |---------------------------  `

This will make the larger planes normal to be closer to the light and therefor always become mucgh brighter then the small plane, altough the planes might be in the exact same distance from the light.

When you normalize the normals you make them all have the same size, (distance from the plane).

I'm no expert on the subject, just lernt this myself a couple of weeks ago, so if I'm wrong someone please correct me

return 1;

Edited by - panic on March 17, 2001 7:37:05 PM

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11
• Advertisement

• 9
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013299
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!