在 OpenGL 中绘制新月形状
如何在 OpenGL 中绘制 2D 新月或月亮形状?我尝试过使用 sin 和 cos ,就像我画圆时所做的那样,但因为新月内部有一个“切口”,所以 sin 和 cos 看起来不够。我也不知道如何在两个多边形之间进行相交。所以我在想是否有一个绘制新月的数学公式?
How can I draw a 2D crescent or moon shape in OpenGL? I have tried using sin and cos like how I did for drawing circles but because a crescent has a "cut" inside it, the sin and cos don't look enough. I couldn't figure out how I could do an intersection between 2 polygons either. So I'm thinking if there a mathematical formula for drawing the crescent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在数学上并不正确,但它可能足以满足您的需求:
或者
在
fullness=1
时,它将绘制一个大小为scale
的圆,而在>fullness=-0.99f
,它会画出一个很细的新月。您可以使用两个不同的填充度值:rightFullness
和leftFullness
,并始终将其中之一设置为1.0f
,以便您可以更改填充方向新月。This isn't mathematically correct, but it may be close enough to meet your needs:
or
At
fullness=1
, it will draw a circle of sizescale
while atfullness=-0.99f
, it will draw a very thin cresent. You could use two different fullness values,rightFullness
andleftFullness
, and always set one of them to1.0f
so you can change the direction of the crescent.您可以绘制两个相互相交的垂直椭圆。从其中一次日食中切出的空间形成了新月。绘图时可以使用按位与非逻辑运算符去除交集。
完成此操作的漫长方法是指定一堆顶点,这些顶点形成您想要的形状的骨架。然后,您可以使用 GL_LINES“连接点”来绘制形状。如果您想要更平滑的形状,可以使用顶点作为 Bezier/Catmull-Rom 样条线的控制点,该样条线将绘制一条连接所有顶点的平滑曲线。
You can draw two perpendicular ellipses that intersect each other. A crescent is formed with the space that is cut out from one of the eclipses. The intersection can be removed by using a bitwise NAND logical operator when drawing.
The long way of doing it is to specify a bunch of vertices that form a skeleton for the shape that you want. You can then 'connect the dots' with GL_LINES to draw your shape. If you want a smoother shape, you can use the vertices as control points for a Bezier/Catmull-Rom spline that would draw a smooth curve joining all your vertices.
您可以尝试以下操作:
这会生成新月的相交多边形版本。它将为您提供新月形内弧和外弧的坐标数组。然后你可以通过你最喜欢的绘制方法来提供这些。
注意:内部和外部的端点重叠(我这样做是为了避免到处都是 +/- 1)。我很确定 GL 程序会很好地处理它,但如果你有一个栅栏错误,这可能就是它的来源
You can try this:
This produces the intersected polys version of a crescent. It will give you an array of coordinates for an inside and outside arc for a crescent. Then you can feed these through your favorite draw method.
NOTE: The endpoints of inside and outside overlap (I did this so that I wouldn't have +/- 1's all over the place). I'm pretty sure a GL program will be fine with it, but if you have a fence post error with this, that may be where it came from