Results 1 to 3 of 3

Thread: normals.?.?

  1. #1

    normals.?.?

    Can someone give me a way to find the normal for each primitive using my class structure. My fragmented structure:

    Object: holds an array of verts and an array of primitives that make up object.

    Primitive: holds indices that make up this primitive.

    VERTEX: x, y, z coordinates

    I've been coding for quite awhile today and i just can't think how to get this w/ my class structure. I'd like to have a method in my Primitive class that calculates the normal for that particular primitive, it it possible to do so with just indices and no verts? Ideas and suggestionns please!!??

    Thanks

    Frank

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: normals.?.?

    Hello

    To obtain normals, you have to calculate them on your own. One normal for each polygon building up your object(s).

    All you have to do, is loop through all polygons and calculate the normal, like this:

    for(i=0; i<num_polys; i++)
    {
    p1=polygon[i].vertex_1
    p2=polygon[i].vertex_2
    p3=polygon[i].vertex_3

    v1.x = p2.x - p1.x
    v1.y = p2.y - p1.y
    v1.z = p2.z - p1.z

    v2.x = p3.x - p1.x
    v2.y = p3.y - p1.y
    v2.z = p3.z - p1.z

    // use crossproduct to obtain normal
    n[i].x = (v1.y * v2.z) - (v2.y * v1.z)
    n[i].y = (v1.z * v2.x) - (v2.z * v1.x)
    n[i].z = (v1.x * v2.y) - (v2.x * v1.y)
    }

    Just some quick pseudo code, but i think you get the point...

    Then you have to normalize them (make them of unit length, length of 1).

    Bob

  3. #3
    Member Newbie
    Join Date
    Mar 2000
    Location
    New Jersey
    Posts
    30

    Re: normals.?.?

    Check the advanced boards, I've responded to this with a unit normal implementation.
    fs
    Francis Shanahan
    Architect

Similar Threads

  1. Replies: 6
    Last Post: 04-14-2004, 10:07 PM
  2. face normals or vertex normals
    By infinitecmdz in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 02-21-2004, 07:29 AM
  3. vertex normals or face normals
    By infinitecmdz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-20-2004, 09:35 AM
  4. is it possible to have vertex normals or even face normals using triangle strips nt
    By wildeyedboyfromfreecloud in forum OpenGL: Advanced Coding
    Replies: 63
    Last Post: 03-19-2002, 11:42 PM
  5. Face Normals vs. Vertex Normals
    By detzel in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-05-2001, 10:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean