ch9_test.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Render test for chapter 5 "Put it together".
  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 <transformation.h>
  18. int main()
  19. {
  20. /* First we need to construct the world */
  21. Plane floor = Plane();
  22. floor.material.colour = Colour(1, 0.9, 0.9);
  23. floor.material.specular = 0;
  24. Sphere middle = Sphere();
  25. middle.setTransform(translation(-0.5, 1, 0.5));
  26. middle.material.colour = Colour(0.1, 1, 0.5);
  27. middle.material.diffuse = 0.7;
  28. middle.material.specular = 0.3;
  29. Sphere right = Sphere();
  30. right.setTransform(translation(1.5, 0.5, -0.5) * scaling(0.5, 0.5, 0.5));
  31. right.material.colour = Colour(0.5, 1, 0.1);
  32. right.material.diffuse = 0.7;
  33. right.material.specular = 0.3;
  34. Sphere left = Sphere();
  35. left.setTransform(translation(-1.5, 0.33, -0.75) * scaling(0.33, 0.33, 0.33));
  36. left.material.colour = Colour(1, 0.8, 0.1);
  37. left.material.diffuse = 0.7;
  38. left.material.specular = 0.3;
  39. World w = World();
  40. w.addObject(&floor);
  41. w.addObject(&middle);
  42. w.addObject(&left);
  43. w.addObject(&right);
  44. /* Add light */
  45. Light light = Light(POINT_LIGHT, Point(-10, 10, -10), Colour(1, 1, 1));
  46. w.addLight(&light);
  47. /* Set the camera */
  48. Camera camera = Camera(100, 50, M_PI / 3);
  49. camera.setTransform(viewTransform(Point(0, 1.5, -5),
  50. Point(0, 1, 0),
  51. Vector(0, 1, 0)));
  52. /* Now render it */
  53. Canvas image = camera.render(w);
  54. image.SaveAsPNG("ch9_test.png");
  55. return 0;
  56. }