[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}
效果图如下:
程序如下:
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}
效果图如下:
相关文章推荐
- [NEHE Couse] 02.My first polygon
- [NEHE Couse] 03.My first polygon with various color
- NeHe OpenGL教程 04 旋转场景
- [NEHE Couse] 05.3D Objects
- [NEHE Couse] 06.Texture Map
- NEHE的OpenGL-Lesson 04 Rotations
- [NEHE Couse] 01.Create an empty OpenGL Window
- OpenGL In C# 04 Nehe 第二课 绘制多边形
- 04-控制器的生命周期方法
- C# 多线程详解 Part.04(Lock、Monitor、生产与消费)
- 图像处理的简单优化-04:循环消弱
- Android 04 IntentService
- 黑马程序员——学习笔记04.java数组
- 01-04
- 《Effective C++ 3》01 让自己习惯C++ 条款:01-04
- [Java] Spring 3.0 01/02/03/04/05 -自设源代码
- 《Thinking In Algorithm》04.单向链表和双向链表的区别
- 【04】确定对象被使用之前已先被初始化
- [微信机器人_04]自然语言处理简单实现
- [Java] 动态代理 04 - 想实现什么功能,就实现什么功能