Games101 作业5 光线与三角形相交

这篇博客介绍了光线与三角形相交的计算方法,包括如何生成光线以及求解交点。作业中提到在Windows环境下需要修改CMakeLists.txt以避免编译问题。作者建议通过RayTracingInOneWeekend进一步学习,并展示了通过增加采样数减少锯齿效果的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学霸笔记

       如果是使用 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 / 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值