shape.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. public:
  28. Matrix transformMatrix;
  29. Matrix inverseTransform;
  30. Material material;
  31. public:
  32. Shape(ShapeType = SHAPE_NONE);
  33. virtual Intersect intersect(Ray r);
  34. virtual Tuple normalAt(Tuple point);
  35. void setTransform(Matrix transform);
  36. void setMaterial(Material material) { this->material = material; };
  37. Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
  38. Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
  39. bool operator==(const Shape &b) const { return this->material == b.material &&
  40. this->type == b.type &&
  41. this->transformMatrix == b.transformMatrix; };
  42. };
  43. #endif /* DORAYME_SHAPE_H */