shape.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. SHAPE_PLANE,
  22. SHAPE_CUBE,
  23. SHAPE_CONE,
  24. };
  25. /* Base class for all object that can be presented in the world */
  26. class Shape
  27. {
  28. private:
  29. ShapeType type;
  30. private:
  31. virtual Intersect localIntersect(Ray r) = 0;
  32. virtual Tuple localNormalAt(Tuple point) = 0;
  33. public:
  34. Matrix transformMatrix;
  35. Matrix inverseTransform;
  36. Material material;
  37. public:
  38. Shape(ShapeType = SHAPE_NONE);
  39. Intersect intersect(Ray r);
  40. Tuple normalAt(Tuple point);
  41. void setTransform(Matrix transform);
  42. void setMaterial(Material material) { this->material = material; };
  43. Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
  44. Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
  45. bool operator==(const Shape &b) const { return this->material == b.material &&
  46. this->type == b.type &&
  47. this->transformMatrix == b.transformMatrix; };
  48. };
  49. #endif /* DORAYME_SHAPE_H */