Jump to content

Rotating a mesh in the render loop


neoRiley
 Share

Recommended Posts

I know I must be missing something very simple, but for the life of me, I can not get a simple object to rotate in local space DURING a render loop.  When I create it and then rotate, it works fine, but during the render loop it will not rotate locally.

 

http://jsfiddle.net/neoRiley/ZTD4K/8/

 

I've set up the simplest of examples here and if someone could just point me to *why*, I'd be grateful!  Rotating in world space works fine btw.  If this were working correctly, then we would see the sphere doing vertical donuts on it's Y axis (object is rotated -90 on x axis before animation starts).

 

I had thought, like Mesh.position, that Mesh.rotation was also the local values, but simply updating Mesh.rotation.y += .01 does nothing.

 

On top of that, I created a mesh called origin in my app, and set it's rotation and position to be the starting point for other meshes.  When I went to clone origin.rotation, the values were zero, even though I could clearly see that it was rotated.  So, my concern is that Mesh.rotation is not being updated or used each frame render?  Just guessing out loud here.

 

Thanks for the help,

 

John

Link to comment
Share on other sites

I should elaborate:  in that sample, the marker is NOT parented and that's fine, so what I would have assumed was that setting values on the world rotation would have been relative to whatever direction the object was facing in world space.

 

ie: I rotate the object -90 on X, I would expect that rotating on Y would look like it's rotating on X, but in reality, it's the Y axis.  

 

So, maybe my question should be "why doesn't world rotation respect the direction the mesh is facing?"

 

updated example: http://jsfiddle.net/neoRiley/ZTD4K/9/ - is told to rotate on Y, and in world space, it is, but this is supposed to be relative to the direction of the mesh's transform, and its not.

 

Hope that helps,

 

John

Link to comment
Share on other sites

I found the problem thankfully!

 

Originally, I'd copied this bit of code from the tutorials that showed how to do rotation in world space ( https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translations ):

var rotationToApply = BABYLON.Quaternion.RotationYawPitchRoll(y, x, z);mesh.rotationQuaternion = rotationToApply.multiply(mesh.rotationQuaternion);

After looking at it closer, I switched it to have the mesh.rotationQuaternion multiply the rotaionToApply quat, and bingo -  it's seems to work.

var rotationToApply = BABYLON.Quaternion.RotationYawPitchRoll(tempV3.y, tempV3.x, tempV3.z);if( this.rotationQuaternion == null ) this.rotationQuaternion = new BABYLON.Quaternion(0,0,0,1);this.rotationQuaternion = this.rotationQuaternion.multiply(rotationToApply); // works

I'll be updating Neo.js and testing a bit more, but at least we now have a much simpler way of translating in world and local rotations.

 

updated fiddle using updated Translate method of Neo.js: http://jsfiddle.net/neoRiley/ZTD4K/10/

 

Hope this helps

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...