有人可以帮助我理解这段代码的逻辑吗?它不是随便画一个圆圈。基于Android OpenGL ES Line的圈子
#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)。另一个奇怪的事情是有些线条比其他奇怪的线条看起来更高。
您将要覆盖在每次迭代先前计算的数据相乘。你应该增加2我 – Trax
谢谢,有一点帮助,但看看我准备写更新。 – Jackie
你的新代码仍然是错误的,后缀++运算符在发射一个值后发生,这意味着lineVertices [ii ++] = sin(degInRad)* 0.8f;正在覆盖以前的数据。将其改为++ ii。 – Trax