Eigen::Matrix4f get_model_matrix(float rotation_angle){
Eigen::Matrix4f model = Eigen::Matrix4f::Identity();// 将角度转换为弧度,c++的函数用的都是弧度float radian = rotation_angle/180* MY_PI;// Create the model matrix for rotating the triangle around the Z axis.
Eigen::Matrix4f Trans_Model;
Trans_Model <<cos(radian),-sin(radian),0,0,sin(radian),cos(radian),0,0,0,0,1,0,0,0,0,1;
model = Trans_Model * model;return model;}
将模型映射到屏幕上
Eigen::Matrix4f get_projection_matrix(float eye_fov,float aspect_ratio,float zNear,float zFar){
Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();// TODO: Implement this function
Eigen::Matrix4f Trans_Ortho(4,4);
Eigen::Matrix4f Ortho_Trans(4,4);
Eigen::Matrix4f Ortho_Scale(4,4);float angle = eye_fov /180.0* MY_PI;auto t =tan(angle /2)*-zNear;//zFar is negativeauto r = t * aspect_ratio;auto l =-r;auto b =-t;// Create the projection matrix for the given parameters.
Trans_Ortho << zNear,0,0,0,0, zNear,0,0,0,0, zNear + zFar,-zNear * zFar,0,0,1,0;
Ortho_Scale <<2/(r - l),0,0,0,0,2/(t - b),0,0,0,0,2/(zNear - zFar),0,0,0,0,1;
Ortho_Trans <<1,0,0,-(r+l)/2,0,1,0,-(t+b)/2,0,0,1,-(zNear+zFar)/2,0,0,0,1;// Then return it.
Eigen::Matrix4f Ortho = Ortho_Scale * Ortho_Trans;
projection = Ortho * Trans_Ortho * projection;return projection;}