您的位置:首页 > 移动开发 > Objective-C

[NEHE Couse] 04.Rotating objects

2009-01-09 14:49 183 查看
没有什么新内容,注意glRotatef函数的使用就可以了,我在程序中为了效果,引入了glutIdleFunc函数的使用,具体用法大家可以google下。此外为了让三角面片旋转时不至于旋转出视线,我把glOrtho的参数也修改了。点击鼠标左键物体开始旋转,点击右键旋转停止。

程序如下:

1#include <gl/glut.h>

6#include <stdlib.h>

7

8#define WinWidth 500 //the width of the window

9#define WinHeight 500 //the height of the window

10

11static GLint t;

12static GLfloat spin_x,spin_y; //control the rotate range

13

14void init(void)

15void display(void)

23void reshape(int w,int h)

50void keyboard(unsigned char key,int x,int y)

65void spinDisplay(void)

87void mouse(int button,int state,int x,int y)

97int main(int argc,char *argv[])

115{

116 glutInit(&argc,argv);

117 glutInitDisplayMode(GLUT_DEPTH|GLUT_RGB|GLUT_DOUBLE);

118 glutInitWindowSize(WinWidth,WinHeight);

119 glutInitWindowPosition(100,100);

120 glutCreateWindow("Lesson 04");

121

122 init();

123 glutDisplayFunc(display);

124 glutReshapeFunc(reshape);

125 glutKeyboardFunc(keyboard);

126 glutMouseFunc(mouse);

127 glutMainLoop();

128 return 0;

129}

效果图如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: