pattern.cpp 1010 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. #include <stdio.h>
  12. Pattern::Pattern(Colour a, Colour b): a(a), b(b)
  13. {
  14. this->transformMatrix = Matrix4().identity();
  15. this->inverseTransform = this->transformMatrix.inverse();
  16. };
  17. Colour Pattern::patternAtObject(Shape *object, Tuple worldPoint)
  18. {
  19. Tuple objectPoint = object->worldToObject(worldPoint);
  20. Tuple patternPoint = this->inverseTransform * objectPoint;
  21. return this->patternAt(patternPoint);
  22. }
  23. void Pattern::setTransform(Matrix transform)
  24. {
  25. this->transformMatrix = transform;
  26. this->inverseTransform = transform.inverse();
  27. }
  28. void Pattern::dumpMe(FILE *fp)
  29. {
  30. fprintf(fp, "\"Colour A\": {\"red\": %f, \"green\": %f, \"blue\": %f},\n", this->a.x, this->a.y, this->a.z);
  31. fprintf(fp, "\"Colour B\": {\"red\": %f, \"green\": %f, \"blue\": %f},\n", this->b.x, this->b.y, this->b.z);
  32. }