Assignment01

作业文档:Assignment01

给定程序框架,完成以下任务:

image-20260430092420704

完成时候的一些注意事项:

  1. 在绝大部分数学库中,三角函数和后续计算所需的角均以弧度制表示,如果入参为角度制,需要转换为弧度制。
  2. 计算透视矩阵时,除了标准的透视矩阵,还要对每个值进行归一化处理,以将结果统一到标准化设备坐标系(NDC)中。

实现代码:

get_model_matrix(float rotation_angle)
Eigen::Matrix4f get_model_matrix(float rotation_angle)
{
    //初始化一个4*4的单位矩阵
    Eigen::Matrix4f model = Eigen::Matrix4f::Identity();
    float radian = rotation_angle / 180.f * MY_PI;

    // TODO: Implement this function
    // Create the model matrix for rotating the triangle around the Z axis.
    // Then return it.

    model << cos(radian), -sin(radian), 0, 0,
        sin(radian), cos(radian), 0, 0,
        0, 0, 1, 0,
        0, 0, 0, 1;

    return model;
}
get_projection_matrix(float eye_fov, float aspect_ratio,float zNear, float zFar)
Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio,
                                      float zNear, float zFar)
{
    // Students will implement this function
    Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();

    // TODO: Implement this function
    // Create the projection matrix for the given parameters.
    // Then return it.

    projection(0, 0) = 1 / (aspect_ratio * tan(eye_fov / 180.0f * MY_PI / 2));
    projection(1, 1) = 1 / (tan(eye_fov / 180.0f * MY_PI / 2));
    projection(2, 2) = (zNear + zFar) / (zNear - zFar);
    projection(2, 3) = 2 * zNear * zFar / (zNear - zFar);
    projection(3, 2) = -1;
    projection(3, 3) = 0;

    projection(0, 3) = 0;
    projection(1, 3) = 0;

    return projection;
}