Jump to content

How to rotate a sphere around a tilted axis?


d13
 Share

Recommended Posts

Hi Everyone!

I'm trying to figure out how to do the following:

1. Tilt a sphere about 20 degrees on it's z axis.

2. Then spin the sphere around its tilted axis.

The code I've been using up till looks something like this:

When I create the mesh, I set up its z rotation like this:

mesh.rotation.z = tiltValue * 180 / Math.PI;

This does give me the axis that I need.

Then I've been trying to spin the sphere around that tilted axis in the game loop, like this:

mesh.rotation.y -= rotationValue

But, this causes the mesh to wobble around the y and z a axis instead of spinning on the tilted y axis.

That seems to make sense, but I don't know how to get the effect I need.

 

Can anyone help?

I've tried some of the code from this older thread

 

 

Specifically this bit:

mesh.rotate(BABYLON.Axis.z, 1, BABYLON.Space.LOCAL)

... but this throws an error: TypeError:

t is undefined babylon.js:7:6425

 

I don't know if I'm on the right track or not, but any help will be much appreciated! :)

 

Link to comment
Share on other sites

Hi d13.  I used about the same method as you... but it worked.

https://www.babylonjs-playground.com/#012I9K#2

*shrug*  :)  My "local" isn't all-caps, just the first letter.  Not sure if that is the issue.

Update:  Oh, when I change my .Z to .z, I get the same error as you.

https://www.babylonjs-playground.com/#012I9K#3

I bet your "z" should be capitalized.  weird.

Link to comment
Share on other sites

If you use Quaternions, you can multiply rotations.

Feel free to copy from my code:
http://www.bitofgold.com/solarsystem/

Like this:

Setup:
mesh.baseRotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(0.0, 0.0, 20.0 * Math.PI / 180, 0.0));
mesh.rotationQuaternion = new BABYLON.Quaternion();


...
at every frame:

mesh.rotationQuaternion.copyFrom(mesh.baseRotationQuaternion);
mesh.rotationQuaternion.multiplyInPlace(BABYLON.Quaternion.RotationYawPitchRoll(alpha, 0.0, 0.0));

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...