Skip to content

Commit

Permalink
Update get_projection_matrix()
Browse files Browse the repository at this point in the history
  • Loading branch information
WangSimiao2000 committed Dec 27, 2024
1 parent 024e9f1 commit fb7ace5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion _posts/2024-12-26-GAMES101-Assignment3.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ tags: [GAMES101, 着色]

我的所有GAMES101作业的仓库地址: [GAMES101-Assignments](https://github.com/WangSimiao2000/GAMES101-Assignments)

## 投影矩阵修改

> 之前的投影矩阵感觉有点问题, 这里重新实现一下
修改main.cpp中的get_projection_matrix()函数, 实现投影矩阵的计算:

```cpp
Eigen::Matrix4f projection;
float top = -tan(DEG2RAD(eye_fov/2.0f) * abs(zNear));
float right = top * aspect_ratio;
projection << zNear/right,0,0,0,
0,zNear/top,0,0,
0,0,(zNear+zFar)/(zNear-zFar),(2*zNear*zFar)/(zFar-zNear),
0,0,1,0;
return projection;
```
然后在gloabl.h中添加一个宏定义:
```cpp
inline double DEG2RAD(double deg) {return deg * MY_PI/180;}
```

以上定义是为了将角度(deg)转换为弧度(rad), 以便在计算投影矩阵时使用

## 实现法向量、颜色、纹理颜色的插值

> 对应pdf任务1,2
Expand Down Expand Up @@ -106,7 +131,7 @@ void rst::rasterizer::rasterize_triangle(const Triangle& t, const std::array<Eig
}
```
此外, 还需要将前两次作业的投影矩阵的计算代码复制到此项目的main.cpp的get_projection_matrix()函数中, 以便在rasterizer.cpp中调用
此时可以在build目录的Debug文件夹下运行项目:
Expand Down
Binary file modified assets/posts/GAMES101-Assignment3/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/posts/GAMES101-Assignment3/phong.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fb7ace5

Please sign in to comment.