简体   繁体   中英

if() doesn't seem to work - c++ opengl idle function

I want to make a little animation, a bridge with a traffic light witch warns when the bridge will open (yellow light) , red light while the bridge is animating (just moving u and down) and green light when it is down. For now I just want it to repeat the same animation over and over

In the idle function I have this code :

if(bridgeAnimating==0);
{
   printf("\nwtf,%d\n",bridgeAnimating);
   fflush(stdout);
   startBridge=1;
}

animateBridge();

And this is what I get as output: wtf,0 wtf,1 wtf,1...etc

bridgeAnimating is a global variable such as startBridge int startBridge=0; int bridgeAnimating=0;

And here is the function:

void animateBridge()
{
    float static speed=0.25;
    int static upwards=1;
    double static warnTime=teid;

    warnTime-=dt;

    if(startBridge==1)
    {
        upwards=1;
        bridgeAnimating=1;
        warnTime=teid;
        startBridge=0;
        //printf("Here:Animating=%d",bridgeAnimating); //if un-commented this gets printed!!!
    }
    if(bridgeAngle<30 && upwards==1 && warnTime<=0)
    {
        bridgeAngle+=speed;
        red=2;
        green=0.9;
        orangeRed=0.9;
        orangeGreen=0.6;
        bridgeAnimating=1;
        printf("Upwnwards");
    }else if(bridgeAngle>0 && upwards==0 && warnTime<=0) 
    {
        bridgeAngle-=speed;
        red=2;
        green=0.9;
        orangeRed=0.9;
        orangeGreen=0.6;
        bridgeAnimating=1;
        printf("Downwards");
    }else if(warnTime>0)
    {
        orangeRed=2;
        orangeGreen=1.19;
        red=0.9;
        green=0.9;
        bridgeAnimating=1;
        //printf("Here"); //This gets printed if "un-commented"
    }else
    {
        red=0.9;
        green=2;
        orangeRed=0.9;
        orangeGreen=0.6;
        bridgeAnimating=0;
        printf("anim 0");//this doesn't print out
    }

    if(bridgeAngle>=30)
    {
        upwards=0;
    }

}

I checked the document for other references of these 2 variables and there aren't any. It must be something wrong with the algorithm but I can't figure it out. I have a lot of global variables, this is the last one I added is it possible that the stack is full? What is wrong here?

Your problem is this

   if(bridgeAnimating==0); 

The semicolon on the end indicates an empty statement, which is all that is being controlled by the if statement. Get rid of the ; and it will work as you expect.

删除结尾的分号:

if(bridgeAnimating==0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM