2 u012498707 u012498707 于 2013.11.09 10:57 提问

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

#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();
}

Csdn user default icon
上传中...
上传图片
插入图片