Swivel pendulum

I am making a game that you can see here if you are on Windows or Linux: http://insertnamehere.org/birdsofprey/

If you click and hold the mouse on the bird, you can see that I just swing the bird back and forth in the movement of the pendulum. Instead, I would like to implement a more realistic movement when the movement of your mouse affects the swing of the bird like a pendulum with a moving support rod.

I found a document on this topic, but the equations rely on knowledge of the acceleration of rotation (X 'and Y' '), which I do not; I only repeatedly translated the drawing of the bird to the current position of the mouse.

I have a bird angle (-180 to 180 degrees), speed and acceleration angular. I will need to change these three variables every time the mouse moves, 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 a moving axis of rotation?

+4
source share
1 answer

If you can select the mouse position (x, y) with a sufficiently high temporal resolution, you can calculate the accelerations X '' and Y '' numerically. Suppose you 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 we calculate X '' = V '= dv / dt = (v1-v0) / (tv1 - tv0)

Y '' is calculated in the same way. Then you can connect X '' and Y '' to the equations you have already found to calculate the position of the pendulum in the next step.

+4
source

All Articles