views:

62

answers:

1

I'm making a game which you can see here, if you are on Windows or Linux: http://insertnamehere.org/birdsofprey/

If you click and hold your mouse on a bird, you can see I'm just swinging the bird back and forth in pendulum motion. I would like to, instead, implement a more realistic motion, where the movement of your mouse affects the swinging of the bird like a pendulum with a moving pivot.

I found a document on this topic but the equations rely on knowing the pivot's acceleration (X'' and Y''), which I do not; I am only repeatedly translating the bird graphic to the current mouse position.

I have the bird's angle (-180 to 180 degrees), angular velocity and acceleration. I will need to alter these three variables each time the mouse is moved, so I will also have the last (x,y) and the new mouse (x,y).

Is this enough to make a good simulation of a pendulum with moving pivot?

+2  A: 

If you can sample the mouse position (x,y) at a high enough time resolution, you can calculate the accelerations X'' and Y'' numerically. Suppose you've measured three X positions at known times: (x0, t0), (x1, t1), (x2,t2).

Calculate v = X' = dx/dt for the intervals (t0, t1) and (t1, t2):

v0 = (x1 - x0)/(t1 - t0) at time tv0 = (t1 - t0)/2

v1 = (x2 - x1)/(t2 - t1) at time tv1 = (t2 - t1)/2

Then calculate X'' = V' = dv/dt = (v1-v0)/(tv1 - tv0)

Y'' is calculated similarly. Then you can plug X'' and Y'' into the equations you've already found, to calculate the pendulum position at the next time step.

Jim Lewis