Rotate sphere in Javascript / three.js while moving on x/z axes

Posted by kaipr on Game Development See other posts from Game Development or by kaipr
Published on 2012-09-18T20:57:21Z Indexed on 2012/09/18 21:54 UTC
Read the original article Hit count: 361

Filed under:
|
|

I have a sphere/ball in three.js which I want to "roll" arround on a x/z axis. For the z axe I could simply do this no matter what the current x and y rotation is:

sphere.roll_z = function(distance) {
      sphere.position.z += distance;
      sphere.rotation.x += distance > 0 ? 0.05 : -0.05;
    }

But how can I roll it along the x axe? And how could I properly do the roll_z? I've found a lot about quateration and matrixes, but I can't figure out how to use them properly to achieve my (rather simple) goal.

I'm aware that I have to update multiple rotations and that I have to calculate how far to rotate the sphere to match the distance, but the "how" is the question. It's probably just lack of mathematical skills which I should train, but a working example/short explanation would help alot to start with.

© Game Development or respective owner

Related posts about math

Related posts about JavaScript