Java 分别绘制圆的每个扇形
我想用OpenGL画一个圆,除了我想把每个扇区(总共18个)画成一个单独的形状,这样我就可以对每个扇区进行不同的格式化。我该怎么做呢 这是我迄今为止的尝试,它将18个扇区相互重叠Java 分别绘制圆的每个扇形,java,opengl,Java,Opengl,我想用OpenGL画一个圆,除了我想把每个扇区(总共18个)画成一个单独的形状,这样我就可以对每个扇区进行不同的格式化。我该怎么做呢 这是我迄今为止的尝试,它将18个扇区相互重叠 intx=480/2; int y=(255/2)-15; int r=90; int扇区=90//实际部门数量的5倍 GL11.glPushMatrix(); GL11.GL4F(0.6F,0.6F,0.6F,0.3F); GL11.glBegin(GL11.GL_三角形_扇); GL11.glVertex2f(x,
intx=480/2;
int y=(255/2)-15;
int r=90;
int扇区=90//实际部门数量的5倍
GL11.glPushMatrix();
GL11.GL4F(0.6F,0.6F,0.6F,0.3F);
GL11.glBegin(GL11.GL_三角形_扇);
GL11.glVertex2f(x,y);
对于(int i=0;i<18;i++)
{
对于(int n=0;n//将圆圈稍微放在屏幕中心上方
int x=480/2;
int y=(255/2)-15;
int r=90;
int扇区=90;//圆圈质量
GL11.glPushMatrix();
GL11.GL4F(0.6F,0.6F,0.6F,0.3F);
GL11.glBegin(GL11.GL_三角形_扇);
GL11.glVertex2f(x,y);
对于(int i=0;i<18;i++)
{
对于(int n=0+(i*5);n表示没有圆。你的代码应该做什么,你的确切问题是什么?我的代码应该是一个圆的18个扇区,但事实并非如此。我的问题是我缺乏数学技能。我现在已经设法解决了,我会给出答案。哦,不!glBegin(),我打赌这就是为什么圆圈没有画…只是说。
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();
//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();