smoothtriangle.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Smooth Triangle implementation
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <ray.h>
  10. #include <shape.h>
  11. #include <triangle.h>
  12. #include <smoothtriangle.h>
  13. #include <math_helper.h>
  14. #include <renderstat.h>
  15. SmoothTriangle::SmoothTriangle(Point p1, Point p2, Point p3, Vector n1, Vector n2, Vector n3) : Triangle(p1, p2, p3),
  16. n1(n1), n2(n2), n3(n3)
  17. {
  18. this->type = Shape::SMOOTHTRIANGLE;
  19. stats.addSmoothTriangle();
  20. }
  21. Tuple SmoothTriangle::localNormalAt(Tuple point, Intersection *hit)
  22. {
  23. return (this->n2 * hit->u +
  24. this->n3 * hit->v +
  25. this->n1 * (1 - hit->u - hit->v)).normalise();
  26. }
  27. void SmoothTriangle::dumpMe(FILE *fp)
  28. {
  29. Tuple t = this->n1;
  30. fprintf(fp, "\"n1\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
  31. t.x, t.y, t.z);
  32. t = this->n2;
  33. fprintf(fp, "\"n2\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
  34. t.x, t.y, t.z);
  35. t = this->n3;
  36. fprintf(fp, "\"n3\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
  37. t.x, t.y, t.z);
  38. Triangle::dumpMe(fp);
  39. }