我试图画螺旋形,但我却画了圆。
for(int i = 0 ; i < 121; i++)
{
for(int a = 0 ; a <= 3; a++)
{
if(a == 1){
vertires_chikl[d] = GLfloat(X + R * cos(t));
d++;
}
if(a == 2){
vertires_chikl[d] = GLfloat(Y + R * sin(t));
d++;
}
if(a == 3){
vertires_chikl[d] = GLfloat(0.0);
d++;
}
}
t = t+ 0.256f;
// we are moving in a circle
R = R + 0.00001f;
// circle shifted to the side (right and up)
// Y = Y+ 0.0001f;
// X = X+ 0.0001f;
}
为什么我做错了????
当我尝试更改功能时。我记得增加变量R时,周长应该有所增加和变化。难道为什么???
不带注释的R
后5秒:3
答案 0 :(得分:1)
谢谢tkausl。
错误是全局变量static float R = 0.4f; // Radius of circle.
我将此设置为本地
float R = 0.4f; // Radius of circle.
for(int i = 0 ; i < 121; i++)
{
for(int a = 0 ; a <= 3; a++)
{
if(a == 1){
vertires_chikl[d] = GLfloat(X + R * cos(t));
d++;
}
if(a == 2){
vertires_chikl[d] = GLfloat(Y + R * sin(t));
d++;
}
if(a == 3){
vertires_chikl[d] = GLfloat(0.0);
d++;
}
}
t = t+ 0.256f;
// we are moving in a circle
R = R + 0.004f;
// circle shifted to the side (right and up)
// Y = Y+ 0.0001f;
// X = X+ 0.0001f;
}
结果