songjianjian2013 2013-11-09 02:57
浏览 830

各位帮帮忙!!!为啥显示的不像个球呢

#include
#include
#define PI 3.1415926
#define GLfloat float
#define GLdouble double
#define GLint int
double theta,phi,phir20,phir,thetar,x,y,z;
double c=PI/180.0;
double r=1;
double c80=c*80;
GLfloat ww=500,hh=500;
int rand();
void myInit()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0,0.0,0.0,1.0);
glViewport(0,0,ww,hh);
glOrtho(0.0,(GLdouble)ww,0.0,(GLdouble)hh,-ww,hh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
//void reshape(GLsizei ww,GLsizei hh)
//{

//}

void show()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glRotated(45,0,1,0);
//glRotated(10,1,0,0);
//glRotated(10,0,0,1);
for(phi=-90;phi<=90;phi+=10){

phir=c*phi;
phir20=c*(phi+20);
glPolygonMode(GL_FRONT,GL_LINE);
glPolygonMode(GL_BACK,GL_LINE);
for(theta=-180;theta<=180;theta+=10)
{
thetar=c*theta;
glBegin(GL_QUAD_STRIP);
glColor3f(1.0,0.0,0.0);
x=r*sin(thetar)*cos(phir);
y=r*cos(thetar)*cos(phir);
z=r*sin(thetar);
glVertex3d(x,y,z);

glColor3f(0.0,1.0,1.0);
x=r*sin(thetar)*cos(phir20);
y=r*cos(thetar)*cos(phir20);
z=r*sin(thetar);
glVertex3d(x,y,z);
}
glEnd();
}
glBegin(GL_TRIANGLE_FAN);//画扇形
z = r*sin(c80);
for(theta=-180;theta<=180;theta+=10){
thetar = c*theta;
x=r*sin(thetar)*cos(c80);
y=r*cos(thetar)*cos(c80);
glColor3f(0.0,0.0,1.0);
glVertex3d(x,y,z);
}
glEnd();
glBegin(GL_TRIANGLE_FAN);
z=-r*sin(c80);
for(theta=-180.0;theta<=180.0;theta+=10){
thetar = c*theta;
x=r*sin(thetar)*cos(c80);
y=r*cos(thetar)*cos(c80);
glColor3f(1.0,0.0,0.0);
glVertex3d(x,y,z);
}
glEnd();
glFlush();
}
void display()
{
show();
glutSwapBuffers();
}
void main()
{
myInit();
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("画球");
glutInitWindowSize(ww,hh);
glutDisplayFunc(display);
glutMainLoop();
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?