uvmap_checkeredsphere.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Checkered sphere 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 <material.h>
  14. #include <colour.h>
  15. #include <canvas.h>
  16. #include <camera.h>
  17. #include <pattern.h>
  18. #include <texturemap.h>
  19. #include <uv_checkers.h>
  20. #include <transformation.h>
  21. int main()
  22. {
  23. World w = World();
  24. Light light = Light(POINT_LIGHT, Point(-10, 10, -10), Colour(1, 1, 1));
  25. w.addLight(&light);
  26. Sphere sp = Sphere();
  27. UVCheckers checkers = UVCheckers(20, 10, Colour(0, 0.5, 0), Colour(1, 1, 1));
  28. TextureMap tm = TextureMap(SPHERICAL_MAP, &checkers);
  29. sp.material.pattern = &tm;
  30. sp.material.ambient = 0.1;
  31. sp.material.specular = 0.4;
  32. sp.material.shininess = 10;
  33. sp.material.diffuse = 0.6;
  34. w.addObject(&sp);
  35. /* Set the camera */
  36. Camera camera = Camera(400, 400, 0.5);
  37. camera.setTransform(viewTransform(Point(0, 0, -5),
  38. Point(0, 0, 0),
  39. Vector(0, 1, 0)));
  40. /* Now render it */
  41. Canvas image = camera.render(w);
  42. image.SaveAsPNG("uvmap_checkeredsphere.png");
  43. return 0;
  44. }