0

我正在使用 c++ 和 g3d 绘制一个简单的球体,但不知道如何将多个对象/球体排列成圆形。

for(i = 0.0f;i<1.4f;i+=0.2f){ 
    sphere->position = (Vector3(2,i,0));
}

我怎样才能做到这一点?

4

1 回答 1

1
// num_points is the number of points/objects in 
// the circle and coords is just the center location of where to draw
static void draw_circle_loop(float radius, int num_points, struct vector2d *coords)
{
    int i;
    float x, y;
    float angle;

    for (i = 0; i < num_points; i++)
    {
        angle = i * (2.0f * M_PI / num_points);
        x = coords->x + cosf(angle) * radius;
        y = coords->y + sinf(angle) * radius;
        glVertex2f(x, y);
    }
     glVertex2f(coords->x + radius, coords->y);
}

尝试这样的事情。而不是调用glVertex2f使用这些坐标来循环放置东西。

于 2013-01-11T23:00:56.940 回答