Jump to content

Retrieving rotation after mesh.lookAt()


iiceman
 Share

Recommended Posts

 

 

Welcome to the wonderful world of quaternions, where there are many weird numbers and none of them make any sense.
 

:D

 

A workaround in your case would be to use the RotationFromAxis() static method here :

 

- define the view direction axis from your mesh to its target

- define two other axis, say Y axis and dot product view axis ^ Y axis

 

this is your axis target system in which you want to align your mesh (so to rotate it)

RotationFromAxis(axis1, axis2, axis3) will give you the rotation angle triplet.

 

Then you know the rotation values in terms of euler angles and you can just apply them to your mesh so it will look at its target

Link to comment
Share on other sites

Yeah, the quaternion stuff is confusing indeed. But jeromes suggestion seems to work for me. Thanks! :D

 

http://www.babylonjs-playground.com/#1QM99D#2

 

 

Edit: Hmm, I spoke too soon. It seems there are points that don't work. If I try to make the mesh look at those points with jeromes method the cube disapears because the new rotation is NaN for x (for example I get something like that as the new rotation: t {x: NaN, y: -0.7783801156008564, z: -0.5008333412587954} ).

 

Click around on the plane and sometimes the cube disappears: http://www.babylonjs-playground.com/#1QM99D#3

 

And here an example with a fixed point where it causes the cube to disappear: http://www.babylonjs-playground.com/#1QM99D#5

 

 

So.... is that a bug or is there a problem with how I do it?

Link to comment
Share on other sites

well, it happens when your axis1 and axis2 are collinear,  I guess, or at least not orthogonal....

You must pass three orthogonal left-handed oriented axis to RotationFromAxis().

In my explanation, I was too fast. In your case, you shouldn't directly choose the Y axis.

 

Well, the mesh direction view (axis1) is mesh-pickedPoint : ok

You could then choose axis3 = axis1 ^ Y  , axis3 is now orthogonal to axis1

and then axis2 = axis1 ^ axis3, axis2 is orthogonal to axis1 and to axis3

 

Just check they are well left handed oriented (else just change the cross product factors order)

Link to comment
Share on other sites

Hmm.. sorry, math class is too long ago. I was not sure what you meant, so I just assume with Y you mean the vector (0, 1, 0) and with ^ the cross product? I played around and tried to do what you told me (according to my interpretation) and it sees to work like that:

 

Click around version (couldn't reproduce the issue with this version): http://www.babylonjs-playground.com/#1QM99D#6

Version with fixed point that didn't work before: http://www.babylonjs-playground.com/#1QM99D#7

 

Sooo.. it's looking good but I am totally unsure if I actually did what you tried to tell me or if I am just making stuff up here :D

 

If I did it right: thank you! (if I missed the point, please show me in a playground, it's easier to understand there :P )

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