arealight_test.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. Light light1 = Light(AREA_LIGHT, Point(-1, 2, 4),
  32. Vector(2, 0, 0), 8,
  33. Vector(0, 2, 0), 8,
  34. Colour(1.5, 1.5, 1.5),
  35. true);
  36. w.addLight(&light1);
  37. /* ----------------------------- */
  38. /* Cube that pretend to be the light */
  39. Cube c = Cube();
  40. c.material.colour = Colour(1.5, 1.5, 1.5);
  41. c.material.ambient = 1;
  42. c.material.diffuse = 0;
  43. c.material.specular = 0;
  44. c.dropShadow = false;
  45. c.setTransform(translation(0, 3, 4) * scaling(1, 1, 0.01));
  46. w.addObject(&c);
  47. Plane p = Plane();
  48. p.material.colour = Colour(1, 1, 1);
  49. p.material.ambient = 0.025;
  50. p.material.diffuse = 0.67;
  51. p.material.specular = 0;
  52. w.addObject(&p);
  53. Sphere s1 = Sphere();
  54. s1.setTransform(translation(0.5, 0.5,0) * scaling(0.5, 0.5, 0.5));
  55. s1.material.colour = Colour(1, 0, 0);
  56. s1.material.ambient = 0.1;
  57. s1.material.specular = 0;
  58. s1.material.diffuse = 0.6;
  59. s1.material.reflective = 0.3;
  60. w.addObject(&s1);
  61. Sphere s2 = Sphere();
  62. s2.setTransform(translation(-0.25, 0.33,0) * scaling(0.33, 0.33, 0.33));
  63. s2.material.colour = Colour(0.5, 0.5, 1);
  64. s2.material.ambient = 0.1;
  65. s2.material.specular = 0;
  66. s2.material.diffuse = 0.6;
  67. s2.material.reflective = 0.3;
  68. w.addObject(&s2);
  69. /* ----------------------------- */
  70. /* Set the camera */
  71. Camera camera = Camera(40, 16, 0.7854);
  72. camera.setTransform(viewTransform(Point(-3, 1, 2.5),
  73. Point(0, 0.5, 0),
  74. Vector(0, 1, 0)));
  75. /* Now render it */
  76. Canvas image = camera.render(w, 5);
  77. image.SaveAsPNG("arealight_test.png");
  78. return 0;
  79. }