我正在阅读一系列NeHe OpenGK教程。 Tutorial #9做了一些奇特的东西;我理解了一切,除了我认为是整个教程的骨干之外的两件事。
在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
如果某个机构告诉我机制正在进行中,我将非常感激。
答案 0 :(得分:1)
我不明白他为什么要倾斜屏幕。
倾斜让你从另一个角度看到星星而不仅仅是#34;正好在#34;它们。
另一件事是他首先倾斜屏幕,然后按星角旋转它,然后立即将其旋转。这种技术是什么?
这是因为他想围绕所选平面(在这种情况下为Y平面)旋转星星,但是(!)他还希望纹理四边形面向观察者。让我们说他将它旋转90度,如果是这样的话,你只会看到(就像他在教程中所述)a"厚的"线。
请考虑以下评论:
// 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);