Course Knowledge
- Review Materials
Lecture4, Lecture5
- MVP Transformation
Model, View, Projection
M: Positioning, like where a person stands when taking a photo
V: Camera angle selection
P: Capture operation
- Homework Key Points
Mpersp = Mortho · Mpersp→ortho
Perspective projection matrix = Orthographic projection matrix multiplied by Perspective-to-Orthographic matrix
Timestamp: Lecture4 1:14:00
- FOV (field of view)
Field of view angle, using aspect ratio = r/t and tan(fov/2) = t/|n|, along with near and far plane values to calculate other parameters
Timestamp: Lecture5 12:00
- Additional Topics
Lecture4: Rotation around an axis (10:20)
Experiences and Insights
- Attempted to configure the Windows development environment, referenced (Zhihu) GAMES101 course enviroment setup (Win10 + VSCode)
(CSDN) games101 [Homework 0] Environment Configuration - Windows Environment Setup
Bilibili (GAMES101 - Windows Homework Environment Configuration VSCode + CMake + MinGW)
Nearly succeeded but encountered issues with Eigen header file paths. After spending too much time debugging, decided to abandon this approach.
- Resolved the missing compiler issue when configuring CMake on Windows. After clicking configuration, selected the native option, set C compiler to mingw64/bin/gcc.exe, C++ compiler to mingw64/bin/g++.exe, left Fortran unselected. After errors apeared, clicked Add entry and selected the corresponding files. For details, search on Baidu.
- Minor issues during homework implemantation such as extra or missing matrix elements, incorrect matrix memory, and missing the provided MY_PI condition consumed significant time. The final result generated a rotating triangle, but it didn't meet the requirements in the assignment documentation regarding the make -r 20 command. The exact reason remains unclear.
Eigen::Matrix4f get_model_matrix(float rotation_angle)
{
Eigen::Matrix4f transformation = 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
float rad = rotation_angle / 180.0f * MY_PI;
transformation << cos(rad), -sin(rad), 0, 0, // Z-axis rotation formula
sin(rad), cos(rad), 0, 0,
0, 0, 1, 0,
0, 0, 0, 1;
//end
return transformation;
}
Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio,
float z_near, float z_far)
{
// Students will implement this function
Eigen::Matrix4f proj = Eigen::Matrix4f::Identity();
// TODO: Implement this function
// Create the projection matrix for the given parameters.
// Then return it.
//my code
Eigen::Matrix4f translate_mat = Eigen::Matrix4f::Identity(); // translation matrix
Eigen::Matrix4f scale_mat = Eigen::Matrix4f::Identity(); // scaling matrix
Eigen::Matrix4f ortho_mat = Eigen::Matrix4f::Identity(); // orthographic projection
Eigen::Matrix4f persp_to_ortho = Eigen::Matrix4f::Identity(); // perspective to orthographic
float right, left, top, bottom; // right, left, top, bottom bounds
float half_rad = eye_fov / 2.0f / 180.0f * MY_PI; // half field of view in radians
top = std::tan(half_rad) * z_near;
right = aspect_ratio * top;
left = -right;
bottom = -top;
translate_mat << 1, 0, 0, -(right + left) / 2,
0, 1, 0, -(top + bottom) / 2,
0, 0, 1, -(z_near + z_far) / 2,
0, 0, 0, 1; // translation to origin
scale_mat << 2 / (right - left), 0, 0, 0,
0, 2 / (top - bottom), 0, 0,
0, 0, 2 / (z_near - z_far), 0,
0, 0, 0, 1; // uniform scaling
ortho_mat = scale_mat * translate_mat;
persp_to_ortho << z_near, 0, 0, 0,
0, z_near, 0, 0,
0, 0, z_near + z_far, -z_near * z_far,
0, 0, 1, 0;
proj = ortho_mat * persp_to_ortho;
//end
return proj;
}