球体未在 opengl 中显示

发布于 2024-12-12 13:29:13 字数 992 浏览 0 评论 0原文

这是我的显示方法:

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

}

我正在计算球体表面上的点,然后绘制每个点。但我得到的唯一结果是屏幕左下角的一些像素

here is my display method:

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

}

I am calculating the points on the surface of a sphere and then plotting each point. But the only thing I get are some pixel at the bottom-left corner of the screen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌化 2024-12-19 13:29:13

看起来您正在尝试渲染一个半径为 1.0 的球体,该球体由大约 180 / offset_set 圆片和 360 / offset_set 点组成。你是如何得出 x、y 和 z 的?

对于每个点,您可以在例如 xy 平面上从 theta 构造一个单位长度向量,然后将其绕 z 轴旋转 phi 并缩放得到的向量除以球体的半径。

检查完数学后,请确保您已指定模型视图和投影矩阵,并注意如果您使用标准 cos/sin 函数,它们采用弧度,而不是度数。

It seems like you are trying to render a sphere with radius of 1.0 consisting of about 180 / off_set slices of circles with 360 / off_set points. How did you come up with your x, y and z?

For each point, you could construct a unit length vector on, for example, the xy-plane from theta and then rotate it about the z-axis by phi and scale the resulting vector by the radius of the sphere.

After reviewing your math, make sure you have specified the model-view and projection matrices and note if you are using the standard cos/sin functions, they take radians, not degrees.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文