Hi,
I am using JBox2D. I am trying to simulate the curved trajectory of a spinning ball as it travels through the air, say like a tennis or ping-pong ball. I've achieved this so far in the test bed by overriding the step method and applying the following code:
This appears to have the effect that i want, although i'm not sure that the physics is exactly right. More so, i wondered if there were a better way of implementing it. I'm using a FrictionJoint for the linear and angular friction, and thought it might be appropriate to add the code there (plus a new field to represent the hardcoded 0.0001F).
Any recommendations are welcome.
Regards,
Matthew
I am using JBox2D. I am trying to simulate the curved trajectory of a spinning ball as it travels through the air, say like a tennis or ping-pong ball. I've achieved this so far in the test bed by overriding the step method and applying the following code:
Code: Select all
Vec2 curveImpulse = new Vec2();
@Override
public synchronized void step(TestbedSettings settings) {
super.step(settings);
if (ballBody.m_angularVelocity != 0) {
Vec2.crossToOut(ballBody.m_angularVelocity * 0.0001F, ballBody.m_linearVelocity, curveImpulse);
ballBody.applyLinearImpulse(curveImpulse, ballBody.m_sweep.c);
}
}
This appears to have the effect that i want, although i'm not sure that the physics is exactly right. More so, i wondered if there were a better way of implementing it. I'm using a FrictionJoint for the linear and angular friction, and thought it might be appropriate to add the code there (plus a new field to represent the hardcoded 0.0001F).
Any recommendations are welcome.
Regards,
Matthew