使用应用在箱子上的最后一个变换,尝试将其改变为先旋转,后位移。看看发生了什么,试着想想为什么会发生这样的事情
1 int main() 2 { 3 [...] 4 while(!glfwWindowShouldClose(window)) 5 { 6 [...] 7 // Create transformations 8 glm::mat4 transform; 9 transform = glm::rotate(transform, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f)); // Switched the order 10 transform = glm::translate(transform, glm::vec3(0.5f, -0.5f, 0.0f)); // Switched the order 11 [...] 12 } 13 } 14 15 /* Why does our container now spin around our screen?: 16 == =================================================== 17 Remember that matrix multiplication is applied in reverse. This time a translation is thus 18 applied first to the container positioning it in the bottom-right corner of the screen. 19 After the translation the rotation is applied to the translated container. 20 21 A rotation transformation is also known as a change-of-basis transformation 22 for when we dig a bit deeper into linear algebra. Since we're changing the 23 basis of the container, the next resulting translations will translate the container 24 based on the new basis vectors. Once the vector is slightly rotated, the vertical 25 translations would also be slightly translated for example. 26 27 If we would first apply rotations then they'd resolve around the rotation origin (0,0,0), but 28 since the container is first translated, its rotation origin is no longer (0,0,0) making it 29 looks as if its circling around the origin of the scene. 30 31 If you had trouble visualizing this or figuring it out, don't worry. If you 32 experiment with transformations you'll soon get the grasp of it; all it takes 33 is practice and experience. 34 */
调换一下旋转和位移的顺序即可(题目中指的是阅读的顺序,实际的变换顺序应该与阅读顺序相反)
至于原因,我认为先位移后图像被移到了右下角,再旋转还是以(0,0)为中心旋转,所以看起来是图片绕着中心旋转
而先执行旋转再执行位移,旋转中心也会产生位移,所以看起来是在右下角旋转
2019/11/28