uv_image.h 980 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * UV Image pattern header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_UV_IMAGE_H
  10. #define DORAYME_UV_IMAGE_H
  11. #include <stdint.h>
  12. #include <uv_pattern.h>
  13. #include <canvas.h>
  14. #include <tuple.h>
  15. class UVImage : public UVPattern
  16. {
  17. public:
  18. Canvas *image;
  19. UVImage(Canvas *image) : UVPattern(1, 1, Colour(0, 0, 0), Colour(0, 0, 0)),
  20. image(image) {};
  21. UVImage(const char *filepath) : UVPattern(1, 1, Colour(0, 0, 0), Colour(0, 0, 0)) {
  22. this->image = new Canvas(filepath);
  23. this->width = this->image->width;
  24. this->height = this->image->height;
  25. };
  26. Colour uvPatternAt(double u, double v) {
  27. v = 1 - v;
  28. double x = u * (this->image->width - 1);
  29. double y = v * (this->image->height - 1);
  30. Colour ret = this->image->getPixel(round(x), round(y));
  31. return ret;
  32. };
  33. };
  34. #endif /* DORAYME_UV_IMAGE_H */