pattern.cpp 733 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Pattern implementation
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <pattern.h>
  10. #include <shape.h>
  11. Pattern::Pattern(Colour a, Colour b): a(a), b(b)
  12. {
  13. this->transformMatrix = Matrix4().identity();
  14. this->inverseTransform = this->transformMatrix.inverse();
  15. };
  16. Colour Pattern::patternAtObject(Shape *object, Tuple worldPoint)
  17. {
  18. Tuple objectPoint = object->inverseTransform * worldPoint;
  19. Tuple patternPoint = this->inverseTransform * objectPoint;
  20. return this->patternAt(patternPoint);
  21. }
  22. void Pattern::setTransform(Matrix transform)
  23. {
  24. this->transformMatrix = transform;
  25. this->inverseTransform = transform.inverse();
  26. }