Triangle.cpp 595 B

12345678910111213141516171819202122
  1. #include "client/rendering/Triangle.h"
  2. Triangle::Triangle() {
  3. }
  4. Triangle::Triangle(const Vertex& a, const Vertex& b, const Vertex& c) : a(a), b(b), c(c) {
  5. Vector3 ab = b.position - a.position;
  6. Vector3 ac = c.position - a.position;
  7. normalA = ab.cross(ac);
  8. normalB = normalA;
  9. normalC = normalA;
  10. Vector2 abt = b.texture - a.texture;
  11. Vector2 act = c.texture - a.texture;
  12. float f = 1.0f / (abt[0] * act[1] - act[0] * abt[1]);
  13. tangentA = f * (act[1] * ab - abt[1] * ac);
  14. tangentA.normalize();
  15. tangentB = tangentA;
  16. tangentC = tangentA;
  17. }