• 螺旋线


    代码如下:

    #include <windows.h>
    //#include <GLUT/glut.h>
    #include <GL/glut.h>
    #include <math.h>
    #include <iostream>
    using namespace std;
    
    #define GL_PI 3.1415f
    
    void RenderScene()
    {
        GLfloat x,y,z,angle;
    
        glClear(GL_COLOR_BUFFER_BIT);
    
    
    
        glPushMatrix();
        glRotatef(45.0,1.0f,0.0f,0.0f);
        glRotatef(45.0,0.0f,1.0f,0.0f);
    
        glPointSize(5.0f);
    
        glBegin(GL_POINTS);
        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);
    
            glVertex3f(x,y,z);
            z += 0.5f;
            cout<<"x: "<<x<<" ,y: "<<y<<" ,z: "<<z<<endl;
        }
        glEnd();
    
        glPopMatrix();
        glutSwapBuffers();
    }
    
    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.0,100.0,-100.0/aspectRatio,100.0/aspectRatio,100.0,-100.0);
            //windowWidth = 100;
            //windowHeight = 100/aspectRatio;
        }
        else
        {
            glOrtho(-100.0*aspectRatio,100.0*aspectRatio,-100.0,100.0,100.0,-100.0);
            //windowWidth = 100*aspectRatio;
            //windowHeight = 100;
        }
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        //glLookAt()
    }
    
    void SetupRC()
    {
        glClearColor(0.0f,0.0f,0.0f,1.0f);
        glColor3f(0.0f,1.0f,0.0f);
    }
    
    int main(int argc, char *argv[])
    {
       glutInit(&argc,argv);
       glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
       glutInitWindowSize(800,600);
       glutCreateWindow("Simple");
    
       glutDisplayFunc(RenderScene);
       glutReshapeFunc(ChangeSize);
    
       SetupRC();
       glutMainLoop();
       return 0;
    }
    态度决定高度,细节决定成败,
  • 相关阅读:
    Android开发学习之路-使用Handler和Message更新UI
    Android开发学习之路-Service和Activity的通信
    Android开发学习之路-自定义ListView(继承BaseAdapter)
    URI、URL、URN
    理解 node.js 的事件循环
    创建hexo风格的markdown页面
    heroku
    js通过沿着作用域链还是原型链查找变量
    浏览器中实现3D全景浏览
    数据可视化图表ECharts
  • 原文地址:https://www.cnblogs.com/lxk2010012997/p/4188240.html
Copyright © 2020-2023  润新知