I'm moving my sphere on the screen using this method:

Matrix4 m = myBall.body.getCenterOfMassTransform();
Vector3 translation = new Vector3();

float multiplier = delta * 4 * game.platform.accelerometerFactor();
movement = new Vector3(Gdx.input.getAccelerometerY() * multiplier, 0, Gdx.input.getAccelerometerX() * multiplier);


Then I would like to rotate my sphere during movement. So I counted angle which sphere should be rotated and then applied it before I call myBall.body.setCenterOfMassTransform(m) using:

float x = movement.x;
float z = movement.z;
Vector3 axis = new Vector3(z, 0, -x);
m.rotate(axis, angle);

But the sphere is rotating strangely. Where is the problem in my process of rotation?

enter image description here

  • \$\begingroup\$ What do you mean by "strangely"? Does it rotate around your chosen axis a = (z,0,-x) or not? \$\endgroup\$
    – mvw
    Mar 10, 2016 at 11:28
  • \$\begingroup\$ Strangely means it does not move like in normal world when it is moving on surface. Yes it doesn't move correctly around axis = (z,0,-x) \$\endgroup\$ Mar 10, 2016 at 12:27
  • \$\begingroup\$ I wonder if, depending on your multiplication conventions, the rotation is being applied with respect to the ball's local x & z axes (which wobble around as it rolls to produce a chaotic result) rather than the world's x & z axes. Switching to one of the matrix's premultiplication methods would be a way to test for this. \$\endgroup\$
    – DMGregory
    Jul 8, 2017 at 1:02

1 Answer 1


It seems to me that the axis of rotation should be a positive multiple of

a = v x (-e_z) = (vx, vy, vz) x (0, 0, -1) = (-vy, vx, 0)

where v is the velocity vector, e_z the unit vector in z direction and x the vector product.


You must log in to answer this question.

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