Compute and return the face normal (not normalized)
| 215 | |
| 216 | // Compute and return the face normal (not normalized) |
| 217 | Vector3 ConvexMesh::computeFaceNormal(uint32 faceIndex) const { |
| 218 | |
| 219 | Vector3 normal(0, 0, 0); |
| 220 | |
| 221 | const HalfEdgeStructure::Face& face = mHalfEdgeStructure.getFace(faceIndex); |
| 222 | assert(face.faceVertices.size() >= 3); |
| 223 | |
| 224 | // Use Newell's method to compute the face normal |
| 225 | for (uint32 i = face.faceVertices.size() - 1, j = 0; j < face.faceVertices.size(); i = j, j++) { |
| 226 | |
| 227 | const Vector3& v1 = getVertex(face.faceVertices[i]); |
| 228 | const Vector3& v2 = getVertex(face.faceVertices[j]); |
| 229 | |
| 230 | normal += Vector3((v1.y - v2.y) * (v1.z + v2.z), |
| 231 | (v1.z - v2.z) * (v1.x + v2.x), |
| 232 | (v1.x - v2.x) * (v1.y + v2.y)); |
| 233 | } |
| 234 | |
| 235 | return normal; |
| 236 | } |
| 237 | |
| 238 | // Return the minimum bounds of the mesh in the x,y,z direction |
| 239 | /** |