uvmap_skybox.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Skybox test for bonus chapter UV Mapping
  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 <pattern.h>
  20. #include <texturemap.h>
  21. #include <uv_image.h>
  22. #include <transformation.h>
  23. int main()
  24. {
  25. World w = World();
  26. Light light = Light(POINT_LIGHT, Point(0, 100, 0), Colour(1, 1, 1));
  27. w.addLight(&light);
  28. Sphere sp = Sphere();
  29. sp.setTransform(translation(0, 0, 5) * scaling(0.75, 0.75, 0.75));
  30. sp.material.diffuse = 0.4;
  31. sp.material.specular = 0.6;
  32. sp.material.shininess = 20;
  33. sp.material.reflective = 0.6;
  34. sp.material.ambient = 0;
  35. w.addObject(&sp);
  36. UVImage left = UVImage("negx.jpg");
  37. UVImage right = UVImage("posx.jpg");
  38. UVImage front = UVImage("posz.jpg");
  39. UVImage back = UVImage("negz.jpg");
  40. UVImage up = UVImage("posy.jpg");
  41. UVImage down = UVImage("negy.jpg");
  42. Cube cb = Cube();
  43. TextureMap tm = TextureMap(CUBIC_MAP, nullptr);
  44. tm.setCubePattern(&front, &left, &right, &back, &up, &down);
  45. cb.material.pattern = &tm;
  46. cb.material.diffuse = 0;
  47. cb.material.specular = 0;
  48. cb.material.ambient = 1;
  49. cb.setTransform(scaling(1000, 1000, 1000));
  50. w.addObject(&cb);
  51. /* Set the camera */
  52. Camera camera = Camera(800, 400, 1.2);
  53. camera.setTransform(viewTransform(Point(0, 0, 0),
  54. Point(0, 0, 5),
  55. Vector(0, 1, 0)));
  56. /* Now render it */
  57. Canvas image = camera.render(w);
  58. image.SaveAsPNG("uvmap_skybox.png");
  59. return 0;
  60. }