Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

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,982

    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
    Intern 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

Posting Permissions

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