Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 4 of 4 FirstFirst ... 234
Results 31 to 34 of 34

Thread: Normal question (well, kinda weird actualy)

  1. #31
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    839

    Re: Normal question (well, kinda weird actualy)

    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

    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. #32
    Intern Contributor
    Join Date
    May 2003
    Posts
    50

    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. #33
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    839

    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. #34
    Intern Contributor
    Join Date
    May 2003
    Posts
    50

    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
  •