View Full Version : Faces stored in arrays

Zadkiel

08-22-2000, 08:23 AM

Hi,

My program loads a dxf file and save each FACE3D in an aray in the following order x,y,z,x,y,z,x... These render perfectly but I'm wonder how do I generate normals or texture objects drawn in this fashion.

Thanks

natt_dread

08-22-2000, 07:05 PM

I don't know about texture objects, but calculating a normal from a triangle can be done using the cross product. This is the code that I use:

// Calculate two vectors for the x-product,

// where tri_verts is an array holding your

// triangle vertices:

v1 = tri_verts[ 0 ] - tri_verts[ 1 ];

v2 = tri_verts[ 2 ] - tri_verts[ 1 ];

// Use the cross product of the two vectors

// to compute the face normal:

normal.x = v1.y * v2.z - v1.z * v2.y;

normal.y = v1.z * v2.x - v1.x * v2.z;

normal.z = v1.x * v2.y - v1.y * v2.x;

// OpenGL expects normals to be normalized:

normal.Normalize();

This is a normal for a single face and is only useful if you are using flat shading. If you want smooth objects you'll have to average the normals at each vertex.

Hope this helps.

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