uvmap_checkeredplane.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Checkered plane 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. Plane sp = Plane();
  27. UVCheckers checkers = UVCheckers(2, 2, Colour(0, 0.5, 0), Colour(1, 1, 1));
  28. TextureMap tm = TextureMap(PLANAR_MAP, &checkers);
  29. sp.material.pattern = &tm;
  30. sp.material.ambient = 0.1;
  31. sp.material.specular = 0;
  32. sp.material.diffuse = 0.9;
  33. w.addObject(&sp);
  34. /* Set the camera */
  35. Camera camera = Camera(400, 400, 0.5);
  36. camera.setTransform(viewTransform(Point(1, 2, -5),
  37. Point(0, 0, 0),
  38. Vector(0, 1, 0)));
  39. /* Now render it */
  40. Canvas image = camera.render(w);
  41. image.SaveAsPNG("uvmap_checkeredplane.png");
  42. return 0;
  43. }