shape.h 1.4 KB

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