• OpenGL——三维多面体实现


    #include<iostream>
    #include <math.h>
    #include<Windows.h>
    #include <GL/glut.h>
    
    using namespace std;
    
    GLsizei winWidth = 600, winHeight = 600;
    
    
    
    
    void init()
    {
        glClearColor(1.0, 1.0, 1.0, 0.0);
    
    }
    
    void displayWirePolyhedra()
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(0.0, 0.0, 1.0);
    
        gluLookAt(5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    
        glScalef(1.5, 2.0, 1.0);
        glutWireCube(1.0);
    
        glScalef(0.8, 0.5, 0.8);
        glTranslatef(-6.0, -5.0, 0.0);
        glutWireDodecahedron();
    
        glTranslatef(8.6, 8.6, 2.0);
        glutWireTetrahedron();
    
        glTranslatef(-3.0, -1.0, 0.0);
        glutWireOctahedron();
    
        glScalef(0.8, 0.8, 1.0);
        glTranslatef(4.3, -2.0, 0.5);
        glutWireIcosahedron();
    
        glFlush();
    }
    
    void winReshapeFcn(GLint newWidth, GLint newHeight)
    {
        glViewport(0, 0, newWidth, newHeight);
    
        glMatrixMode(GL_PROJECTION);
        glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 20.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(displayWirePolyhedra);
        glutReshapeFunc(winReshapeFcn);
        glutMainLoop();
    
        system("pause");
        return 0;
    }

    运行结果:

  • 相关阅读:
    【算法】一致性Hash算法
    P1576 最小花费 题解
    Vijos1234 口袋的天空 题解
    P1379 八数码难题 题解
    Tarjan求无向图必经点 笔记
    P3372 【模板】线段树 1 题解
    CF1332A Exercising Walk 题解
    P6270 [SHOI2002]取石子游戏 题解
    P6269 [SHOI2002]空中都市 题解
    P6268 [SHOI2002]舞会 题解
  • 原文地址:https://www.cnblogs.com/farewell-farewell/p/9462107.html
Copyright © 2020-2023  润新知