uv_checkers.h 688 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * UV Checkers header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_UV_CHECKERS_H
  10. #define DORAYME_UV_CHECKERS_H
  11. #include <uv_pattern.h>
  12. #include <math.h>
  13. class UVCheckers : public UVPattern
  14. {
  15. public:
  16. UVCheckers(double width, double height, Colour a, Colour b) : UVPattern(width, height, a, b) {};
  17. Colour uvPatternAt(double u, double v) {
  18. double u2 = floor(u * this->width);
  19. double v2 = floor(v * this->height);
  20. if (modulo((u2 + v2), 2) == 0)
  21. {
  22. return this->a;
  23. }
  24. return this->b;
  25. };
  26. };
  27. #endif /* DORAYME_UV_CHECKERS_H */