ch15_teapot_objfile.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Render test for OBJ File using teapots in chapter 15.
  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 <plane.h>
  12. #include <material.h>
  13. #include <colour.h>
  14. #include <canvas.h>
  15. #include <camera.h>
  16. #include <objfile.h>
  17. #include <pattern.h>
  18. #include <strippattern.h>
  19. #include <gradientpattern.h>
  20. #include <checkerspattern.h>
  21. #include <ringpattern.h>
  22. #include <transformation.h>
  23. int main()
  24. {
  25. World w = World();
  26. /* Add lights */
  27. Light light1 = Light(POINT_LIGHT, Point(50, 100, 20), Colour(.5, .5, .5));
  28. w.addLight(&light1);
  29. Light light2 = Light(POINT_LIGHT, Point(2, 50, 100), Colour(.5, .5, .5));
  30. w.addLight(&light2);
  31. /* ----------------------------- */
  32. /* Floor */
  33. Plane p = Plane();
  34. CheckersPattern checkered = CheckersPattern(Colour(0.35, 0.35, 0.35), Colour(0.4, 0.4, 0.4));
  35. p.material.pattern = &checkered;
  36. p.material.ambient = 1;
  37. p.material.diffuse = 0;
  38. p.material.specular = 0;
  39. p.material.reflective = 0.1;
  40. w.addObject(&p);
  41. Plane p2 = Plane();
  42. p2.setTransform(translation(0, 0, -10) * rotationX(M_PI/2));
  43. p2.material.pattern = &checkered;
  44. p2.material.ambient = 1;
  45. p2.material.diffuse = 0;
  46. p2.material.specular = 0;
  47. w.addObject(&p2);
  48. OBJFile teapot = OBJFile("teapot-low.obj");
  49. teapot.setTransform(translation(7, 0, 3) * rotationY(M_PI*23/22) * rotationX(-M_PI/2) * scaling(0.3, 0.3, 0.3));
  50. teapot.material.colour = Colour(1, 0.3, 0.2);
  51. teapot.material.shininess = 5;
  52. teapot.material.specular = 0.4;
  53. w.addObject(&teapot);
  54. OBJFile teapot2 = OBJFile("teapot-lowtri.obj");
  55. teapot2.setTransform(translation(-7, 0, 3) * rotationY(-M_PI*46/22) * rotationX(-M_PI/2) * scaling(0.3, 0.3, 0.3));
  56. teapot2.material.colour = Colour(1, 0.3, 0.2);
  57. teapot2.material.shininess = 5;
  58. teapot2.material.specular = 0.4;
  59. w.addObject(&teapot2);
  60. OBJFile teapot3= OBJFile("teapot.obj");
  61. teapot3.setTransform(translation(0, 0, -5) * rotationY(-M_PI) * rotationX(-M_PI/2) * scaling(0.4, 0.4, 0.4));
  62. teapot3.material.colour = Colour(0.3, 1, 0.2);
  63. teapot3.material.shininess = 5;
  64. teapot3.material.specular = 0.4;
  65. teapot3.material.reflective = 0.5;
  66. w.addObject(&teapot3);
  67. /* ----------------------------- */
  68. /* Set the camera */
  69. Camera camera = Camera(80, 40, M_PI/2);
  70. camera.setTransform(viewTransform(Point(0, 7, 13),
  71. Point(0, 1, 0),
  72. Vector(0, 1, 0)));
  73. /* Now render it */
  74. Canvas image = camera.render(w, 5);
  75. image.SaveAsPNG("ch15_teapot_objfile.png");
  76. return 0;
  77. }