zoukankan      html  css  js  c++  java
  • GAMES101 作业1 基础版 答案

    简介

    GAME101作业1的答案,基础版本,仅供参考,一直认为,没有标准版本和评级版本的作业没有必要做。所以希望分享我的观点。

    问题

    实现 MVP中的M和P矩阵的构建。
    get_model_matrix(float rotation_angle): 逐个元素地构建模型变换矩阵并返回该矩阵。在此函数中,你只需要实现三维中绕 z 轴旋转的变换矩阵,而不用处理平移与缩放。
    get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar): 使用给定的参数逐个元素地构建透视投影矩阵并返回该矩阵。

    关于model矩阵的构建&code

    model 在闫老师的课程上说的是,关于物品的摆放。

    Eigen::Matrix4f get_model_matrix(float rotation_angle)
    {
        Eigen::Matrix4f model = Eigen::Matrix4f::Identity();
    
        // TODO: Implement this function
        // Create the model matrix for rotating the triangle around the Z axis.
        // Then return it.
        Eigen::Matrix4f rotate;
        float radian = rotation_angle/180.0*MY_PI;
        rotate << cos(radian), -1*sin(radian), 0, 0,
                  sin(radian), cos(radian), 0, 0,
                  0, 0, 1, 0,
                  0, 0, 0, 1;//单纯实现了关于z轴的旋转矩阵
        model = rotate * model; 
        return model;
    }
    

    关于Projection 的构建 & code

    Projection 在闫老师的课程上说的是,将三维的物体映射为二维的物体

    /*
     * eye_fov 视野的大小
     * aspect_ratio  长宽比? 猜测是视野的长宽比率
     * zNear 最近处的坐标
     * zFar 最远处的坐标
     */
    Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio,
                                          float zNear, float zFar)
    {
        // Students will implement this function
        // TODO: Implement this function
        // Create the projection matrix for the given parameters.
        // Then return it.
        Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();
        Eigen::Matrix4f P2O = Eigen::Matrix4f::Identity();//将透视投影转换为正交投影的矩阵
        P2O<<zNear, 0, 0, 0,
             0, zNear, 0, 0,
             0, 0, zNear+zFar,(-1)*zFar*zNear,
             0, 0, 1, 0;// 进行透视投影转化为正交投影的矩阵
        float halfEyeAngelRadian = eye_fov/2.0/180.0*MY_PI;
        float t = zNear*std::tan(halfEyeAngelRadian);//top y轴的最高点
        float r=t*aspect_ratio;//right x轴的最大值
        float l=(-1)*r;//left x轴最小值
        float b=(-1)*t;//bottom y轴的最大值
        Eigen::Matrix4f ortho1=Eigen::Matrix4f::Identity();
        ortho1<<2/(r-l),0,0,0,
            0,2/(t-b),0,0,
            0,0,2/(zNear-zFar),0,
            0,0,0,1;//进行一定的缩放使之成为一个标准的长度为2的正方体
        Eigen::Matrix4f ortho2 = Eigen::Matrix4f::Identity();
        ortho2<<1,0,0,(-1)*(r+l)/2,
            0,1,0,(-1)*(t+b)/2,
            0,0,1,(-1)*(zNear+zFar)/2,
            0,0,0,1;// 把一个长方体的中心移动到原点
        Eigen::Matrix4f Matrix_ortho = ortho1 * ortho2;
        projection = Matrix_ortho * P2O;
        return projection;
    }
    

    测试样例

    Rasterizer -r 0/45/90


    QUESTION

    整个流程其实还是不是特别清楚

    [M_{persp} = M_{ortho}M_{persp->ortho} ]

    这个公式的作用输入输出是什么?
    GUESS:猜测 先将一个锥视图转为正交视图然后调用正交矩阵就可以得到相应的人类视觉的图片。

    参考资料

    viede https://www.bilibili.com/video/av90798049?p=4
    pdf https://sites.cs.ucsb.edu/~lingqi/teaching/resources/GAMES101_Lecture_04_supp.pdf

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    SSIS 学习之旅 FTP文件传输-脚本任务
    SSIS 学习之旅 FTP文件传输-FTP任务
    SSIS 学习之旅 数据同步
    SSIS 学习之旅 第一个SSIS 示例(二)
    SSIS 学习之旅 第一个SSIS 示例(一)(下)
    SSIS 学习之旅 第一个SSIS 示例(一)(上)
    图解 VS2015 如何打包winform 安装程序
    常用SQL Server 语句
    蓝桥杯 算法训练 Remember the A La Mode
    Competition in Swiss-system——2019CCPC哈尔滨 C题
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/12465518.html
Copyright © 2011-2022 走看看