开发者

OpenGl Rotation and Translation

I am going through a series of NeHe OpenGK tutorials. Tutorial #9 does some fancy stuff; I understood everything, except for two things which I think are the back bone of the whole tutorial.

In the DrawGlScene function, I didn't understand the following line.

glRotatef(tilt,1.0f,0.0f,0.0f);  // Tilt The View (Using The Value In 'tilt') 

I understand what that line does and it is also very clearly mentioned in the tutorial. But I don't understand why he wants to tilt the screen.

The other thing is first he tilts the screen and then rotate it by star angle and immediately after that he does the the reverse of that. What is that technique? What needs to tilt? Just rotate the star when the star faces the user.

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

I will be really thankful if some body tells me the mechanism going on under the hood.


I don't understand why he wants to tilt the screen.

Tilting makes you see the stars in another angle and not just "right above" them.

The other thing is first he tilts the screen and then rotate it by star angle and immediately after that he does the the reverse of that. What is that technique?

That is because he wants to rotate the star around the selected plane (in this case Y plane), but (!) he also want the textured quad to face the viewer. Let us say he rotate it 90 degrees, if so, you would only see (like he states in the tutorial) a "thick" line.

Consider these comments:

// 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜