C++ 在OpenGL中绘制新月形

C++ 在OpenGL中绘制新月形,c++,opengl,graphics,C++,Opengl,Graphics,如何在OpenGL中绘制二维新月形或月亮形?我试着用正反两个字,就像我画圆圈一样,但因为新月形的内部有一个“切口”,所以正反两个字看起来不够。我也不知道如何在两个多边形之间进行相交。所以我在想,是否有一个画新月的数学公式?你可以画两个相互相交的垂直椭圆。月牙形是由一次日食的空间切割而成的。绘制时,可以通过使用逐位NAND逻辑运算符删除交点 glEnable(GL_COLOR_LOGIC_OP); drawEllipse1(); glLogicOp(GL_NAND); drawEllipse2(

如何在OpenGL中绘制二维新月形或月亮形?我试着用正反两个字,就像我画圆圈一样,但因为新月形的内部有一个“切口”,所以正反两个字看起来不够。我也不知道如何在两个多边形之间进行相交。所以我在想,是否有一个画新月的数学公式?

你可以画两个相互相交的垂直椭圆。月牙形是由一次日食的空间切割而成的。绘制时,可以通过使用逐位NAND逻辑运算符删除交点

glEnable(GL_COLOR_LOGIC_OP);
drawEllipse1(); 
glLogicOp(GL_NAND);
drawEllipse2();

要做到这一点,需要指定一组顶点,这些顶点构成所需形状的骨架。然后,您可以使用GL_线“连接点”来绘制您的形状。如果想要更平滑的形状,可以使用顶点作为Bezier/Catmull Rom样条曲线的控制点,该样条曲线将绘制一条连接所有顶点的平滑曲线。

这在数学上不正确,但可能足够接近以满足您的需要:

void drawCrescentLine(float step,float scale,float fullness) {
   float angle=0.0f;
   while (angle<M_PI) {
      glVertex2f(scale*sinf(angle),scale*cosf(angle));
      angle+=step;
   }
   while (angle<(2.0f*M_PI)) {
      glVertex2f(fullness*scale*sinf(angle),scale*cosf(angle));
      angle+=step;
   }
   glVertex2f(0.0f,scale);
}
void drawCrescentLine(浮动步长、浮动刻度、浮动满度){
浮动角度=0.0f;
而(角度您可以尝试以下方法:

Vertex outside [N+1]; // Fill in N with the precision you want
Vertex  inside [N+1]; // Fill in N with the precision you want

double neg_size = sqrt (1 + NEG_DIST); // Size of intescting circle.
                                       // NEG_DIST is the distance between their centers
                                       //  Greater NEG_DIST => wider crecent

double start_angle = atan (1 / NEG_DIST); // Start angle for the inside edge
double arc = M_PI - (2 * start_angle);    // Arc of the inside edge

for (int i = 0; i <= N; i++)
{
  // Outside edge
  outside [i].x = cos ((M_PI / N) * i) * SIZE;
  outside [i].y = sin ((M_PI / N) * i) * SIZE;

  // Inside edge
  inside [i].x = (cos (start_angle + ((arc / N) * i)) * neg_size) * SIZE;
  inside [i].y = (sin (start_angle + ((arc / N) * i)) * neg_size - NEG_DIST) * SIZE;
}
顶点在[N+1]之外;//用所需的精度填写N
[N+1]内的顶点;//以所需的精度填充N
双负尺寸=sqrt(1+负距离);//连接圆的尺寸。
//NEG_DIST是它们中心之间的距离
//更大的负区=>更宽的crecent
双起始角=atan(1/NEG距离);//内边缘的起始角
双圆弧=M_PI-(2*起始角);//内边缘的圆弧

对于(inti=0;i),新月是两个非同心圆之间的差。但我需要一种“相交”的方法使其中一个圆清除另一个圆的相交区域。我如何才能做到这一点?我如何在OpenGL中指定逻辑运算符以删除相交?glBegin或glVertex2f不允许我添加逐位运算符参数。谢谢!我尝试使用logic op,但看起来像素或混合到背景中的任何颜色都会变成许多点像素。为什么它不删除交点?我通常使用多边形的正反两种方法绘制椭圆。我使用多边形绘制此代码,但多边形的末端用一条横切形状的直线连接。当填充颜色时,整个形状都会消失out.@xEnOn原始版本生成的顶点,以便适合使用
GL\u LINE\u STRIP
。我已经更新了答案,包括一个应该使用
GL\u TRIANGLE\u STRIP
的版本。非常感谢!这真是一个绘制新月的聪明方法!谢谢!)
Vertex outside [N+1]; // Fill in N with the precision you want
Vertex  inside [N+1]; // Fill in N with the precision you want

double neg_size = sqrt (1 + NEG_DIST); // Size of intescting circle.
                                       // NEG_DIST is the distance between their centers
                                       //  Greater NEG_DIST => wider crecent

double start_angle = atan (1 / NEG_DIST); // Start angle for the inside edge
double arc = M_PI - (2 * start_angle);    // Arc of the inside edge

for (int i = 0; i <= N; i++)
{
  // Outside edge
  outside [i].x = cos ((M_PI / N) * i) * SIZE;
  outside [i].y = sin ((M_PI / N) * i) * SIZE;

  // Inside edge
  inside [i].x = (cos (start_angle + ((arc / N) * i)) * neg_size) * SIZE;
  inside [i].y = (sin (start_angle + ((arc / N) * i)) * neg_size - NEG_DIST) * SIZE;
}