best way to compute vertex normals from a Triangle's list
- by nkint
hi
i'm a complete newbie in computergraphics so sorry if it's a stupid answer.
i'm trying to make a simple 3d engine from scratch, more for educational purpose than for real use.
i have a Surface object with inside a Triangle's list.
For now i compute normals inside Triangle class, in this way:
triangle.computeFaceNormals() {
Vec3D u = v1.sub(v3)
Vec3D v = v1.sub(v2)
Vec3D normal = Vec3D.cross(u,v)
normal.normalized()
this.n1 = this.n2 = this.n3 = normal
}
and when building surface:
t = new Triangle(v1,v2,v3).computeFaceNormals()
surface.addTriangle(t)
and i think this is the best way to do that.. isn't it?
now.. what about for vertex normals?
i've found this simple algorithm: flipcode vertex normal
but.. hei this algorithm has.. exponential complexity? (if my memory doesn't fail my computer science background..) (bytheway.. it has 3 nested loops.. i don't think it's the best way to do it..)
any suggestion?