Thread: Normal question (well, kinda weird actualy)

1. Re: Normal question (well, kinda weird actualy)

hello,

Why is this important to know? Because if you haev two vectors, u and v, and computed the crossproduct(u, v) and crossproduct(v, u) (note the change in ordering), then you'll get _two vectors in opposite directions_.

So, the problem you have, I think, is that you're sometimes computing the wrong normal.

to fix this,
1) decide on a winding order for your veritices. I suggest counter-clockwise (the opengl default).
2) make sure all your triangles are in couter-clockwise order, and
3) make sure you compute the normals in the right order for your winding.

for example, if you choose counter clockwise, then the front side of your triangle would look like

Code :
```0
|\
| \
1--2```
(0, 1, 2 travel counterclockwise). You could compute the normal as crossProduct(1-0, 2-0) and get a normal pointing towards you (since you're looking down at this triangle).

If you ensure that your winding order is ALWAYS clockwise then you can always comute your nromals that way and gauarantee they point outwards.

hope this helps
chees
JOhn

2. Re: Normal question (well, kinda weird actualy)

hmm... i can't change the order at wch it is drawn, because its being read from a file. but, if i used quads instead, would i not have to do that?

3. Re: Normal question (well, kinda weird actualy)

changing to quads won't make a difference because you still have to pick to vectors for the dot product.

reading from a file shouldn't be an impediment on Correct Vector Ordering, for two reasons
- you can always buffer, and;
- the file should be correct, not ad hoc.

cheers
john

4. Re: Normal question (well, kinda weird actualy)

ok, im still working on this.... this is my code:

Code :
```for(i = 0; i < h1.num_faces; i++)
{
faces[i].normalx = vertices[faces[i].vertexindices[1]].y * vertices[faces[i].vertexindices[2]].z - vertices[faces[i].vertexindices[1]].z * vertices[faces[i].vertexindices[2]].y;
faces[i].normaly = vertices[faces[i].vertexindices[1]].z * vertices[faces[i].vertexindices[2]].x - vertices[faces[i].vertexindices[1]].x * vertices[faces[i].vertexindices[2]].z;
faces[i].normalz = vertices[faces[i].vertexindices[1]].x * vertices[faces[i].vertexindices[2]].y - vertices[faces[i].vertexindices[1]].y * vertices[faces[i].vertexindices[2]].x;
float length = sqrtf( faces[i].normalx * faces[i].normalx + faces[i].normaly * faces[i].normaly + faces[i].normalz * faces[i].normalz );
faces[i].normalx /= length;
faces[i].normaly /= length;
faces[i].normalz /= length;
}```
still doesnt work!

[This message has been edited by c_olin (edited 08-13-2003).]

Posting Permissions

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