我使用c ++和g3d绘制一个简单的球体,但不知道如何以圆形形状排列多个物体/球体。
for(i = 0.0f;i<1.4f;i+=0.2f){
sphere->position = (Vector3(2,i,0));
}
我怎样才能做到这一点?
答案 0 :(得分: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
使用这些坐标循环放置。