uvmap_earth.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Earth globe render 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 <cylinder.h>
  14. #include <material.h>
  15. #include <colour.h>
  16. #include <canvas.h>
  17. #include <camera.h>
  18. #include <pattern.h>
  19. #include <texturemap.h>
  20. #include <uv_image.h>
  21. #include <transformation.h>
  22. int main()
  23. {
  24. World w = World();
  25. Light light = Light(POINT_LIGHT, Point(-100, 100, -100), Colour(1, 1, 1));
  26. w.addLight(&light);
  27. Plane p = Plane();
  28. p.material.colour = Colour(1, 1, 1);
  29. p.material.diffuse = 0.1;
  30. p.material.specular = 0;
  31. p.material.ambient = 0;
  32. p.material.reflective = 0.4;
  33. w.addObject(&p);
  34. Cylinder cyl = Cylinder();
  35. cyl.minCap = 0;
  36. cyl.maxCap = 0.1;
  37. cyl.isClosed = true;
  38. cyl.material.colour = Colour(1, 1, 1);
  39. cyl.material.diffuse = 0.2;
  40. cyl.material.specular = 0;
  41. cyl.material.ambient = 0;
  42. cyl.material.reflective = 0.1;
  43. w.addObject(&cyl);
  44. Sphere sp = Sphere();
  45. UVImage sphereTexture = UVImage("earthmap1k.png");
  46. TextureMap tm = TextureMap(SPHERICAL_MAP, &sphereTexture);
  47. sp.setTransform(translation(0, 1.1, 0) * rotationY(1.9));
  48. sp.material.pattern = &tm;
  49. sp.material.ambient = 0.1;
  50. sp.material.specular = 0.1;
  51. sp.material.shininess = 10;
  52. sp.material.diffuse = 0.9;
  53. w.addObject(&sp);
  54. /* Set the camera */
  55. Camera camera = Camera(800, 400, 0.8);
  56. camera.setTransform(viewTransform(Point(1, 2, -10),
  57. Point(0, 1.1, 0),
  58. Vector(0, 1, 0)));
  59. /* Now render it */
  60. Canvas image = camera.render(w);
  61. image.SaveAsPNG("uvmap_earth.png");
  62. return 0;
  63. }