1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
Eigen::Matrix4f get_model_matrix(float rotation_angle) { Eigen::Matrix4f model = Eigen::Matrix4f::Identity();
float angle = radian(rotation_angle); float cos_angle = cos(angle); float sin_angle = sin(angle); Eigen::Matrix4f rotation_matrix; rotation_matrix<<cos_angle,-sin_angle,0,0,sin_angle,cos_angle,0,0,0,0,1,0,0,0,0,1; model = rotation_matrix * model;
return model; }
Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar) { Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();
float half_height = tan(eye_fov/2*MY_PI/180)*zNear; float half_width = aspect_ratio*half_height; float t = half_height; float r = half_width; float b = -half_height; float l = -half_width; float n = -zNear; float f = -zFar; Eigen::Matrix4f S,T,M; S<< 2/(r-l),0,0,0, 0,2/(t-b),0,0, 0,0,2/(n-f),0, 0,0,0,1;
T<< 1,0,0,-(l+r)/2, 0,1,0,-(b+t)/2, 0,0,1,-(n+f)/2, 0,0,0,1; M<< zNear,0,0,0, 0,zNear,0,0, 0,0,zNear+zFar,-zFar*zNear, 0,0,1,0;
projection = S * T * M * projection; return projection; }
|