课程知识
- 复习课程
Lecture4, Lecture5
- MVP变换
Model,Viewing,Projection
M:给定位置,相当于照相时人站位
V:相机找角度
P:拍照
- 作业重点
Mpersp=Mortho·Mpersp→ortho
透视投影矩阵=正交投影矩阵 点乘 透视挤压正交矩阵
时间点 Lecture4 1:14:00
- FOV(field of view)
视场角,通过aspect(宽高比)=r/t和tan(fov/2)=t/|n|以及给定近端near远端far求其他值
时间点 Lecture5 12:00
- 其他知识点
Lecture4:绕轴旋转(10:20)
收获感悟
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.
//my code start
rotation_angle=rotation_angle/180*MY_PI;
model<<cos(rotation_angle),-sin(rotation_angle),0,0,//绕Z轴旋转公式
sin(rotation_angle),cos(rotation_angle),0,0,
0,0,1,0,
0,0,0,1;
//end
return model;
}
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.
//my code
Eigen::Matrix4f Mortho_translate=Eigen::Matrix4f::Identity();//平移
Eigen::Matrix4f Mortho_scale=Eigen::Matrix4f::Identity();//缩放
Eigen::Matrix4f Mo=Eigen::Matrix4f::Identity();//Mo是先平移到原点,再缩放,左乘后进行的变换
Eigen::Matrix4f Mpo=Eigen::Matrix4f::Identity();//Mp->o
float r,l,t,b;//右,左,上,下;近端远端已给出
float halfAngle=eye_fov/2/180*MY_PI;//半视场角
t=std::tan(halfAngle)*zNear;
r=aspect_ratio*t;
l=-r;
b=-t;
Mortho_translate<<1,0,0,-(r+l)/2,
0,1,0,-(t+b)/2,
0,0,1,-(zNear+zFar)/2,
0,0,0,1; //平移
Mortho_scale<<2/(r-l),0,0,0,
0,2/(t-b),0,0,
0,0,0,2/(zNear-zFar),
0,0,0,1; //缩放
Mo=Mortho_scale*Mortho_translate;
Mpo<<zNear,0,0,0,
0,zNear,0,0,
0,0,zNear+zFar,-zNear*zFar,
0,0,1,0;
projection=Mo*Mpo;
//end
return projection;
}