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