Normal question (well, kinda weird actualy)

Don’t bump topics; it is childish and counter-productive. It is also unnecessary in a forum that uses cookies to keep track of new messages.

Think about what would happen if everyone bummped their topic every time it wasn’t top.

Oh, and you didn’t ask a question: you merely stated an observation.

Im sorry, but it was half way down the page.

I can read more than half a page before my brain hurts. <nods wisely>

You still didn’t ACTUALLY ask a question, btw.

Maybe you are confused by Wolfram’s notation. The two vectors in his notation are u and v. The components for U are thus U_x (U subscript x), U_y and U_z. So… the “x’s” are actually U_x and V_x.

but compare the Wolfram equation to Dorbie’s equation:
normalx = v2.yv1.z - v2.zv1.y;
normaly = v2.zv1.x - v2.xv1.z;
normalz = v2.xv1.y - v2.yv1.x;

they are different!

Do i use Wolfram’s or Dorbie’s?

hello,

they are the same equation, actually.

check out the equation: http://mathworld.wolfram.com/c3img1196.gif

that is the same as what dorbie wrote, albeit using a different notation.

x’hat (x with a caret (^) above it) et al are basis vectors; it indicates the magnitude in the corresponding direction.

I apologise for being snakey before.

no, i deserved it.

i still don’t quiet get it, but ill just go with dorbies Math, thansk for the help!

no, no, getting it is all part of the trick bcause then you’ll understand MORE stuff, and that has to be a good thight.

It’s kinda like this: the decimal number 1234 can also be written as 11000 + 2100 + 310 + 41, right? Well, a three-dimensional vector <1, 2, 3> can be written as 1*<1, 0, 0> + 2*<0, 1, 0> + 3*<0, 0, 1>. So… when dorbie says that the x component of a normal is A (where A is u.yu.z - u.zu.y), the y component is B and the z component is C, then what he’s saying is you can decompose the vector like so: A*<1, 0, 0> + B*<0, 1, 0> + C*<0, 0, 1>. the X^ from wolfram is just short-hand for writing <1, 0, 0>, i.e. a vector in the x-direction.

now, does THAT make sense?

cheers,
John

woah, ill print that out and read it a dozen times before i go to bed… lol

im only in algebra 1!

ok, i think i understand, and i got it to code… he it is:

for(i = 0; i < h1.num_faces; i++)
{
faces[i].normalx = vertices[faces[i].vertexindices[1]].y * vertices[faces[i].vertexindices[0]].z - vertices[faces[i].vertexindices[1]].z * vertices[faces[i].vertexindices[0]].y;
faces[i].normaly = vertices[faces[i].vertexindices[1]].z * vertices[faces[i].vertexindices[0]].x - vertices[faces[i].vertexindices[1]].x * vertices[faces[i].vertexindices[0]].z;
faces[i].normalz = vertices[faces[i].vertexindices[1]].x * vertices[faces[i].vertexindices[0]].y - vertices[faces[i].vertexindices[1]].y * vertices[faces[i].vertexindices[0]].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;
}

but weird problems, i get weird triangles, some black and some regular whenever i enable lighting… please help!

[This message has been edited by c_olin (edited 07-24-2003).]

hello,

make sure your normals are correct with respect to your geometry. The cross product of two vectors u & v will generate a normal with the ‘right-hand rule’. If you point your index finger of your right hand in the direction of u and stick your middle finger at right angles to your palm and point it in the direction of v then sticking your thumb up into the air is the cross product of u and v. This trick works because you can only rotate your middle finger so far and so you’re compelled to rotate your hand to get your fingers pointnig in u and v… and as you do so, your thumb will change direction accordingly.

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

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

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?

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

ok, im still working on this… this is my 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).]