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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
Eigen::Matrix4f get_model_matrix(float rotation_angle) { float rotation_angle_rad = rotation_angle / 180.0 * MY_PI;
Eigen::Matrix4f model = Eigen::Matrix4f::Identity();
model << cos(rotation_angle_rad), -sin(rotation_angle_rad), 0, 0, sin(rotation_angle_rad), cos(rotation_angle_rad), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1;
return model; }
Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar) {
zNear = -zNear; zFar = -zFar; Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();
Eigen::Matrix4f M_persp; M_persp << zNear, 0, 0, 0, 0, zNear, 0, 0, 0, 0, zNear + zFar, -zNear*zFar, 0, 0, 1, 0;
float alpha = 0.5 * (eye_fov / 180.0f * MY_PI); float yTop = -zNear * std::tan(alpha); float yBottom = -yTop; float xRight = yTop * aspect_ratio; float xLeft = -xRight;
Eigen::Matrix4f M_trans; M_trans << 1, 0, 0, -(xLeft + xRight) / 2, 0, 1, 0, -(yTop + yBottom) / 2, 0, 0, 1, -(zNear + zFar) / 2, 0, 0, 0, 1;
Eigen::Matrix4f M_ortho; M_ortho << 2 / (xRight - xLeft), 0, 0, 0, 0, 2 / (yTop - yBottom), 0, 0, 0, 0, 2 / (zNear - zFar), 0, 0, 0, 0, 1;
M_ortho = M_ortho * M_trans;
projection = M_ortho * M_persp * projection;
return projection; }
Eigen::Matrix4f get_random_model_matrix(Eigen::Vector3f n,float rotation_angle) { Eigen::Matrix4f model = Eigen::Matrix4f::Identity(); Eigen::Matrix3f I = Eigen::Matrix3f::Identity(); float angle = rotation_angle / 180.0f * MY_PI ; float nx = n[0]; float ny = n[1]; float nz = n[2]; Eigen::Matrix3f N; N << 0, -nz, ny, nz, 0, -nx, -ny, nx, 0; Eigen::Matrix3f R = std::cos(angle) * I + (1 - std::cos(angle)) * n * n.transpose() + std::sin(angle) * N; model << R(0, 0), R(0, 1), R(0, 2), 0, R(1, 0), R(1, 1), R(1, 2), 0, R(2, 0), R(2, 1), R(2, 2), 0, 0, 0, 0, 1;
return model; }
|