shape.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. bool dropShadow;
  38. public:
  39. Shape(ShapeType = SHAPE_NONE);
  40. Intersect intersect(Ray r);
  41. Tuple normalAt(Tuple point);
  42. void setTransform(Matrix transform);
  43. void setMaterial(Material material) { this->material = material; };
  44. Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
  45. Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
  46. bool operator==(const Shape &b) const { return this->material == b.material &&
  47. this->type == b.type &&
  48. this->transformMatrix == b.transformMatrix; };
  49. };
  50. #endif /* DORAYME_SHAPE_H */