The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Attn: OpenGL gurus by ataraxia 2009-05-08 15:25:15
I'm working on a lab for school, and we're using a data structure neither the book nor lecture covers. Basically, we are defining a diamond shape using 6 vertices and 8 faces. I am supposed to find the normals and do a bunch of other stuff. Here's where I get lost...

    int numFaces = 8;
    Vector3 p1, p2, p3;        // points or vertices of the triangle

    // define 5 vertices of a diamond shape - colors not being used now
    Vector3 vertexes[] = {
         Vector3(  0,  2,  0 ),     // vertex 0
         Vector3(  1,  0,  1 ),     // vertex 1
         Vector3(  1,  0, -1 ),     // vertex 2 ...
         Vector3( -1,  0, -1 ),
         Vector3( -1,  0,  1 ),
         Vector3(  0, -2,  0 )
    };

    // set up the face index data into the vertex array above
    // each triple will define a single face (triangle) of our shape
    Face faceData[] = {
         0, 4, 1,    // top front-facing face
         0, 3, 4,    // top left face
         0, 2, 3,    // top rear face
         0, 1, 2,    // top right face
         5, 1, 4,    // bottom front face ...
         5, 4, 3,
         5, 3, 2, 
         5, 2, 1,
    };

I am supposed to insert my normals into the faceData array. How do I do that? Teh Google-fu, it fails....

I have a means to calculate the normal by defining another Vector3 and assigning it the value of CrossProduct(Vector3 a, Vector3 b), and then using the normalize() function on that variable. I have done this like so:

Vector3 normals[] = {
     CrossProduct(vertexes[0],vertexes[4]), // normal for face 0, 4, 1
     CrossProduct(vertexes[0],vertexes[3]), // normal for face 0, 3, 4
     CrossProduct(vertexes[0],vertexes[2]), // etc.
     CrossProduct(vertexes[0],vertexes[1]),
     CrossProduct(vertexes[5],vertexes[1]),
     CrossProduct(vertexes[5],vertexes[4]),
     CrossProduct(vertexes[5],vertexes[3]),
     CrossProduct(vertexes[5],vertexes[2])
};
for (int count = 0;count < numFaces;count++)
 normals[count].normalize();


Don't worry if my normals are wrong. I can figure out the solution to that. I just need to know how to insert this data into the faceData array?
[ Reply ]
  Not a guru, but I'm not sure you can do that here. by bwkaz2009-05-08 19:54:23
  Beginner's Mistake... :-) by datenwolf2009-05-09 03:47:59

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)