以圆形排列三维对象 我用C++和G3D绘制一个简单的球面,但是不知道如何排列多个物体/球的形状。< /P> for(i = 0.0f;i<1.4f;i+=0.2f){ sphere->position = (Vector3(2,i,0)); } for(i=0.0f;i位置=(向量3(2,i,0)); }

以圆形排列三维对象 我用C++和G3D绘制一个简单的球面,但是不知道如何排列多个物体/球的形状。< /P> for(i = 0.0f;i<1.4f;i+=0.2f){ sphere->position = (Vector3(2,i,0)); } for(i=0.0f;i位置=(向量3(2,i,0)); },c++,C++,如何实现这一点?//num\u points是中的点/对象数 // 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;

如何实现这一点?

//num\u points是中的点/对象数
// 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);
}
//圆圈和坐标只是绘制位置的中心位置 静态空心绘制圆循环(浮动半径、整数点、结构向量2D*坐标) { int i; 浮动x,y; 浮动角; 对于(i=0;ix+cosf(角度)*半径; y=坐标->y+sinf(角度)*半径; glVertex2f(x,y); } glVertex2f(坐标->x+半径,坐标->y); }

尝试类似的方法。不要调用
glVertex2f
而是使用这些坐标来循环放置东西。

我在发布时没有注意到格式被弄乱,代码现在是固定的,更清晰了。