作业1涉及的知识点比较碎,有很多矩阵,需要回顾课程。比较烦的还是配环境,vscode环境配好了但连不上gdb进行debug…,但同份cmake, clion倒是可以debug…
坑点
这里说一个踩坑点。如果实现了进阶要求(绕某个轴旋转角度),会发现在绕x轴旋转到屏幕出界时,程序会崩溃。
排查了一下,发现是rasterizer.cpp
中的set_pixel
方法有问题,ind
越界了,所以程序直接crash掉,异常也捕不了。
所以需要加上越界判断,这下才算是完美实现了进阶要求。
void rst::rasterizer::set_pixel(const Eigen::Vector3f &point, const Eigen::Vector3f &color) {
//old index: auto ind = point.y() + point.x() * width;
if (point.x() < 0 || point.x() >= width ||
point.y() < 0 || point.y() >= height)
return;
int ind = (height - point.y()) * width + point.x();
if(ind >= frame_buf.size()) // 需要判断
return;
frame_buf[ind] = color;
}