位置: 编程技术 - 正文
推荐整理分享人走鸟飞之二(人走鸟不惊,出自于谁的诗句?),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:人走鸟散,飞鸟走禽,鸟飞?走,人走鸟散,人走鸟飞什么意思,人走鸟不惊,出自于谁的诗句?,人走鸟飞什么意思,人走鸟散,内容如对您有帮助,希望把文章链接给更多的朋友!
//相比上一篇,这一个程序增加了视角方面的转换,我们可以从四方区观察这个运动的简单3D世界。写给和我一样的菜鸟。这些代码也比较容易懂的。
#include"stdafx.h"#define GLUT_DISABLE_ATEXIT_HACK#include <gl/glut.h>#include<time.h>#pragma comment(lib, "opengl.lib")#pragma comment(lib, "glut.lib")#pragma comment(lib, "glu.lib")#pragma comment(lib, "glut.lib")static double angle1; //翅膀的扇动角度static double angle2; //人腿的旋转角度static double walk; //人走动的速度static double fly; //鸟飞的速度static double d = 0.1; //增量static double e = 0.1; //增量static double s = 0.;//增量static double f = 0.;float g_rotateY = 0.0f; // 绕Y轴旋转变量float g_posX = 0.0f; //横向位移float g_posY = 0.0f;float g_posZ = 0.0f;int camerdire;void init(void){ glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT);}void cylinder(){ glPushMatrix(); glTranslatef(0, 0, -0.); glScalef(0., 0., 0.1); GLUquadricObj *cylinder_obj1; GLUquadricObj *cylinder_obj2; //GLUquadricObj *cylinder_obj3; //然后再初始化 cylinder_obj1 = gluNewQuadric(); cylinder_obj2 = gluNewQuadric(); //cylinder_obj3=gluNewQuadric(); //GL_COLOR_BUFFER_BIT标志用glClearColor设置的颜色清除颜色缓冲区 glColor3f(1.0, 1.0, 0.1); //glColor{}{b s i f d ub us ui}{v}(....) //画圆柱体 glPushMatrix(); glRotatef(0, 1.0, 0.0, 0.0);//绕y轴旋转的角度 gluCylinder(cylinder_obj1, 2, 2, 4, , ); gluDisk(cylinder_obj2, 0, 2, , ); glPopMatrix(); glPopMatrix();}void display(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glLoadIdentity(); if (camerdire==1) //从左侧观看 gluLookAt(-.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0); //设置照相机参数,照相机的位置为(0,0,5),指向(0,0,0),向上为(0,1,0) if (camerdire==0) //从前面观看 gluLookAt(0.0, 0.0, .0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0); //设置照相机参数,照相机的位置为(0,0,5),指向(0,0,0),向上为(0,1,0) if (camerdire==2) //从后面观看 gluLookAt(0.0, 0.0, -.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0); //设置照相机参数,照相机的位置为(0,0,5),指向(0,0,0),向上为(0,1,0)//----------------------画出地面------------------- glPushMatrix(); glTranslatef(-g_posX, g_posY, g_posZ5); glTranslatef(-2, 6, -6); glScalef(3, 1, 2); glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glVertex3f(2.0f, -1.5f, 2.0f); glVertex3f(-2.0f, -1.5f, 2.0); glVertex3f(-2.0f, -1.5f, -2.0); glVertex3f(2.0f, -1.f, -2.0); glEnd(); glPopMatrix();//----------------------以上画出地面----------
//---------------------以下画出飞鸟 glPushMatrix();
glTranslatef(0, -5, 0.3); glTranslatef(fly=f, angle1/0.1, 0); //飞鸟身躯的上下起伏,左右移动 //一对翅膀(用两个扁长的立方体表示) glColor3f(0.7, 0.7, 0.7); glPushMatrix(); glRotatef(angle1, 0, 0, 1); glTranslatef(-0.5,0,0); glScalef(1, 0., 0.3); glutSolidCube(1.0); glPopMatrix(); glPushMatrix(); glRotatef(-angle1, 0, 0, 1); glTranslatef(0.5, 0, 0); glScalef(1, 0., 0.3); glutSolidCube(1.0); glPopMatrix(); //一个身躯(用一个立方体表示) glColor3f(1.0, 0.0, 0.0); glPushMatrix(); glScalef(0.3,0.3,0.3); glutSolidCube(1.0); glPopMatrix();
glPopMatrix(); //----------------------以上为飞鸟的动画
glColor3f(0, 1, 0);//-----------------------下面画出一个人走路 glPushMatrix(); glRotatef(-, 0, 0, 1); glTranslatef(-4,walk=s,0); //两腿的前进 glScalef(2.0, 2.0, 2.0); //调整机器人的大小 //---------------------下面是两腿摆动的动画---------- glPushMatrix(); glColor3f(1.0, 0.0, 1.0); glRotatef(angle2, 0, 0, 1); glTranslatef(-0.5, 0, 0); glScalef(1, 0., 0.1); glutSolidCube(1.0); glPopMatrix(); glPushMatrix(); glRotatef(, 0, 0, 1); glRotatef(-angle2, 0, 0, 1); glTranslatef(0.5, 0, 0.3); glScalef(1, 0., 0.1); glutSolidCube(1.0); glPopMatrix(); cylinder(); glPopMatrix();//-----------------------以上为人走动的动画-------------- glFlush();}void reshape(int w,int h){ glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, .0); glMatrixMode(GL_MODELVIEW);}void myIdle(void){ angle1 -= d; if (angle1 <-) d = -d; else if (angle1>) d = -d; angle2 -= e; if (angle2 <-) e = -e; else if (angle2>) e = -e;
if (walk <-3) s = -s; else if (walk>3) s = -s;
if (fly < -5) f = -f; else if (fly>5) f = -f; display();}void ProcessSpecialKeyboead(int key, int x, int y)//转换摄像头视角的方向{ if (key == GLUT_KEY_F1) { camerdire = 0; } if (key == GLUT_KEY_F2) { camerdire = 1; } if (key == GLUT_KEY_F3) { camerdire = 2; }}void KeyboardFunc(unsigned char key, int x, int y){ switch (key) {//---------------------控制地面的移动---------------------------- case 'A': case 'a': // 向左移动 g_posX -= 0.f; if (g_posX < -4.0f) { g_posX = -4.0f; } break;
case 'D': case 'd': // 向右移动 g_posX = 0.f; if (g_posX > 4.0f) { g_posX = 4.0f; } break; case 'W': case 'w': // 向上移动 g_posY -= 0.f; break; case 'S': case 's': // 向上移动 g_posY = 0.f; break; case 'F': case 'f': // 向前移动 g_posZ -= 0.f; break; case 'B': case 'b': // 向前移动 g_posZ = 0.f; break; default: break; }}
int main(int argc, char * *argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(, ); glutInitWindowPosition(, ); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutIdleFunc(myIdle); glutReshapeFunc(reshape); glutKeyboardFunc(KeyboardFunc); glutSpecialFunc(ProcessSpecialKeyboead); glutMainLoop(); return 0;}
OpenGL学习-直线&三角形绘制 一、画线(1)在glBegin中使用GL_LINES绘制图元时,每两个顶点会连成一条直线,例如:glBegin(GL_LINES);glVertex3f(.0f,0.0f,0.0f);glVertex3f(.0f,.0f,0.0f);glVertex3f(-5
OpenGL,Android注意事项初始化顺序 NullPointer BUG:Causedby:java.lang.IllegalStateException:setRendererhasalreadybeencalledforthisinstance.或者NullPointer错误解决方法:把setEGLContextClientVersion(2);挪到setRenderer()前面。方法的
Qt_OpenGL:雾程序小测 Qt_OpenGL:雾程序小测//.h#ifndefFOGTEST_H#defineFOGTEST_H#includeQWidget#includeQtOpenGLclassFogTest:publicQGLWidget{Q_OBJECTpublic:FogTest(QWidget*parent=0);~FogTest();protected:voidinitializeG
标签: 人走鸟不惊,出自于谁的诗句?
本文链接地址:https://www.jiuchutong.com/biancheng/373214.html 转载请保留说明!友情链接: 武汉网站建设