无法使阿基米德螺旋式上升

时间:2019-02-21 05:15:14

标签: opengl

我试图画螺旋形,但我却画了圆。

    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;
    }

enter image description here

为什么我做错了????

当我尝试更改功能时。我记得增加变量R时,周长应该有所增加和变化。难道为什么???

matematik model i give there

不带注释的R

enter image description here

后5秒:3

enter image description here

1 个答案:

答案 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;
    }

结果

enter image description here