This topic is now archived and is closed to further replies.


problem with generating normals

Recommended Posts

adam17    227
whenever i compile my code and run the program i keep getting unlit triangles. i am generating the normals on the fly from my vertex values. the vertex array is designed so that i can just throw them into a loop with glVertex3fv(). the function Cross generates the cross product. anyway here is the code:
vector<float> normal;
vector<float> vertex;
vector<float> face;
struct Vector3 
{float x, y, z};

		Vector3 vertex1, vertex2, vertex3;
		Vector3 edge1, edge2;
		Vector3 tnormal;
		for(int x=0; x<normal.size(); x+=9)
			vertex1.x = face[x];	vertex1.y = face[x+1];	vertex1.z = face[x+2];
			vertex2.x = face[x+3];	vertex2.y = face[x+4];	vertex2.z = face[x+5];
			vertex3.x = face[x+6];	vertex3.y = face[x+7];	vertex3.z = face[x+8];

			edge1 = vertex3 - vertex2;
			edge2 = vertex1 - vertex2;

			tnormal = Cross(edge1, edge2);

			normal[x%9] = tnormal.x;
			normal[(x%9)+1] = tnormal.y;
			normal[(x%9)+2] = tnormal.z;
[edited by - adam17 on May 26, 2004 9:29:00 PM]

Share this post

Link to post
Share on other sites