float scale = tan(deg2rad(scene.fov * 0.5)); float imageAspectRatio = scene.width / (float)scene.height; Vector3f eye_pos(-1, 5, 10); int m = 0; for (uint32_t j = 0; j < scene.height; ++j) { for (uint32_t i = 0; i < scene.width; ++i) { // generate primary ray direction float x = (2 * (i + 0.5) / (float)scene.width - 1) * imageAspectRatio * scale; float y = (1 - 2 * (j + 0.5) / (float)scene.height) * scale; // TODO: Find the x and y positions of the current pixel to get the // direction // vector that passes through it. // Also, don't forget to multiply both of them with the variable // *scale*, and x (horizontal) variable with the *imageAspectRatio* // x = (2 * (i + 0.5f) / (float)(scene.width-1) - 1) * imageAspectRatio * scale; // y = (1 - 2 * (j + 0.5f) / (float)(scene.height-1)) * scale;
/*作业6添加部分*/ Vector3f dir = Vector3f(x, y, -1); // Don't forget to normalize this direction! Ray ray(eye_pos, normalize(dir)); framebuffer[m++] = scene.castRay(ray, 0); /*作业6添加部分*/