Calculating Vertex Normals

Started by
3 comments, last by GameDev.net 24 years, 5 months ago
There is a function "ComputeNormals" in d3dfile.cpp ( find it under d3dframe ) u can take it and modify it, I did that with my .LWO loader.
You will find the answer for your question in the first loop of that function , I completed my loader successfuly yesterday so u can ask me if have any troubles with the function
Advertisement
I don't have a "d3dfile.cpp" or anything like that in the d3dframe folder, or anywhere on my computer for that matter. I also searched through all the d3dframe files, none of them have any function like you described. help?
I have DX7 SDK which I downloaded from MS website the file is in c:\mssdk\samples\Multimedia\D3DIM\src\D3DFrame\d3dfile.cpp .
If u couldnt find it u can Email me or ICQ me on:
auday@softhome.net , ICQ 50534800
and I'll send it to u
Alright, I wrote a file loader for the caligari ".cob" file. It works pretty well, except cob files don't include vertex normals. Since I want to use the lighting engine of DirectX, i'm going to have to calculate these myself. So, here's where the problem starts. I know that if I could calculate all the face normals (the cross product of two edge vectors) surrounding a vertex, I could basically get the average of these and would then have a vertex normal. But when reading through a file, how am i going to know which faces surround each vertex?! Maybe I am not doing this correctly. Could someone explain therefore how I would calculate all the vertex normals? I have gotten all the vertices from the file and put them in order so that each face is in order too (as a set of three).
I'm not sure how objects are stored in .cob files, or if this is the "proper" way to do it. But for each object mesh, i'm storing a vertex list, with the polygon list storing pointers to the verticies in the vertex list.
After i've calculated all of the polygon normals, i calculate the vertex normal's by traversing through the vertex list, and comparing the address of the vertex with every vertex pointer stored by the polygons in the polygon list.

So once i find the polygons that point to this particular vertex, it's a simple matter of getting the weighted average of the polygon normals.

This topic is closed to new replies.

Advertisement