如果是使用 windows 跑代码的同学,需要把 CMakeLists.txt 下的两处 -fsanitize=undefined 关键字给去掉,才能正常编译。
本次作业非常简单,建议可以看看 RayTracingInOneWeekend 进一步学习。
光线生成
void Renderer::Render(const Scene& scene)
{
std::vector<Vector3f> framebuffer(scene.width * scene.height);
float scale = std::tan(deg2rad(scene.fov * 0.5f));
float imageAspectRatio = scene.width / (float)scene.height;
// Use this variable as the eye position to start your rays.
Vector3f eye_pos(0);
int m = 0;
for (int j = 0; j < scene.height; ++j)
{
for (int i = 0; i < scene.width; ++i)
{
// generate primary ray direction
float x;
float y;
// 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 = float(i / (scene.width - 1.0)) * 2 - 1;
y = (1 - float(j / (scene.height <