I'm working on a cannon that shoots a cannon ball in OpenGL. I get the ball to move in a line but no arc. The ball is suppose to shoot up and come back down. The two formulas I have to use are:
velocity = velocity +a*dt
position = position + (1/2)*(v_f +v_i)*dt
(Note: try not to use 1/2 in C++, but rather use 0.5)
You will use -32.2 for the second component of acceleration.
In my code above I can't figure out why I don't have the ball going in parabolic form. So basically I just need some tips on the position formula. I'm basically confused with the formula and how it's suppose to do the parabolic. It looks like the code has everything in the formula but not sure if I'm taking the correct steps in the formula. If some one could break down the formula step by step that would be awesome!
W = Add(Vf, Vi); //position = position + (1/2)*(v_f +v_i)*dt
pos = Add(pos, W); //updates position = position + vel
pos = Multiply(W, dt);
pos.scale(0.5); //This multiplies pos by 0.5, i.e. W = 0.5 * W
pos.scale(dt);
}
Do you add the position to (.5) then * (v_f + v_i) * (dt)?