【发布时间】:2014-12-02 06:58:05
【问题描述】:
首先,我使用以下资源来生成我的圈子。
http://slabode.exofire.net/circle_draw.shtml
现在我正在尝试使用以下方法将纹理应用于圆形,但我似乎无法正确计算。
void drawCircle(float cx, float cy, float cz,
float r, int points,
float red, float green, float blue)
{
float theta;
theta = 2 * PI / (float)points;
float c = cosf(theta);//precalculate the sine and cosine
float s = sinf(theta);
float t;
int i;
float x = r; //we start at angle = 0
float y = 0;
float tx = c * 0.5 + 0.5;
float ty = s * 0.5 + 0.5;
glPushMatrix();
glTranslatef(cx, cy, cz);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, newBelgTex);
glBegin(GL_POLYGON);
// glColor3f(red/255.0, green/255.0, blue/255.0);
for(i = 0; i < points; i++)
{
glTexCoord2f(tx, ty);
glVertex2f(x, y);//output vertex
//apply the rotation matrix
t = x;
x = c * x - s * y;
y = s * t + c * y;
// Not sure how to update tx and ty
}
glVertex2f(-r, 0);
glEnd();
glPopMatrix();
}
我尝试了一些不同的方法,但在正确更新 tx 和 ty 方面似乎都失败了。
【问题讨论】:
-
见这里:stackoverflow.com/questions/26536570/…。问题是关于圆柱体的,但第一部分(顶盖)显示了如何绘制圆。