Hi all, I am in the process of developing a project that will require the flicking or FLICK MOTION of an object such as a ball...obviously it will have to travel through a trajectory based on the position and the path travelled by the finger on the iphone screen...Please can anyone help me out with the code or how to go about getting this physics sorted as I am lost. Thanks.
+2
A:
Motion is defined by Newton's laws of physics. In particular, F = ma, which is equivalent to d2p/dt2 = F/m. If you don't know calculus, this will be a little tough to grasp.
The i-just-want-it-to-work answer is to use a regular time quantum (1/60 s is common for game engines), during which you use the acceleration due to gravity to update the velocity, and the velocity to update the position:
dt = 1.0/60.0;
v += g*dt;
p += v*dt;
This is done using vector arithmetic, so in practice (unless you write or steal a C++ vector library) you'll end up writing something like v = vec_add(v, vec_mulf(g, dt))
.
Marcelo Cantos
2010-06-23 23:59:05
Hi Marcelo, thanks a million I think I still have a lot of work to do in terms of dusting my mathematics books... I never really thought about that all I was thinking was that there was a code in the iphone reference lib that could take care of this.Please I do not wish to bother you and ask for too much but can put me in the clear about what the expression v = vec_add(v, vec_mulf(g, dt)) means and what it will actually do. Thanks a lot.
BUNBA
2010-06-24 22:54:17