zoukankan      html  css  js  c++  java
  • OpenGL——二次曲面函数(球面-圆锥面-圆柱面)

     代码:

    #include<iostream>
    #include <math.h>
    #include<Windows.h>
    #include <GL/glut.h>
    
    using namespace std;
    
    GLsizei winWidth = 500, winHeight = 500;
    
    void init()
    {
        glClearColor(1.0, 1.0, 1.0, 0.0);
    }
    
    void wireQuadSurfs()
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(0.0, 0.0, 1.0);
    
        gluLookAt(2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    
        glPushMatrix();
        glTranslatef(1.0, 1.0, 1.0);
        //球面,半径为0.5
        glutWireSphere(0.50, 8, 6);
        glPopMatrix();
        
        glPushMatrix();
        glTranslatef(1.0, -0.5, 0.5);
        //圆锥面,底面半径为0.5,高位1.5
        glutWireCone(0.5, 1.5, 7, 6);
        glPopMatrix();
    
        GLUquadricObj *cylinder;
        glPushMatrix();
        glTranslatef(0.0, 1.5, 0.8);
        //激活二次曲面绘制器
        cylinder = gluNewQuadric();
        //每对顶点之间用线连接,按线框图形式显示
        gluQuadricDrawStyle(cylinder, GLU_LINE);
        //生成圆柱面
        gluCylinder(cylinder, 0.5, 0.5, 1.5, 6, 4);
        glPopMatrix();
    
        glFlush();
    }
    
    
    
    void winReshapeFcn(GLint newWidth, GLint newHeight)
    {
        glViewport(0, 0, (GLsizei)newWidth, (GLsizei)newHeight);
    
        glMatrixMode(GL_PROJECTION);
        glOrtho(-2.0, 2.0, -2.0, 2.0, 0.0, 5.0);
    
        glMatrixMode(GL_MODELVIEW);
    
        glClear(GL_COLOR_BUFFER_BIT);
    }
    
    
    int main(int argc, char* argv[])
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
        glutInitWindowPosition(100, 100);
    
        glutInitWindowSize(winWidth, winHeight);
        glutCreateWindow("球面-圆锥面-圆柱面");
        init();
        glutDisplayFunc(wireQuadSurfs);
        glutReshapeFunc(winReshapeFcn);
        glutMainLoop();
    
        system("pause");
        return 0;
    }

    运行结果:

  • 相关阅读:
    js上传文件
    IOS怎么实现一个UITableView的下拉刷新
    Android的事件处理-android学习之旅(四十四)
    NIO框架之MINA源代码解析(二):mina核心引擎
    每日五题
    Joda-Time 简介
    用websocket实现后台推送消息
    websoclet简单示例 my 改
    struts2拦截器interceptor的配置方法及使用
    activiti复盘重推的一种简单实现方式:
  • 原文地址:https://www.cnblogs.com/farewell-farewell/p/9480901.html
Copyright © 2011-2022 走看看