shape.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Object header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_SHAPE_H
  10. #define DORAYME_SHAPE_H
  11. class Shape;
  12. #include <ray.h>
  13. #include <tuple.h>
  14. #include <matrix.h>
  15. #include <intersect.h>
  16. #include <material.h>
  17. enum ShapeType
  18. {
  19. SHAPE_NONE,
  20. SHAPE_SPHERE,
  21. };
  22. /* Base class for all object that can be presented in the world */
  23. class Shape
  24. {
  25. private:
  26. ShapeType type;
  27. private:
  28. virtual Intersect localIntersect(Ray r) = 0;
  29. virtual Tuple localNormalAt(Tuple point) = 0;
  30. public:
  31. Matrix transformMatrix;
  32. Matrix inverseTransform;
  33. Material material;
  34. public:
  35. Shape(ShapeType = SHAPE_NONE);
  36. Intersect intersect(Ray r);
  37. Tuple normalAt(Tuple point);
  38. void setTransform(Matrix transform);
  39. void setMaterial(Material material) { this->material = material; };
  40. Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
  41. Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
  42. bool operator==(const Shape &b) const { return this->material == b.material &&
  43. this->type == b.type &&
  44. this->transformMatrix == b.transformMatrix; };
  45. };
  46. #endif /* DORAYME_SHAPE_H */