第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用Visual C ++在Opengl中創(chuàng)建3D球體

使用Visual C ++在Opengl中創(chuàng)建3D球體

C++
尚方寶劍之說(shuō) 2019-09-24 09:54:24
我無(wú)法使用C ++中的OpenGL庫(kù)函數(shù)glutSolidSphere()創(chuàng)建簡(jiǎn)單的3D球體。這是我嘗試過(guò)的:#include<GL/glu.h> void display() {     glClear(GL_COLOR_BUFFER_BIT);     glColor3f(1.0,0.0,0.0);     glLoadIdentity();     glutSolidSphere( 5.0, 20.0, 20.0);     glFlush(); } void myInit() {    glClearColor(1.0,1.0,1.0,1.0);     glColor3f(1.0,0.0,0.0);     glMatrixMode(GL_PROJECTION);     glLoadIdentity();     gluOrtho2D(0.0,499.0,0.0,499.0);     glMatrixMode(GL_MODELVIEW); } void main(int argc,char **argv) {     qobj = gluNewQuadric();     glutInit(&argc,argv);     glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);     glutInitWindowSize(500,500);     glutCreateWindow("pendulum");             glutDisplayFunc(display);     myInit();     glutMainLoop(); }
查看完整描述

3 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

我不知道datenwolf的索引生成如何正確。但是我仍然發(fā)現(xiàn)他的解決方案相當(dāng)明確。這是我經(jīng)過(guò)一番思考后得到的:


inline void push_indices(vector<GLushort>& indices, int sectors, int r, int s) {

    int curRow = r * sectors;

    int nextRow = (r+1) * sectors;


    indices.push_back(curRow + s);

    indices.push_back(nextRow + s);

    indices.push_back(nextRow + (s+1));


    indices.push_back(curRow + s);

    indices.push_back(nextRow + (s+1));

    indices.push_back(curRow + (s+1));

}


void createSphere(vector<vec3>& vertices, vector<GLushort>& indices, vector<vec2>& texcoords,

             float radius, unsigned int rings, unsigned int sectors)

{

    float const R = 1./(float)(rings-1);

    float const S = 1./(float)(sectors-1);


    for(int r = 0; r < rings; ++r) {

        for(int s = 0; s < sectors; ++s) {

            float const y = sin( -M_PI_2 + M_PI * r * R );

            float const x = cos(2*M_PI * s * S) * sin( M_PI * r * R );

            float const z = sin(2*M_PI * s * S) * sin( M_PI * r * R );


            texcoords.push_back(vec2(s*S, r*R));

            vertices.push_back(vec3(x,y,z) * radius);

            push_indices(indices, sectors, r, s);

        }

    }

}


查看完整回答
反對(duì) 回復(fù) 2019-09-24
  • 3 回答
  • 0 關(guān)注
  • 806 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)