# Normal question

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

## Recommended Posts

If I had a quad which consists of 2 tris, when I work out their face normals, why one would face up, the other face down?

	DWORD numVerts = pMesh->GetNumVertices();
DWORD numTris = pMesh->GetNumFaces();
VertexPN* v = NULL;
DWORD* id = NULL;
std::vector<VertexPN> verts;
pMesh->LockVertexBuffer(0, (void**)&v);
for (int i = 0; i < numVerts; i++)
{
const VertexPN& _v = v;
verts.push_back(_v);
}
pMesh->UnlockVertexBuffer();
pMesh->LockIndexBuffer(0, (void**)&id);
for (int i = 0; i < numTris; i++)
{
const VertexPN& v0 = verts[id[i*3+0]];
const VertexPN& v1 = verts[id[i*3+1]];
const VertexPN& v2 = verts[id[i*3+2]];
D3DXVECTOR3 faceNormal;
D3DXVec3Cross(&faceNormal, &v0.pos, &v1.pos);
if (faceNormal.y > 0)
{
TRACE("Face #" << i << " is up" << "\n");
ChangeAttrib(i, 246);

}
TRACE("Face #: " << i << " normal is y:" << faceNormal.y << "\n");
}
pMesh->UnlockIndexBuffer();

Edited by lucky6969b

##### Share on other sites

If you've searched, you would find that normals aren't calculated like that.

You take a=v1-v0 and b=v2-v0 and use a and b for calculating the normal.

##### Share on other sites

Without looking at the code, it likely means you assume the wrong winding order for one of the tris. Just change the order in which you do the cross-product for the incorrect triangle (i assume you use backface-cullling, so the tri should be correct per se; if not just fix that.

Yep,

Thanks

Jack

##### Share on other sites

When showing source code in public, it may be beneficial to ensure that your indentation is consistent.

You seem to have a wild mixture of four spaces and four-wide tabs that expand very poorly in a eight-wide tab world. You may want to invest in a source code formatter or an IDE that unscrews your indentation.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 20
• 36
• 9
• 16