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 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条