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 4 of 4

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
    Member Regular Contributor
    Join Date
    Feb 2000
    Location
    milano, italy
    Posts
    282

    Re: normals.?.?

    you can do it two ways: add vectors to your face/vert list, or add a separate normal vectors database and dereference them with pointers or indexes into your face/vert list.

    personally i prefer to have face normals directly specified into face structure and indexes to a database into the vertex structure.

    is what you were looking for?

    Dolo/\/\ightY
    Dolo/\/\ightY

  3. #3

    Re: normals.?.?

    Dolo/\/\ightY can i get your email. I'm still a little confused on what your saying. Do you have aol instant messenger? Realtime chat would be best. You can email me at eckiller@home.com if you dont want to post your email/aim id. on the board. Your method sounds like what i'm looking for but i need a bit more detail to understand exactly what your saying.

  4. #4
    Intern Newbie
    Join Date
    Mar 2000
    Location
    New Jersey
    Posts
    30

    Re: normals.?.?

    Is this what you're looking for ?
    Pass in a 3d point to CalcNormal, it'll get the normal and put it in the out variable. Then use this normal vector in your call to glNormal();

    Hope this helps.
    Francis


    CalcNormal(Point3D a, Point3D b, Point3D c, Point3D *out)
    {
    Point3D v1,v2;

    // Calculate two vectors from the three points
    v1.x = a.x - b.x;
    v1.y = a.y - b.y;
    v1.z = a.z - b.z;

    v2.x = b.x - c.x;
    v2.y = b.y - c.y;
    v2.z = b.z - c.z;

    // Take the cross product of the two vectors to get
    // the normal vector which will be stored in out
    out->x = v1.y * v2.z - v1.z * v2.y;
    out->y = v1.z * v2.x - v1.x * v2.z;
    out->z = v1.x * v2.y - v1.y * v2.x;

    // Normalize the vector (shorten length to one)
    GLReduceToUnit(out);
    }

    void GLElement::GLReduceToUnit(Point3D *vector)
    {
    float length;

    // Calculate the length of the vector
    length = (float)sqrt( (vector->x * vector->x ) +
    (vector->y * vector->y ) +
    (vector->z * vector->z ) );

    // Keep the program from blowing up by providing an exceptable
    // value for vectors that may calculated too close to zero.
    if (length == 0.0f) length = 1.0f;

    // Dividing each element by the length will result in a
    // unit normal vector.
    vector->x /= length;
    vector->y /= length;
    vector->z /= length;
    }
    Originally posted by eckiller:
    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
    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
  •