Advertisement

Vertex Normals

Started by October 17, 2000 12:56 PM
5 comments, last by jollyjeffers 24 years, 1 month ago
hi, Could someone tell me how I could get 4 vertex normals given this information: 4 points in 3D space (XYZ) defining a tile - rendered as two triangles in a trianglestrip: 0-1 / 2-3 I need to get the normals so I can finish my lighting engine; I know this is fairly simple, and have seen it many times before - but never needed to use it, so have never paid any attention to it... many thanks in advance, Jack,

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

I think that the best way to solve is the normal
of polygon 1,2,3,4

1------2
| |
| |
3------4

you can get it with this

void NormalizedCross(float* u, float* v, float* n)
{
float l;

n[0] = u[1] * v[2] - u[2] * v[1];
n[1] = u[2] * v[0] - u[0] * v[2];
n[2] = u[0] * v[1] - u[1] * v[0];

l = (float)sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]);
if (l == 0) l = 1.0;
n[0] /= l;
n[1] /= l;
n[2] /= l;
}

where the u is vector from 1 to 2
and v is vector from 1 to 3 and n is
normal vector.


Dave
--------Dave[ Math Studio ] A Computer Algebra System
Advertisement
well it''s me again....
to get the normals, you just calculate the normal of each triangle and divide the by 2 (You calculate the average normal vector....) though i don''t think this would help you too much, cause to make a nice lightning engine you''d have to think of the tile lying next to it, right? and the recalculate the average... Correct me if i''m wrong....
cya,
Phil
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
well dave was faster... ;o)
cya!
Phil

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

thanks...
I already have something similiar to that; what I really need is the normal for the two different triangles that make up the tile...

as they can "bend" down the middle it is possible that they''ll face very different directions...

Jack;

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

I had the same problem - non planar quads but solved it by breaking my strip into two tri''s to calculate the normals. now the problem is averaging the normals against all the joined edges so that it looks smoother.

Advertisement
quote: Original post by phueppl1

well it''s me again....
to get the normals, you just calculate the normal of each triangle and divide the by 2 (You calculate the average normal vector....) though i don''t think this would help you too much, cause to make a nice lightning engine you''d have to think of the tile lying next to it, right? and the recalculate the average... Correct me if i''m wrong....
cya,
Phil



There''s one problem with this: the average of normals of the triangles will not get you the right results in all cases. For the presented case, it will probably work.

What is better is to add all the triangles'' normals together, then normalize. It will, in general, be more accurate.



---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!
---- --- -- -
New York. New York. New York. Texas. Texas. New York. New York. Canada.
---- --- -- -

This topic is closed to new replies.

Advertisement