【发布时间】:2010-04-08 01:07:04
【问题描述】:
在使用 C++ OpenGL 制作一个小型 Pong 游戏时,我认为在弹跳时创建弧线(半圆)会很有趣。我决定暂时跳过贝塞尔曲线,直接使用直代数,但我并没有走多远。我的代数遵循一个简单的二次函数 (y = +- sqrt(mx+c))。
这个小摘录只是我尚未完全参数化的一个示例,我只是想看看它的外观。然而,当我画这个时,它给了我一条直线,直线的切线接近 -1.0 / 1.0。
这是 GL_LINE_STRIP 样式的限制还是有更简单的方法来绘制半圆/弧?还是我完全错过了一些明显的东西?
void Ball::drawBounce()
{ float piecesToDraw = 100.0f;
float arcWidth = 10.0f;
float arcAngle = 4.0f;
glBegin(GL_LINE_STRIP);
for (float i = 0.0f; i < piecesToDraw; i += 1.0f) // Positive Half
{ float currentX = (i / piecesToDraw) * arcWidth;
glVertex2f(currentX, sqrtf((-currentX * arcAngle)+ arcWidth));
}
for (float j = piecesToDraw; j > 0.0f; j -= 1.0f) // Negative half (go backwards in X direction now)
{ float currentX = (j / piecesToDraw) * arcWidth;
glVertex2f(currentX, -sqrtf((-currentX * arcAngle) + arcWidth));
}
glEnd();
}
提前致谢。
【问题讨论】: