Home › Forums › GAMES在线课程(现代计算机图形学入门)讨论区 › 作业1get_view_matrix函数可能没理解到位
- This topic has 4 replies, 4 voices, and was last updated 5 years, 10 months ago by
刘知安.
-
AuthorPosts
-
-
Vinal
ParticipantEigen::Matrix4f get_view_matrix(Eigen::Vector3f eye_pos)//把眼睛位置移到原点 { Eigen::Matrix4f view = Eigen::Matrix4f::Identity(); Eigen::Matrix4f translate; translate << 1, 0, 0, -eye_pos[0], 0, 1, 0, -eye_pos[1], 0, 0, 1, -eye_pos[2], 0, 0, 0, 1; view = translate * view; return view; }函数中有两个Matrix4f:view和translate。其中view就是个单位矩阵,感觉自始至终没发挥什么作用,就是和translate乘了一下。那么为啥不能直接return translate呢?或者view<<1, 0, 0, -eye_pos[0], 0, 1, 0, -eye_pos[1], 0, 0, 1,-eye_pos[2], 0, 0, 0, 1;再直接return view(不设置translate)呢?
感觉view和translate好像其中之一是多余的,不知道它们是否还有相关的联系、或者预留的功能?这可能是我没有理解到位的地方,谢谢!
-
我觉得这里是预留的功能,这次作业中没有特别设置相机角度,所以不需要rotate相机,只需要translate。
在之后有rotate之后,这里会改为 view=rotate*translate-
刘知安
Participant我对这里也有一点小疑惑,按照老师在课程中讲到的,view transformation应该是:
1. 先把相机位置e平移到原点;
2. 再把up direction 和 look-at direction分别旋转到y和-z轴。请问是不是在作业1里面只进行了第一步,而第二步尚未做?
-
-
Vinal
Participant作业里要填的函数也都有类似的写法,如get_model_matrix中第一行是
Eigen::Matrix4f model = Eigen::Matrix4f::Identity();
那这个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 r; r << cos(rotation_angle), -sin(rotation_angle), 0, 0, sin(rotation_angle), cos(rotation_angle), 0, 0, 0, 0, 1, 0, 0, 0, 1, 1; return r; }-
这样的确是可行的,因为对于这两个函数,变换矩阵只有一个,所以直接返回是可以的。
但是如果在函数中需要用到复合变换(比方设为先平移后旋转),那么就可以先对transformation矩阵赋值(平移),用model左乘transformation后再对transformation赋值(旋转),最后model再左乘transformation,这样就不需要定义多个变换矩阵,且看起来比较直观。-
This reply was modified 5 years, 10 months ago by
Shi YuChen(助教).
-
This reply was modified 5 years, 10 months ago by
Shi YuChen(助教).
-
This reply was modified 5 years, 10 months ago by
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.