Jump to content
  • Advertisement

Archived

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

adam17

problem with generating normals

This topic is 5141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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};

		normal.resize(36*3);
		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
Advertisement
For one, you are missing normal normalization.

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!