首页 > 代码库 > 动态圆锥
动态圆锥
代码如下:
#include <windows.h>//#include <GLUT/glut.h>#include <GL/glut.h>#include <math.h>#include <iostream>using namespace std;#define GL_PI 3.1415fvoid RenderScene(){ static GLfloat xRot = 0,yRot = 0; GLfloat x,y,angle; int iPivot = 1; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); GLboolean bCull = true; GLboolean bDepth = true; GLboolean bOutline = true; if(bCull) //启动剔除标志 glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); if(bDepth) //启用深度测试标志 glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); if(bOutline) //启用多边形模式标志 glPolygonMode(GL_BACK,GL_LINE); else glPolygonMode(GL_BACK,GL_FILL); glPushMatrix(); glRotatef(45.0f,1.0f,0.0f,0.0f); glRotatef(45.0f,0.0f,1.0f,0.0f); glRotatef(xRot,1.0f,0.0f,0.0f); glRotatef(yRot,0.0f,1.0f,0.0f); glFrontFace(GL_CW); glBegin(GL_TRIANGLE_FAN); glVertex3f(0.0f,0.0f,75.0f); for(angle = 0.0f;angle < (2.0*GL_PI);angle += (GL_PI)/8.0) { x = 50.0f*sin(angle); y = 50.0f*cos(angle); if((iPivot %2)==0) glColor3f(0.0f,0.0f,1.0f); else glColor3f(1.0f,0.0f,0.0f); iPivot++; glVertex2f(x,y); } glEnd(); //glFrontFace(GL_CCW|GL_CW); glBegin(GL_TRIANGLE_FAN); glVertex2f(0.0f,0.0f); for(angle = 0.0f;angle < (2.0f*GL_PI);angle += (GL_PI)/8.0f) { x = 50.0f*sin(angle); y = 50.0f*cos(angle); if((iPivot %2)==0) glColor3f(0.0f,0.0f,1.0f); else glColor3f(1.0f,0.0f,0.0f); iPivot++; glVertex2f(x,y); } glEnd(); if(xRot < 360) xRot += 5.0f; else xRot = 0.0f; if(yRot < 360) yRot += 5.0f; else yRot = 0; glPopMatrix(); glutSwapBuffers();}void TimerFunction(int value){ glutPostRedisplay(); glutTimerFunc(33,TimerFunction,1);}void ChangeSize(GLsizei w,GLsizei h){ if(h==0) h = 1; GLfloat aspectRatio = (GLfloat)w/(GLfloat)h; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-100,100,-100/aspectRatio,100/aspectRatio,100.0,-100.0); else glOrtho(-100*aspectRatio,100*aspectRatio,-100,100,100.0,-100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}void SetupRC(){ glClearColor(0.0f,0.0f,0.0f,1.0f); glColor3f(1.0f,0.0f,0.0f); glShadeModel(GL_FLAT); glFrontFace(GL_CW);}int main(int argc, char *argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(800,600); glutCreateWindow("Simple"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); glutTimerFunc(33,TimerFunction,1); SetupRC(); glutMainLoop(); return 0;}
动态圆锥
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。