c++ - 将 3d 对象排列成圆形

标签 c++

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

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

我怎样才能做到这一点?

最佳答案

// 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,而是使用这些坐标来循环放置东西。

关于c++ - 将 3d 对象排列成圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14288024/

相关文章:

c++ - 连词模板不会短路

c++ - GetFullPathNameA 不返回 DLL 的路径

c++ - std::set 没有成员 emplace

c++ - 通过2层方法传递shared_ptr?

c++ - 捕获类成员初始化的异常 "in-place"

c++ - 尽管有更新,clang 还是产生了关于 c++11 的警告

c++ - 为什么在英特尔编译器上将 OpenMP 的 firstprivate 与 std::vector 结合使用时会出现未定义的行为?

c++ - 按下 W/A/S/D 键时 Qt keyPressEvent 未注册

c++ - 如何给一个枚举值的索引并得到它?

c++ - 缺少 msvcr80.dll