shape.h 1.5 KB

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