有人可以帮我理解这段代码的逻辑吗?它不是画一个圆圈,只是随机的线条。
#include <math.h>
...
void drawCircle(){
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(programObject);
const float DEG2RAD = 3.14159f / 180.0f;
int totalVertices = 360;
const float radsPerLine = (360.f / totalVertices) * DEG2RAD;
float lineVertices[(totalVertices * 4)];
int i;
int ii = 0;
float rad = 0.8f;
for (i = 0; i < (totalVertices); i++) {
float degInRad = radsPerLine * i;
float cosine = cos(degInRad);
float sine = sin(degInRad);
lineVertices[ii++] = 0.0f;
lineVertices[ii++] = 0.0f;
lineVertices[ii++] = cosine * rad;
lineVertices[ii++] = sine * rad;
}
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, lineVertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_LINES, 0, totalVertices * 4);
}
分形模式出现在一个很高的数字(例如 360)。另一个奇怪的事情是有些线条看起来比其他线条高,这也很奇怪。