Jump to content

Rotation vector always zero in Babylon 2.4


ozRocker
 Share

Recommended Posts

On 5/28/2016 at 5:25 AM, ozRocker said:

Does anyone know how to get the rotation of an object in Babylon 2.4?  mesh.rotation is always zero.  I can't set absolute rotation either.

Hi OzR.  You might have confused mesh.rotate() and mesh.rotation.  mesh.rotation = new BABYLON.Vector3(x, y, z);  ...will always work fine, but as you now know, mesh.rotate() sets the quat, and mesh.rotation doesn't get updated continuously.  (you could do it yourself in the renderLoop, but no, don't do that, something will explode.)

Okay, if you must...  then in the render loop... if (mesh.rotationQuaternion ) { mesh.currentEulerAngles = mesh.rotationQuaternion.toEulerAngles() }

Don't let the quat make "pokes" into mesh.rotation.  Could be trouble.  Also, this activity could mega-bog the scene.

Yuh, you forgot all about the mesh.rotation = vec3 method... and it is a little offended by that uncaring neglect.  :D 

You've been giving all of your love and attention to .rotate(), right? (just trying to be funny, OzR) 

No sweat... I tried to set the diffuseColor on a texture yesterday.  MANY times I've tried to set a color with a vector3.  hellllooooo... wingy?  Anyone home?  :)  It's part of the fun.  Hat's off to DK... excellent forum custodianship.  (63rd time you've answered this question, DK?  *nod*  *hug*)  :)  Quats are the "ghosts" of the forum, it seems... generating many confusions and discussions.

Link to comment
Share on other sites

yeh, well the reason I was confused was because I was using both mesh.rotate() and mesh.rotation back in version 2.3.  I'd rotate my avatar with relative movements using mesh.rotate() then if I wanted to find out where he was facing I'd read from mesh.rotation.  But its all good now cos I can use  quaternion.toEulerAngles instead

Link to comment
Share on other sites

Hi again.  I don't know if that is true, OzR.  I don't think there has been any recent changes, but maybe.

As far as I know... any rotate()... or yawPitchRoll()... or physics rotational impulsing... will NOT be updated into mesh.rotation property.

Thus, I don't see how you used mesh.rotate(), and got fresh values in mesh.rotation.  As @Temechon mentions, mesh.rotation is set to 000 when quat is created.  This is also why we see mesh rotations getting "nulled-out" when mesh.setPhysicsState.  Physics needs the quat... and makes one, which nulls .rotation. (I think)

Heck, I don't know.  I'm probably wrong.  Framework could have changed.  Maybe you are correct, Oz.  My curiosity is piqued, to say the least.  :)

 

Link to comment
Share on other sites

nod, DK... thx.

http://www.babylonjs-playground.com/#1JNDSK#12

Here I am using rotate()  [a Quaternion thing] in both LOCAL and WORLD spaces (lines 43-48)... and I see no sphere.rotation updates happening.  (normal, I think)

(see blue-text reporter above canvas)

@ozRocker  If you DID see quat rotations... being reported in mesh.rotation... in BJS 2.x...  I want to know about that, ok Oz?  Thanks.  I don't think that changed in any recent versions.

http://www.babylonjs-playground.com/#1JNDSK#13

In the above PG, I added prop sphere.curEuler, and I am updating IT... from quat.toEulerAngles... continuously. 

We see some FPS loss... not much.  Ozzy, keep in mind that sphere.rotation is a getter AND setter.  I could have continuously sent sphere.rotationQuaternion.toEulerAngles() => sphere.rotation... but BECAUSE .rotation is a setter... it doesn't work.  I tested it. 

http://www.babylonjs-playground.com/#1JNDSK#14

The sphere's rotation goes bonkers, and sphere.rotation STILL doesn't ever leave 0, 0, 0.  I would have thought sphere.rotation would have been some garbage numbers.  But nope, 0, 0, 0.  This ALMOST indicates that... not only is sphere.rotation set to 0,0,0 when the quat is MADE, but it is also set to 0,0,0 each time the quat CHANGES.

But, somebody once told me...that you can't "edit" (change) a Quat, you can only replace it with a different one.  THAT might explain why .rotation stays at 0,0,0 even as we stream quat.toEulerAngles() into it.  Maybe every time we do a .rotate(), a new quat is made... and thus... it re-zeroes .rotation during every .rotate() usage.

sphere.curEuler (used in #13) doesn't have 'setter' power, so it is a good place to continuously monitor sphere.rotationQuaternion.toEulerAngles() values... on a case-by-case basis.  DK and the core Gods COULD add .curEuler or similar and have it update just like I did in #13... but... it is likely not worth the bog-per-usefulness hit. 

Setters and getters... yuh yuh yuh.  I wonder if Dublin-based @Nockawa has ever coded Irish setters?  ar ar ar!  :)  Party on!

PS:  Anyone seen @Dad72?  I miss him.  If he doesn't come back and visit soon, I'm forming a search and rescue crew.  :)  He might have been kidnapped by Lerps or something.

Link to comment
Share on other sites

5 hours ago, Wingnut said:

But, somebody once told me...that you can't "edit" (change) a Quat

I edit quats all the time.

Maybe you are talking about editing a single x, y, z component thinking that it will affect the rotation like it does with eulers.  You have to do the correct math and then set x, y, z, w.

Link to comment
Share on other sites

4 hours ago, Wingnut said:

PS:  Anyone seen @Dad72?  I miss him.  If he doesn't come back and visit soon, I'm forming a search and rescue crew.  :)  He might have been kidnapped by Lerps or something.

@Wingnut I'm here, but I spend less often being on a creation project of a carpentry workshop,my first profession, I love. I also like manual works, make furniture. . . I need physical activity right now. :)
But thank you for your attention. If you want to help me do my workshop, I give free training in carpentry after.:D

Link to comment
Share on other sites

@adam - if you need to set all 4 values, isn't that replacing the quat?  Ok, maybe it's not TRUE replacing... I guess.  :)  Thanks for the info, Adam.

@Dad72 - good to hear from you.  Sure, I'll come do some sanding (about the only thing I'm qualified to do).  :)  Good luck on the project.  Remember the old joke about smelling the wood to identify where it came from?  The punch line was something about a restroom door from a tuna boat... err something like that.  You can imagine the rest of the joke.   (eww)

Ahem.  Alrighty then.  :)  Moving right along.  heh

Link to comment
Share on other sites

Ok, I  had to do some more fun tests.

SO... I was thinking about what Adam taught me... no editing allowed... of the discreet components of sphere.rotationQuaternion. 

Changing quat x, y, z, or w... would not give ANY good/expected results.  But I thought... hmm.  I bet quat.w... could be animated/edited/changed... without meshing-up the mesh.  ;)

I was right... http://www.babylonjs-playground.com/#1JNDSK#16   (line 61)  Look at that!  Animating quat.w has no affect whatsoever.  Ok, we MUST try the other 3 quat values, now.

"Line 58, 59, 60... animators... ENGAGE!"  http://www.babylonjs-playground.com/#1JNDSK#15   

Oh my goodness.  It's easy to see that the sphere quickly becomes angry with us.  Things like this... can void manufacturer warranties on your motherboard.  And, you could lose a finger.  ;)  Yuh, live-poking quat.w was certainly allowed, and no trouble seen... other than almost yawning to death.  heh

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