TriMesh.cpp 664 B

1234567891011121314151617181920212223242526
  1. // This code is in the public domain -- Ignacio Castaño <castano@gmail.com>
  2. #include "TriMesh.h"
  3. using namespace nv;
  4. /// Triangle mesh.
  5. Vector3 TriMesh::faceNormal(uint f) const
  6. {
  7. const Face & face = this->faceAt(f);
  8. const Vector3 & p0 = this->vertexAt(face.v[0]).pos;
  9. const Vector3 & p1 = this->vertexAt(face.v[1]).pos;
  10. const Vector3 & p2 = this->vertexAt(face.v[2]).pos;
  11. return normalizeSafe(cross(p1 - p0, p2 - p0), Vector3(0.0f), 0.0f);
  12. }
  13. /// Get face vertex.
  14. const TriMesh::Vertex & TriMesh::faceVertex(uint f, uint v) const
  15. {
  16. nvDebugCheck(v < 3);
  17. const Face & face = this->faceAt(f);
  18. return this->vertexAt(face.v[v]);
  19. }