arealight_test.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Render test for reflection in chapter 13.
  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 <cube.h>
  14. #include <cylinder.h>
  15. #include <material.h>
  16. #include <colour.h>
  17. #include <canvas.h>
  18. #include <camera.h>
  19. #include <group.h>
  20. #include <cone.h>
  21. #include <pattern.h>
  22. #include <strippattern.h>
  23. #include <gradientpattern.h>
  24. #include <checkerspattern.h>
  25. #include <ringpattern.h>
  26. #include <transformation.h>
  27. int main()
  28. {
  29. World w = World();
  30. /* Add lights */
  31. #if 0
  32. Light light1 = Light(AREA_LIGHT, Point(-1, 2, 4),
  33. Vector(2, 0, 0), 8,
  34. Vector(0, 2, 0), 8,
  35. //jitter,
  36. Colour(1.5, 1.5, 1.5));
  37. #else
  38. Light light1 = Light(POINT_LIGHT, Point(-1, 2, 4), Colour(1.5,1.5,1.5));
  39. #endif
  40. w.addLight(&light1);
  41. /* ----------------------------- */
  42. /* Cube that pretend to be the light */
  43. Cube c = Cube();
  44. c.material.colour = Colour(1.5, 1.5, 1.5);
  45. c.material.ambient = 1;
  46. c.material.diffuse = 0;
  47. c.material.specular = 0;
  48. c.dropShadow = false;
  49. c.setTransform(translation(0, 3, 4) * scaling(1, 1, 0.01));
  50. w.addObject(&c);
  51. Plane p = Plane();
  52. p.material.colour = Colour(1, 1, 1);
  53. p.material.ambient = 0.025;
  54. p.material.diffuse = 0.67;
  55. p.material.specular = 0;
  56. w.addObject(&p);
  57. Sphere s1 = Sphere();
  58. s1.setTransform(translation(0.5, 0.5,0) * scaling(0.5, 0.5, 0.5));
  59. s1.material.colour = Colour(1, 0, 0);
  60. s1.material.ambient = 0.1;
  61. s1.material.specular = 0;
  62. s1.material.diffuse = 0.6;
  63. s1.material.reflective = 0.3;
  64. w.addObject(&s1);
  65. Sphere s2 = Sphere();
  66. s2.setTransform(translation(-0.25, 0.33,0) * scaling(0.33, 0.33, 0.33));
  67. s2.material.colour = Colour(0.5, 0.5, 1);
  68. s2.material.ambient = 0.1;
  69. s2.material.specular = 0;
  70. s2.material.diffuse = 0.6;
  71. s2.material.reflective = 0.3;
  72. w.addObject(&s2);
  73. /* ----------------------------- */
  74. /* Set the camera */
  75. //Camera camera = Camera(400, 160, 0.7854);
  76. Camera camera = Camera(800, 320, 0.7854);
  77. camera.setTransform(viewTransform(Point(-3, 1, 2.5),
  78. Point(0, 0.5, 0),
  79. Vector(0, 1, 0)));
  80. /* Now render it */
  81. Canvas image = camera.render(w, 5);
  82. image.SaveAsPNG("arealight_test.png");
  83. return 0;
  84. }