# Thread: Projectile C++ and OpenGL

1. ## Projectile C++ and OpenGL

Code:
```void Update(float dt)
{
Vector3 acceleration;
Vector3 Vi, Vf, W;
Vi.set(5, 20, 10);
Vf.set(400, 200, -900);

acceleration.set(0, -32.2, 0);				// acceleration (x,y,z)=(0,-2,0)

vel = Add(vel, acceleration);			//velocity = velocity + acceleration
vel.scale(dt);							//velocity = velocity +a*dt

W = Add(Vf, Vi);                 		//position = position + (1/2)*(v_f +v_i)*dt
pos.scale(0.5);							//This multiplies pos by 0.5, i.e. W = 0.5 * W
pos.scale(dt);

}```
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!

Do you add the position to (.5) then * (v_f + v_i) * (dt)? 2. position = position + velocity*dt since, after all, velocity has the same relationship to position (rate of change) as acceleration does to velocity.

I don't know what your v_f and v_i are supposed to be -- they lead me to think of "final velocity" and "initial velocity", but in this case you have no idea what the final velocity could possibly be. 3. Yeah I was thinking the same thing just not sure how I would float the final velocity. 4. You don't know what the final velocity is. That's why you don't use that formula, but instead use position = position + velocity*dt. (If nothing else, you need to be using a changing value for velocity, otherwise you have no acceleration.) 5. More cross-posting madness and selfishness
Projectile OpenGL With C++ - C And C++ | Dream.In.Code

How To Ask Questions The Smart Way

Stop clogging up multiple forums with the same question at the same time. You're WASTING valuable help time by running around with the "me me me me me" attention grabbing. 6. Originally Posted by Salem You're WASTING valuable help time by running around with the "me me me me me" attention grabbing.
You're the only one looking for attention here. Get over yourself. They're completely unrelated, unaffiliated forums on different domains. 7. Read how to ask a question, and stop assuming yours is the only question on the net worth answering!

Actually, you're not even the OP, you're just a thread jumping troll that just likes to sound off. Popular pages Recent additions 