3
\$\begingroup\$

Why is it when I drag a JBox2d Body with the mouse, the vertical component is flipped?

e.g. If I drag down-right, the Body moves up-right.

Is this expected behaviour, a bug in JBox2D, a Mac incompatibility or something else?

I'm on a Mac (10.9.3) with Java 1.7.60, JBox2d 2.2.1.1. I thought it might be Mac's "natural scrolling" but changing that setting didn't have any effect.

\$\endgroup\$
3
  • \$\begingroup\$ Are you sure you're rendering it the right way up? Many graphics libraries set the origin of their coordinate space in the top left corner, such that a more positive y-coordinate actually means further down on screen. \$\endgroup\$
    – Anko
    Jul 7, 2014 at 12:59
  • \$\begingroup\$ Great thought. This is the latest version of JBox2d without any code changes. Running tests, eg car. \$\endgroup\$
    – null
    Jul 7, 2014 at 13:19
  • 1
    \$\begingroup\$ p.s. The body objects (e.g. Car) are the right way up. Also gravity works down the page. \$\endgroup\$
    – null
    Jul 7, 2014 at 23:59

2 Answers 2

0
\$\begingroup\$

As you did not show your code it's hard to answer. This is my answer.

When pressing the mouse I move my 'kicker' into position and stun it's velocity. When the mouse is released I apply the mouse direction as an impulse.

void mouseDragged()
{
  kicker.setPosition(physics.screenToWorld(new Vec2(mouseX, mouseY)));
  kicker.setLinearVelocity(new Vec2(0,0));
}

void mouseReleased()
{

  Vec2 impulse = physics.screenToWorld(new Vec2(mouseX - pmouseX, mouseY - pmouseY));
  impulse = impulse.mul(10);
  kicker.applyImpulse(impulse, kicker.getWorldCenter());
}

If you do not stop the 'kicker' it retains it's current impulse and it's new direction will not match the users intent.

\$\endgroup\$
1
  • \$\begingroup\$ Hi Clemens. Sorry for a late response. From memory there was change in the directions between versions of the JAR. I updated to the later JAR and the drag direction became correct. \$\endgroup\$
    – null
    Sep 5, 2016 at 2:44
0
\$\begingroup\$

There was change in the directions between versions of the JAR. I updated to the later JAR and the drag direction became correct.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .