user2988064
user2988064

Reputation: 1

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

I'm trying to make a simulation of a bouncing ball, one which just spits out the numbers of the x-position, y-position, time and number of bounces. It works perfectly as far as the physics goes, but the problem is that when I try to increment the 'bounces' variable, it increases by one every frame, instead of one, then waiting for the next bounce.

Here's the relevant loop:

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

Upvotes: 0

Views: 341

Answers (1)

Sorin
Sorin

Reputation: 11968

Your simulation is a bit wrong. You should have an else branch on if yPos<0 that does a dropBall.

Upvotes: 1

Related Questions