1
在C++ OpenGL中制作一个小型Pong游戏时,我决定当东西弹跳时创建弧线(半圆形)会很有趣。我决定暂时跳过贝塞尔曲线,直接用直的代数去走,但是我没有走得很远。我的代数遵循一个简单的二次函数(y = + - sqrt(mx + c))。如何在OpenGL中绘制弧线
这个小节选仅仅是一个我尚未完全参数化的例子,我只是想看看它的外观。然而,当我画这个时,它给了我一条垂直线,直线的切线接近-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();
}
在此先感谢。
呀,有个白痴。不知道为什么我决定使用抛物线,而不是回想起记住我的单位圈子。 我想我挂断了为什么有一条垂直线穿过我的线条画。 谢谢 – rpgFANATIC 2010-04-08 22:40:04