• Advertisement

Archived

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

vertex normals

This topic is 5120 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

I'm calculating normals from a hiehgtmap for cubemapping... and when i render, the reflections dont connect at the polygons, so im assuming there is something wrong with my vertex normal calculation, here is the code:
v1 = m_points[polyCount][1] - m_points[polyCount][0];
				v2 = m_points[polyCount][2] - m_points[polyCount][0];
				normal = cross(v1, v2);
				normal = normalize(normal);

				glNormal3f(normal.x, normal.y, normal.z); glVertex3f(m_points[polyCount][0].x, m_points[polyCount][0].y, m_points[polyCount][0].z);	
				
				v1 = m_points[polyCount][2] - m_points[polyCount][1];
				v2 = m_points[polyCount][0] - m_points[polyCount][1];
				normal = cross(v1, v2);
				normal = normalize(normal);

				glNormal3f(normal.x, normal.y, normal.z); glVertex3f(m_points[polyCount][1].x, m_points[polyCount][1].y, m_points[polyCount][1].z);	
				
				v1 = m_points[polyCount][0] - m_points[polyCount][2];
				v2 = m_points[polyCount][1] - m_points[polyCount][2];
				normal = cross(v1, v2);
				normal = normalize(normal);

				glNormal3f(normal.x, normal.y, normal.z); glVertex3f(m_points[polyCount][2].x, m_points[polyCount][2].y, m_points[polyCount][2].z);	
				
				v1 = m_points[polyCount][2] - m_points[polyCount][0];
				v2 = m_points[polyCount][3] - m_points[polyCount][0];
				normal = cross(v1, v2);
				normal = normalize(normal);
				
				glNormal3f(normal.x, normal.y, normal.z); glVertex3f(m_points[polyCount][0].x, m_points[polyCount][0].y, m_points[polyCount][0].z);	
				
				v1 = m_points[polyCount][3] - m_points[polyCount][2];
				v2 = m_points[polyCount][0] - m_points[polyCount][2];
				normal = cross(v1, v2);
				normal = normalize(normal);

				glNormal3f(normal.x, normal.y, normal.z); glVertex3f(m_points[polyCount][2].x, m_points[polyCount][2].y, m_points[polyCount][2].z);	
				
				v1 = m_points[polyCount][0] - m_points[polyCount][3];
				v2 = m_points[polyCount][2] - m_points[polyCount][3];
				normal = cross(v1, v2);
				normal = normalize(normal);
				
				glNormal3f(normal.x, normal.y, normal.z); glVertex3f(m_points[polyCount][3].x, m_points[polyCount][3].y, m_points[polyCount][3].z);	
				polyCount++;
 
im drawing clockwise.... whats wrong with this!? [edited by - colinisinhere on April 14, 2004 6:42:47 PM] [edited by - colinisinhere on April 14, 2004 6:43:10 PM]

Share this post


Link to post
Share on other sites
Advertisement
Although I''d like to help, its often difficult and frustrating to offer assistance when a Code Block of Significant Size is just dumped into your post. Some members will even resort to flaming.

Let me see if I can be of any help without actually stepping through your code line by line. The first thing I''d ask is, have you done so? If you''re using an IDE with a debugger, step through the code very carefully and see if you can''t determine just where the problem lies.

If that doesn''t work, and you''ve exhausted all other resources at your disposal, maybe you could re-post your code, but comment it very thoroughly this time. That way whoever tries to help will be able to understand precisely what you''re trying to do.

Hope that helps.

****************************************

Brian Lacy
ForeverDream Studios

Comments? Questions? Curious?


"I create. Therefore I am."

Share this post


Link to post
Share on other sites
ive been working on this all day, but i have figured out the problem, now my question is... how can i calculate vertex normals without calculating the face normal first?

Share this post


Link to post
Share on other sites
Hmm...i remember doing a terrain generator and setting the terrain vertex normals.

My approach/conclusion was the following:

1) I calculated the vertex normals on loadtime since i couldnt efficiently calculate them each frame in runtime (atleast not the way i was doing it).

2) Vertex normals were sufficient...i didnt need to calculate surface normals. (why would you want that...anyone???)


.......

So, i simply calculated the vertex normals of every vertex in my terrain mesh. And to do that, i simply did a crossproduct of two vectors. simple, dirty, but it was sufficient to give the look i wanted.

Share this post


Link to post
Share on other sites

  • Advertisement