Free Autumn Question

Well, I will try my best to explain my problem. I have this program where you can choose 5 goals. When you select it, you can drag it while you click the mouse button, and the cursor is within the radius of the ball.

The problem is that I need a way to make the ball rise when the user stops pressing the mouse button, as if he sent it to the float in the air, and then fell again. I have one way to find out time, speed, and therefore acceleration, but I don’t know how to implement it.

Now I have this:

void Circle::Fall(float velocity,float time)
{    
    if(this->posY >= 580)
    {
        this->posY = 580;
        this->vfall= 0.0f;
    }
    else if(this->posY < 580)
    {
        //this->distance=9.81f * 0.5f*time*time;
        this->vfall+= velocity;
        this->posY += this->vfall;
    } 
}

With this, he simply falls, and I cannot make the effect that I was trying to explain.

In addition, I am calculating a time like this (just in case, it helps):

difX=(x> event.motion.xrel)? x-event.motion.xrel : event.motion.xrel-x;
difY=(y> event.motion.yrel)? y-event.motion.yrel : event.motion.yrel-y;

And I use difYas a time variable


, , . :

, , , . - Y. SDL,

, ,

+3
3

, : .

+2

, , .

, . , , .

, this->yVelocity ( ; D) this->yPosition, gravityMagnitude, - -0.1.

, - :

this->yVelocity += gravityMagnitude; //Subtracts 0.1
this->yPosition += this->yVelocity; //Make it actually move

, .

, , , , :

this->yVelocity = 2.0; //Or some other positive number

.

+2

. suvat , , :

           1   2
s = ut  +  - at
           2
  • s - ( ).
  • u - .
  • t - .
  • a - .

, , () 5 , -9,8 ( ), 0,2 .

, (), , .

, , () ( ), .

, . ( ) , , (, ).

+1
source

Source: https://habr.com/ru/post/1742633/


All Articles