ch7_test.cpp 2.3 KB

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