Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. //Rendu par lancer de rayon
  2. vec3* scene::intersectPrimitive(int h_img, int w_img, vec3 pixels[], vec3 oCamera, float fov) {
  3. vec3 origine(0, 0, 0);
  4. vec3 direction(0, 0, 0);
  5. vec3 pixelNull(0, 0, 0);
  6. for (int i = 0; i < h_img; i++) {
  7. for (int j = 0; j < w_img; j++) {
  8. direction.set_x(j - (w_img / 2));
  9. direction.set_y(i - (h_img / 2));
  10. direction.set_z(-(w_img / (2 * tan(fov / 2))));
  11. ray r(origine, direction.normalizedVecteur());
  12. float distance, distanceMin=100000;
  13. bool intersection=false;
  14. vec3 couleurSphere(0,0,0);
  15. for (int k = 0; k < nbPrimitive - 1; k++) {
  16. distance = tabSphere[k].intersect(r);
  17. if (distance > 0) {
  18. intersection = true;
  19.  
  20. if (distance < distanceMin) {
  21. distanceMin = distance;
  22. couleurSphere.set_x(tabSphere[k].get_couleur().get_x());
  23. couleurSphere.set_y(tabSphere[k].get_couleur().get_y());
  24. couleurSphere.set_z(tabSphere[k].get_couleur().get_z());
  25. }
  26. }
  27. }
  28.  
  29. if (intersection) {
  30. pixels[(i*w_img) + j] = couleurSphere;
  31. }
  32. else {
  33. pixels[(i*w_img) + j] = pixelNull;
  34. }
  35. }
  36. }
  37.  
  38. return pixels;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement