opengl中未显示球体
以下是我的显示方法:opengl中未显示球体,opengl,Opengl,以下是我的显示方法: void display() { GLfloat sphere_vertices[3]={0.0,0.0,0.0}; int theta,phi; float x,y,z; int off_set; off_set=5; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); for (theta=-90; theta<=90-off_set; theta+
void display()
{
GLfloat sphere_vertices[3]={0.0,0.0,0.0};
int theta,phi;
float x,y,z;
int off_set;
off_set=5;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for (theta=-90; theta<=90-off_set; theta+=off_set) {
for (phi=0; phi<=360-off_set; phi+=off_set)
{
//calculate X of sphere
x= cos(theta + off_set) * sin(phi + off_set);
//calculate Y of sphere
y = cos(theta + off_set) * cos(theta + off_set);
//calculate Z of sphere
z = sin(theta + off_set);
//store vertices
sphere_vertices[0]=x;
sphere_vertices[1]=y;
sphere_vertices[2]=z;
//plot new point
glVertex3fv(sphere_vertices);
printf("X is %f, Y is %f, Z is %f", x,y,z);
}
}
glEnd();
glFlush();
}
void display()
{
GLfloat sphere_顶点[3]={0.0,0.0,0.0};
intθ,φ;
浮动x,y,z;
int off_set;
off_set=5;
glClear(GLU颜色缓冲位);
glBegin(总分);
对于(θ=-90;θ来说,你似乎试图渲染一个半径为1.0的球体,它由大约180/off\u集
的圆片组成,这些圆片具有360/off\u集
点。你是如何得到你的x、y和z的
对于每个点,可以从θ
在xy平面上构建单位长度向量,然后将其绕z轴旋转φ
,并按球体半径缩放生成的向量
检查数学后,确保您指定了模型视图和投影矩阵,并注意如果您使用的是标准cos/sin函数,它们采用的是弧度,而不是度。您没有写什么是查看矩阵,请将其添加到问题中。请注意,cos和sin采用的是弧度,而不是度。glMatrixMode(GL_投影);glLoadIdentity();gluOrtho2D(0.0,50.0,0.0,50.0);glMatrixMode(GL_MODELVIEW);什么是查看矩阵?我对OpenGL非常陌生