一次将退回变量递增 1 - C++

Incrementing a bounce variable by one at a time - C++

本文关键字:变量 C++ 一次      更新时间:2023-10-16

我正在尝试模拟一个弹跳球,它只是吐出x位置,y位置,时间和反弹次数的数字。就物理而言,它运行良好,但问题是,当我尝试增加"反弹"变量时,它每帧增加一个,而不是一个,然后等待下一次反弹。

以下是相关循环:

while(bounces<=maxBounces){
    frames++;
    seconds=frames/1000;    
    if(yPos>=0&&bounces==0){
        initRads=getRads(initAng);
        dropBall(initVel, initRads);    
    }
    if(yPos<0){
        yPos=0;
        bounces++;
        cout.precision(5);
        cout<<seconds<<"t"<<yPos<<"t"<<xPos<<"t"<<bounces<<"n";
        newVel=getVel(currYVel, currXVel, cor);
        newAng = getAng(currYVel,newVel);
        dropBall(newVel, newAng);
    }   
}

你的模拟有点错误。你应该有一个 else 分支,如果yPos<0执行dropBall.