Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenGl旋转和平移_Opengl_Rotation_Translation_3d - Fatal编程技术网

OpenGl旋转和平移

OpenGl旋转和平移,opengl,rotation,translation,3d,Opengl,Rotation,Translation,3d,我正在学习一系列的NeHe OpenGK教程。做一些花哨的事情;我什么都懂,除了我认为是整个教程的核心的两件事 在DrawGlScene函数中,我不理解下面的行 glRotatef(tilt,1.0f,0.0f,0.0f); // Tilt The View (Using The Value In 'tilt') 我理解这一行的作用,教程中也非常清楚地提到了这一行。但我不明白他为什么要倾斜屏幕 另一件事是,他先倾斜屏幕,然后以星形角度旋转屏幕,然后立即进行相反的操作。那是什么技巧?什么需要

我正在学习一系列的NeHe OpenGK教程。做一些花哨的事情;我什么都懂,除了我认为是整个教程的核心的两件事

DrawGlScene
函数中,我不理解下面的行

glRotatef(tilt,1.0f,0.0f,0.0f);  // Tilt The View (Using The Value In 'tilt') 
我理解这一行的作用,教程中也非常清楚地提到了这一行。但我不明白他为什么要倾斜屏幕

另一件事是,他先倾斜屏幕,然后以星形角度旋转屏幕,然后立即进行相反的操作。那是什么技巧?什么需要倾斜?当星星面向用户时,只需旋转星星即可

glRotatef(star[loop].angle,0.0f,1.0f,0.0f); // Rotate To The Current Stars Angle
glTranslatef(star[loop].dist,0.0f,0.0f);    // Move Forward On The X Plane

glRotatef(-star[loop].angle,0.0f,1.0f,0.0f); // Cancel The Current Stars Angle
glRotatef(-tilt,1.0f,0.0f,0.0f);             // Cancel The Screen Tilt
如果有人告诉我引擎盖下的机制,我会非常感激

我不明白他为什么要倾斜屏幕

倾斜使你从另一个角度看星星,而不仅仅是在“正上方”

另一件事是,他先倾斜屏幕,然后以星形角度旋转屏幕,然后立即进行相反的操作。那是什么技巧

这是因为他希望围绕选定平面(在本例中为Y平面)旋转星星,但是(!)他还希望纹理四边形面向观众。假设他将其旋转90度,如果是这样,您将只看到(如他在教程中所述)一条“粗”线

考虑这些评论:

// Rotate the current drawing by the specified angle on the Y axis 
// in order to get it to rotate.
glRotatef(star[loop].angle, 0.0f, 1.0f, 0.0f); 

// Rotating around the object's origin is not going to make 
// any visible effects, especially since the star object itself is in 2D.
// In order to move around in your current projection, a glRotatef()
// call does rotate the star, but not in terms of moving it "around" 
// on the screen.
// Therefore, use the star's distance to move it out from the center.  
glTranslatef(star[loop].dist, 0.0f, 0.0f);

// We've moved the star out from the center, with the specified 
// distance in star's distance. With the first glRotatef() 
// call in mind, the 2D star is not 100 % facing
// the viewer. Therefore, face the star towards the screen using 
// the negative angle value.
glRotatef(-star[loop].angle, 0.0f, 1.0f, 0.0f);

// Cancel the tilt on the X axis.
glRotatef(-tilt, 1.0f, 0.0f, 0.0f);
我不明白他为什么要倾斜屏幕

倾斜使你从另一个角度看星星,而不仅仅是在“正上方”

另一件事是,他先倾斜屏幕,然后以星形角度旋转屏幕,然后立即进行相反的操作。那是什么技巧

这是因为他希望围绕选定平面(在本例中为Y平面)旋转星星,但是(!)他还希望纹理四边形面向观众。假设他将其旋转90度,如果是这样,您将只看到(如他在教程中所述)一条“粗”线

考虑这些评论:

// Rotate the current drawing by the specified angle on the Y axis 
// in order to get it to rotate.
glRotatef(star[loop].angle, 0.0f, 1.0f, 0.0f); 

// Rotating around the object's origin is not going to make 
// any visible effects, especially since the star object itself is in 2D.
// In order to move around in your current projection, a glRotatef()
// call does rotate the star, but not in terms of moving it "around" 
// on the screen.
// Therefore, use the star's distance to move it out from the center.  
glTranslatef(star[loop].dist, 0.0f, 0.0f);

// We've moved the star out from the center, with the specified 
// distance in star's distance. With the first glRotatef() 
// call in mind, the 2D star is not 100 % facing
// the viewer. Therefore, face the star towards the screen using 
// the negative angle value.
glRotatef(-star[loop].angle, 0.0f, 1.0f, 0.0f);

// Cancel the tilt on the X axis.
glRotatef(-tilt, 1.0f, 0.0f, 0.0f);

你可能想看一个相关的问题你可能想看一个相关的问题你的答案很有帮助,你在这个例子中正确地解释了旋转和平移的复杂行为,比如先旋转然后反转。然而,在我看来,在本教程中,简单的事情变得复杂了,就像我们可以通过以下几行glTranslatef(0.0f,0.0f,zoom)获得相同的效果一样;glRotatef(星形[环])。角度,0.0f,0.0f,1.0f);GLTRANSTALEF(星形[loop].dist,0.0f,0.0f);而不是所有先旋转然后反向旋转的线。欢迎评论。有很多方法可以处理翻译和旋转,这主要是个人喜好。:-)您的回答非常有帮助,并且您在本例中正确地解释了旋转和平移的复杂行为,如先旋转,然后反转。然而,在我看来,在本教程中,简单的事情变得复杂了,就像我们可以通过以下几行glTranslatef(0.0f,0.0f,zoom)获得相同的效果一样;glRotatef(星形[环])。角度,0.0f,0.0f,1.0f);GLTRANSTALEF(星形[loop].dist,0.0f,0.0f);而不是所有先旋转然后反向旋转的线。欢迎评论。有很多方法可以处理翻译和旋转,这主要是个人喜好。:-)