Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rendu par lancer de rayon
- vec3* scene::intersectPrimitive(int h_img, int w_img, vec3 pixels[], vec3 oCamera, float fov) {
- vec3 origine(0, 0, 0);
- vec3 direction(0, 0, 0);
- vec3 pixelNull(0, 0, 0);
- for (int i = 0; i < h_img; i++) {
- for (int j = 0; j < w_img; j++) {
- direction.set_x(j - (w_img / 2));
- direction.set_y(i - (h_img / 2));
- direction.set_z(-(w_img / (2 * tan(fov / 2))));
- ray r(origine, direction.normalizedVecteur());
- float distance, distanceMin=100000;
- bool intersection=false;
- vec3 couleurSphere(0,0,0);
- for (int k = 0; k < nbPrimitive - 1; k++) {
- distance = tabSphere[k].intersect(r);
- if (distance > 0) {
- intersection = true;
- if (distance < distanceMin) {
- distanceMin = distance;
- couleurSphere.set_x(tabSphere[k].get_couleur().get_x());
- couleurSphere.set_y(tabSphere[k].get_couleur().get_y());
- couleurSphere.set_z(tabSphere[k].get_couleur().get_z());
- }
- }
- }
- if (intersection) {
- pixels[(i*w_img) + j] = couleurSphere;
- }
- else {
- pixels[(i*w_img) + j] = pixelNull;
- }
- }
- }
- return pixels;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement