Projectile OpenGL

I am working on a project for school and am stuck. I need to update a loop using vectors to make a cannon fire like it actually would. I got it to fire but the distance is not as far as it should. Here is the part that I am having trouble with.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 void Update(float dt) {
        Vector3 acceleration;
Vector3 initvel,Vi,Vf,U; //initial velocity vector, or old velocity vector
initvel = vel; // initial velocity is initialized to the current velocity
Vi.set(20,40,10);
Vf.set(200,600,-300);
Vi.scale(-2);
U = Add(Vi,Vf);
acceleration = Add(vel,U);
		acceleration.set(0, -32.2, 0);	// acceleration (x,y,z)=(0,-2,0) 
		acceleration = Add(acceleration,initvel);
		acceleration.scale(2);
		vel = Add(initvel, acceleration);              //velocity = vvelocity + acceleration
		
		vel.scale(dt);                           //this is velocity= velocity*time
        
		
		
		
        pos = Add(pos, vel);                    //updates position = position + vel
		

    }
I think I have all of the math correct but I'm not sure. I know the equations that I need are velocity = velocity +a*dt
position = position + (1/2)*(v_f +v_i)*dt
but I am not sure how to do them with vectors. I just need pointed in the right direction about how to code it.
Looking at your code I see you are hard coding the velocity. This is causing the sphere to come out and pause. Try something like this..see you tuesday lol.

void Update(float dt) {
int Vi;
int Vf;
int a;

Vector3 acceleration;
Vector3 initvel; //initail velocity vector, or old velocity vector
initvel = vel;

acceleration.set(0, -2, 0); // acceleration (x,y,z)=(0,-2,0)
acceleration.scale(dt);
vel = Add(vel, acceleration); //velocity = vvelocity + acceleration

Vector3 delta_pos = Add(vel,initvel);
delta_pos.scale(0.5*dt);
//this is velocity= velocity*time
pos = Add(pos,delta_pos); //updates position = position + vel


}
Thank you. I thought I had it a couple times it wasn't the way that it needed to be.
Topic archived. No new replies allowed.