【发布时间】:2013-11-09 18:36:31
【问题描述】:
我正在尝试仅绘制 3d 圆的 扇区/部分 - 给出了 2 个角度(开始、结束)、圆心的坐标、圆的半径和宽度. 我在 Photoshop 中绘制了什么结果必须是这样的。
您能帮我做吗(2d 示例,带有 1 条简单的曲线,也可以)?只是想了解如何做到这一点...
p.s.抱歉英语不好
【问题讨论】:
我正在尝试仅绘制 3d 圆的 扇区/部分 - 给出了 2 个角度(开始、结束)、圆心的坐标、圆的半径和宽度. 我在 Photoshop 中绘制了什么结果必须是这样的。
您能帮我做吗(2d 示例,带有 1 条简单的曲线,也可以)?只是想了解如何做到这一点...
p.s.抱歉英语不好
【问题讨论】:
给定半径、圆心 (x0/y0) 和角度(以弧度为单位)的圆上点的计算公式
float x = radius * cos(angle) + x0;
float y = radius * sin(angle) + y0;
使用它来构建相应的三角形带(参见例如http://en.wikipedia.org/wiki/Triangle_strip):
float[] coordinates = new float[steps * 3];
float t = start_angle;
int pos = 0;
for (int i = 0; i < steps; i++) {
float x_inner = radius_inner * cos(t) + x0;
float y_inner = radius_inner * sin(t) + y0;
float x_outer = radius_outer * cos(t) + x0;
float y_outer = radius_outer * sin(t) + y0;
coordinates[pos++] = x_inner;
coordinates[pos++] = y_inner;
coordinates[pos++] = 0f;
coordinates[pos++] = x_outer;
coordinates[pos++] = y_outer;
coordinates[pos++] = 0f;
t += (end_angle - start_angle) / steps;
}
// Now you need to hand over the coordinates to gl here in your preferred way,
// then call glDrawArrays(GL_TRIANGLE_STRIP, 0, steps * 2);
【讨论】:
glBegin() 在 2013 年?真的吗?
glDrawElements() 不会使代码更长,对于当代适当的解决方案付出的代价很小。