intersection.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Intersection header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_INTERSECTION_H
  10. #define DORAYME_INTERSECTION_H
  11. #include <stdlib.h>
  12. #include <ray.h>
  13. #include <material.h>
  14. #include <renderstat.h>
  15. class Shape;
  16. class Intersect;
  17. struct Computation
  18. {
  19. Computation(Shape *object, double t, Tuple point, Tuple eyev, Tuple normalv, Tuple overHitP,
  20. bool inside, Tuple reflectV = Vector(0, 0, 0), double n1 = 1.0, double n2 = 1.0,
  21. Tuple underHitP = Point(0, 0, 0), Material *objMat = nullptr) :
  22. object(object), t(t), hitPoint(point), eyeVector(eyev), normalVector(normalv), inside(inside),
  23. overHitPoint(overHitP), underHitPoint(underHitP), reflectVector(reflectV), n1(n1), n2(n2), material(objMat) { };
  24. double schlick();
  25. Shape *object;
  26. double t;
  27. Tuple hitPoint;
  28. Tuple overHitPoint;
  29. Tuple underHitPoint;
  30. Tuple eyeVector;
  31. Tuple normalVector;
  32. Tuple reflectVector;
  33. Material *material;
  34. double n1;
  35. double n2;
  36. bool inside;
  37. };
  38. class Intersection
  39. {
  40. public:
  41. double t;
  42. Shape *object;
  43. double u, v;
  44. public:
  45. Intersection(double t, Shape *object, double u = NAN, double v = NAN) : t(t), object(object), u(u), v(v) { stats.addIntersection(); };
  46. bool nothing() { return (this->object == nullptr); };
  47. Computation prepareComputation(Ray r, Intersect *xs = nullptr);
  48. bool operator==(const Intersection &b) const { return ((this->t == b.t) && (this->object == b.object)); };
  49. };
  50. #endif /* DORAYME_INTERSECTION_H */