Jump to content
  • Advertisement

Archived

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

AbeE

Vertex Normals

This topic is 6205 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 was wondering how I should approach this. I know what they are but not how to implement them. I have an array with all the vertices of my triangle strips, and have calculated the normals for each face (well, I made a normal for each set of 2 triangle strips, treating them more like a quad). Should I just run through this array checking for vertices that are equal for what. I just can''t think of specific code to accomplish this.

Share this post


Link to post
Share on other sites
Advertisement
Hey there, to get a vertex normal, you add the normals of all the faces that use that vertex, then normalize the result. I think you''ll find each vertex has 3 different faces whose normals need to be added and then normalised.

I may post some code later,

FatalXC

Share this post


Link to post
Share on other sites
I dunno if this works or not, because the 'land' in my game so far is flat, maybe some1 could tell me if this makes sense:

All my vertices are stored like this (bad I know but I'm a beginner)

numstrips_x[polynum][3];
numstrips_y[polynum][3];
numstrips_z[polynum][3];

Where polynum is the polygon number and the '3' represents 3 x,y,z coordinates for each polygon. I have already generated the face normals and transfered these face normals to each vertex on that face and stored this normal in
Norm_Vertex[Polynum][3]; '3' representing this time the normal at each of the 3 points on the polygon.

The following code I ain't sure about, basically what its MEANT to do is search for any points that are the same (therefore the normals at that point should added - normalised later)

for(int u=0; u < TotalPolygonNumber ; u++) //Loop through all polygons
{
for(int y=0; y < TotalPolygonNumber ; y++)
{
if( (((numstrips_x[u][0] == numstrips_x[y][0]) && (numstrips_y[u][0] == numstrips_y[y][0])) && (numstrips_z[u][0] == numstrips_z[y][0])) )
{
Norm_Vertex[u][0] += Norm_Vertex[y][0];
}

if( (((numstrips_x[u][1] == numstrips_x[y][1]) && (numstrips_y[u][1] == numstrips_y[y][1])) && (numstrips_z[u][1] == numstrips_z[y][1])) )
{
Norm_Vertex[u][1] += Norm_Vertex[y][1];
}

if( (((numstrips_x[u][2] == numstrips_x[y][2]) && (numstrips_y[u][2] == numstrips_y[y][2])) && (numstrips_z[u][2] == numstrips_z[y][2])) )
{
Norm_Vertex[u][2] += Norm_Vertex[y][2];
}

}
}

After this I just normalize the normals and assign them to their vertex? Sorry for being long winded' and complex.

Edited by - AbeE on June 26, 2001 10:55:48 AM

Share this post


Link to post
Share on other sites
How are you calculating your vertices from the faces? Are you using 3-plane intersection? If you are then vertex normals are easy. Just add the normals of the faces that intersect at the vertex then normalise the result.

You really should change your data formats to something nicer. Have a cVector class with all your vector operations, and a cFace class and a cPlane class etc... It will make everything so much easier. You could have my base classes if you want, they are a good starting platform.

If you need more explanation or if I''ve screwed something up, its no problem.

FatalXC

Share this post


Link to post
Share on other sites
Thanks, that''d be a great help, but I''ve got one minor problem left. I have gotten some type of lighting going, I think its per Vertex, it looks decent enough anyways I think for a first attempt. In fact I''ve gotten the whole terrain done and I''d love you to try it on your system some-time and tell me what kinda frame-rate you get. But before I show anyone I have 1 more question:
At certain areas on my terrain the frame-rate is alot higher than on others, and because of this the movement of the ''camera'' occurs quicker in some areas than others (it all depends on where you look!). Is there anyway I can fix this using the timer of something???
That''d be a great help
Thanks again.

Share this post


Link to post
Share on other sites
OK, frame rate fluctuations are normally due to overdraw. Doing frustrum culling will help, definitely have back face culling on (especially for a terrain engine!!) and implement a QuadTree for relatively flat terrain, else use an Octree. I''m not sure but maybe using an SBuffer would be good, there are some articles on www.flipcode.com. Alpha blending can also slow rendering down a lot, so don''t complain if thats whats causing it!! I hope I haven''t confused you more!!

I''ll send you my cVector, cVertex, cPlane, cCamera, cTiming, cPolygon classes and anything else i think might be useful!! They work pretty well and are not frame rate linked. What address should I use?

I''d love to see what you''ve made, my address is standingintheshadows@hotmail.com. I have an Athlon 800 and a GeForce 256 DDR.

Cheers,

FatalXC

Share this post


Link to post
Share on other sites
Sure, I''ll send it to you hopefully tomorrow, I just have a couple of things to do to it first.
See ya

Share this post


Link to post
Share on other sites
Hey FatalXC:
Could I give u the address of my website to download it off? It would save me emailing it on my crappy modem.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!