View Full Version : normals.?.?

eckiller

03-18-2000, 12:45 PM

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

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

eckiller

03-19-2000, 08:05 AM

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.

fshana

03-20-2000, 09:54 AM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.