uvmap_checkeredcylinder.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Checkered cylinder for bonus chapter UV Mapping
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <world.h>
  10. #include <light.h>
  11. #include <sphere.h>
  12. #include <plane.h>
  13. #include <cylinder.h>
  14. #include <material.h>
  15. #include <colour.h>
  16. #include <canvas.h>
  17. #include <camera.h>
  18. #include <pattern.h>
  19. #include <texturemap.h>
  20. #include <uv_checkers.h>
  21. #include <transformation.h>
  22. int main()
  23. {
  24. World w = World();
  25. Light light = Light(POINT_LIGHT, Point(-10, 10, -10), Colour(1, 1, 1));
  26. w.addLight(&light);
  27. Cylinder sp = Cylinder();
  28. sp.minCap = 0;
  29. sp.maxCap = 1;
  30. sp.setTransform(scaling(1, 3.1415, 1) * translation(0, -0.5, 0));
  31. UVCheckers checkers = UVCheckers(16, 8, Colour(0, 0.5, 0), Colour(1, 1, 1));
  32. TextureMap tm = TextureMap(CYLINDRICAL_MAP, &checkers);
  33. sp.material.pattern = &tm;
  34. sp.material.ambient = 0.1;
  35. sp.material.specular = 0.6;
  36. sp.material.shininess = 15;
  37. sp.material.diffuse = 0.8;
  38. w.addObject(&sp);
  39. /* Set the camera */
  40. Camera camera = Camera(400, 400, 0.5);
  41. camera.setTransform(viewTransform(Point(0, 0, -10),
  42. Point(0, 0, 0),
  43. Vector(0, 1, 0)));
  44. /* Now render it */
  45. Canvas image = camera.render(w);
  46. image.SaveAsPNG("uvmap_checkeredcylinder.png");
  47. return 0;
  48. }