分别绘制圆的每个扇区

时间:2015-09-03 18:22:22

标签: java opengl

我想使用OpenGL画一个圆圈,除了我想要将每个扇区(总共18个)绘制成一个单独的形状,这样我就能以不同的方式格式化每个扇区。我该怎么做呢?

这是我到目前为止的尝试,它相互吸引了18个扇区enter image description here

int x = 480/2;
int y = (255/2)-15;
int r = 90;
int sectors = 90; //5x amount of actual sectors

GL11.glPushMatrix();
    GL11.glColor4f(0.6F, 0.6F, 0.6F, 0.3F);
    GL11.glBegin( GL11.GL_TRIANGLE_FAN );   
        GL11.glVertex2f(x, y);
        for(int i = 0; i < 18; i++)
        {
            for(int n = 0; n <= sectors/18; n++)
            {
                float t = 2 * 3.14152f * (float)n / (float)sectors;
                GL11.glVertex2d(x + Math.sin(t) * r, y + Math.cos(t) * r);
            }
        }
    GL11.glEnd();
GL11.glPopMatrix();

这是针对Minecraft Forge mod。

1 个答案:

答案 0 :(得分:0)

                //Place circle slightly above centre of screen
            int x = 480 / 2;
            int y = (255 / 2) - 15;

            int r = 90;
            int sectors = 90; // Circle quality

            GL11.glPushMatrix();
            GL11.glColor4f(0.6F, 0.6F, 0.6F, 0.3F);
            GL11.glBegin(GL11.GL_TRIANGLE_FAN);
            GL11.glVertex2f(x, y);
            for(int i = 0; i < 18; i++)
            {
                for(int n = 0+(i*5); n <= (sectors / 18) + (i*5); n++) //I just had to re-multiply the sectors to get up to 90 and carry on where the last sector left off.
                {
                    float t = 2 * 3.14152f * (float) n / (float) sectors;
                    GL11.glVertex2d(x + Math.sin(t) * r, y + Math.cos(t) * r);
                }
            }
            GL11.glEnd();
            GL11.glPopMatrix();