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