about counter(or not) clockwise oriented triangles

Hi !
I try to compute normals from a .3ds file, and i have two values for the orientation of the triangles :
7 in binary 111 (vector from A to B (the first ‘1’ in binary), B to C (the second ‘1’ in binary), and C to A (the third ‘1’ in binary))
5 in binary 101 (A to B (the first ‘1’ in binary), C to B (the ‘0’ in binary), and C to A (the third ‘1’ in binary))
with what vectors have i to make a cross product and WHY ? mainly when i 've got the 5 value

don’t hesitate to tell me if you think that i’m not clear :wink:

To compute the vector at point A : Take the cross product of vectors of (Vector A to B) and (Vector A to C).

So on , calculate for the other vertices.

Cant help much on the bits … didnt understand it :wink:

thanks for your answer, i’ll try to explain for the bits:
if i read for a face the number ‘7’ in the file, it gives ‘111’ in binary.if the first bit is at ‘1’ (from the left), the vector between A and B is from A to B, with a bit at ‘0’ the vector is from B to A.idem for both bits witch are for BC and CA (for the last).
so can i compute the cross product with A to B and C to A ? Otherwise what have i to do ?

If you can obtain the vectors A to B and C to A.
Wht you can do is

  • Let Vector A to B be as it is.
  • Vector C to A , reverse it . Reverse it means, if the vector is ai+bj+ck , make it -ai-bj-ck.
    This vector represent Vector A to C.

Now you can calculate the cross product at vertex A.

Was this problem solved ?
if it is not solved - Can u post some links on the file format for .3ds.

Will take it up from there.

Maybe this will help. To compute a normal for two vectors of a triangle:

  1. The two vectors common point must be at the origin to use this method. If they are not you need to shift the vectors so the common point (the point where the two vecotrs meet) is at the origin.

  2. You now have two vectors relative to the origin. Lets call them U and V and the normal will be N. So U = <U.x,U.y,U.z> and V = <V.x,V.y,V.z> and N = <N.x,N.y,N.z>.

N.x = U.yV.z - U.zV.y;
N.y = U.zV.x - U.xV.z;
N.z = U.xV.y - U.yV.x;

Depending on which vector you call U and which vector you call V the normal will point one way or the other (you can have two vectors that are perpendicular to a triangle, one on each side).

  1. Now you have a vector that is perpendicular to the other two vectors. But now you have to make sure it has a length of one. All normals need to have a length of one. To do that you find the length of the normal and divide each component of the normal by that length:

length = sqrt(N.xN.x + N.yN.y + N.z*N.z)

N.x = N.x/length;
N.y = N.y/length;
N.z = N.z/length;

This should give you the normal. (note that this is usefull because it also more or less gives you the plane equation for the triangle).

Here is an example:

here are the verts for a triangle:

Vert1 = 0,0,0
Vert2 = 10,0,0
Vert3 = 0,0,10

So the two vectors that start at the origin are:

U = <10,0,0> 10,0,0
V = <0,0,10> 0,0,10

calculate the normal:

N.x = 010 - 00 = 0
N.y = 00 - 1010 = 100
N.z = 010 - 00 = 0

Make the length one:

length = sqrt(00 + 100100 + 0*0) = 100

N.x = 0/100 = 0
N.y = 100/100 = 1
N.z = 0/100 = 0

so the normal ends up where it should be pointing directly up from the origin (y = 1) and has a length of one. Good luck. I hope this helped.