Jump to content

[Feature Request] Where is the globalRotation?


Nodragem
 Share

Recommended Posts

Hello,

I attached my player and the camera to the same TransformNode to move and rotate them around together.

Because of that, the rotation of the camera is always zeros (or whatever I made it) in local coordinates. I was a bit surprise to find out that I could not get the rotation in world coordinates as I would with globalPosition.

I thought I may have missed something but @Deltakosh confirmed that globalRotation or globalRotationQuaternion don't exit, he suggested me to use https://doc.babylonjs.com/api/classes/babylon.matrix#decompose instead for the time being.

 I believe that this is not user friendly and should only be a temporary/hacky solution for my project. Hence my feature is to add a globalRotation and globalRotationQuaternion to meshes and compatible Nodes.

Feature Request

add globalRotation and globalRotationQuaternion properties to meshes and compatible Nodes.

 


 

 

Link to comment
Share on other sites

Thank you for this thread:)

So here is why I think we should not do it: whereas globalPosition is easy to compute (last line of the worldMatrix), globalRotation and globalScaling would require a really expensive operation (matrix.decompose). 

I think that the engine should be a guide to make sure games and applications built with it perform well in every situation. Here, if we expose these two properties there is no way we can let people know that they could be expensive and they should be used cautiously. This is why I recommend not adding them and instead add a word about how to compute them in the doc.

Link to comment
Share on other sites

sounds reasonable... but I am not sure why globalRotation has to be an expensive computation, it looks to me that the global Rotation is just something like that:

// start with a null rotation:
globalRotationQuaternion = BABYLON.Quaternion.Identity()

// applying the rotation of all the parents of the mesh:
for parent in mesh.parents:
    globalRotationQuaternion *= parent.rotationQuaternion

// then apply the local rotation of the mesh:
globalRotationQuaternion *= mesh.rotationQuaternion

I mean I am not sure how Quaternions work, so I might be wrong to start with the identity.

The idea is that global Rotation is simply the application of all the rotations of the parents + your own rotation.

I guess that might be what's decompose() is doing?

On 11/12/2018 at 12:11 AM, Deltakosh said:

I think that the engine should be a guide to make sure games and applications built with it perform well in every situation. Here, if we expose these two properties there is no way we can let people know that they could be expensive and they should be used cautiously.

In the API doc, which pop-ups in VS code when you call a function, you can add a warning: this is an expensive operation; use it with moderation.

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