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条回答

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料