2
\$\begingroup\$

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

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

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

translation.add(movement);
m.setTranslation(translation);
myBall.body.setCenterOfMassTransform(m);

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

\$\endgroup\$
  • \$\begingroup\$ What do you mean by "strangely"? Does it rotate around your chosen axis a = (z,0,-x) or not? \$\endgroup\$ – mvw Mar 10 '16 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\$ – Adrian Śliwa Mar 10 '16 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 '17 at 1:02
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.