用opengl生成螺旋线算法
2013-12-03 10:38
381 查看
// test01.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <gl/glut.h> #include <math.h> #define GL_PI 3.1415f // Rotation amounts static GLfloat xRot = 0.0f; static GLfloat yRot = 0.0f; // Called to draw scene void RenderScene(void) { GLfloat x,y,z,angle; // Storeage for coordinates and angles // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Call only once for all remaining points /*glBegin(GL_POINTS);*/ glBegin(GL_LINE_STRIP); z = -50.0f; for(angle = 0.0f; angle <= (2.0f*GL_PI)*3.0f; angle += 0.1f) { x = 50.0f*sin(angle); y = 50.0f*cos(angle); // Specify the point and move the Z value up a little glVertex3f(x, y, z); z += 0.5f; } // Done drawing points glEnd(); // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); } // This function does any needed initialization on the rendering // context. void SetupRC() { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Set drawing color to green glColor3f(0.0f, 1.0f, 0.0f); } void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) xRot-= 5.0f; if(key == GLUT_KEY_DOWN) xRot += 5.0f; if(key == GLUT_KEY_LEFT) yRot -= 5.0f; if(key == GLUT_KEY_RIGHT) yRot += 5.0f; if(key > 356.0f) xRot = 0.0f; if(key < -1.0f) xRot = 355.0f; if(key > 356.0f) yRot = 0.0f; if(key < -1.0f) yRot = 355.0f; // Refresh the Window glutPostRedisplay(); } void ChangeSize(int w, int h) { GLfloat nRange = 100.0f; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Points Example"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); SetupRC(); glutMainLoop(); return 0; }
相关文章推荐
- 基于OpenGL的三种直线生成算法
- 基于OpenGL的三种直线生成算法
- 【OpenGL】中点圆、椭圆生成算法
- OpenGl(jogl)分形算法生成树
- 计算机图形学(二)输出图元_6_OpenGL曲线函数_1_圆生成算法
- 计算机图形学(二)输出图元_6_OpenGL曲线函数_3_椭圆生成算法
- OpenGL 4.0 GLSL 用 shadow map 算法 生成阴影
- 【OpenGL】直线生成算法DDA+Bresenham
- OpenGL入门2——曲线生成算法
- 空当接龙牌局生成算法
- 算法训练 安慰奶牛 最小生成树
- 最小生成树(kruskal算法)和 (Prime算法)
- 随机生成图,dijkstra算法求最短路径,深度、广度优先历遍【待更新其他算法】
- opengl:凸包算法
- 求解最小生成树的算法 prim算法(附模板)
- 【学习笔记】斯坦福大学公开课(机器学习) 之生成学习算法:朴素贝叶斯
- Prim 算法求最小生成树 O(n^2)
- 算法之美---100幅由程序生成的图像,总有一幅让你感到惊艳[下]
- JavaScript生成GUID的算法
- 几种语言的随机数生成算法