ParadoxMaster

Rotation to the target vector

Recommended Posts

Is the face a vector ? If yes, then what you can do is -
First find the new direction; this can be achieved by doing (some coord - face vector)

After that you have find the angle between the old face vector and the new vector found by step 1. Use this angle to rotate the object mesh

Share this post


Link to post
Share on other sites
4 minutes ago, ssaket said:

Is the face a vector ? If yes, then what you can do is -
First find the new direction; this can be achieved by doing (some coord - face vector)

After that you have find the angle between the old face vector and the new vector found by step 1. Use this angle to rotate the object mesh

Face is just initial direction of my object without rotation (front side of my mesh). I do not sure understand how i can get the vector of this direction.

Share this post


Link to post
Share on other sites
44 minutes ago, ssaket said:

Use  (some coord - position vector of object) to find the new direction, then using face normal's direction vector as old face vector , find the angle between them. 

Not so fast.. I can't get it.

I do not understand how to get face normal's direction vector.. I need to create Vertex Normal's Data?

And the function for calculating angle between Vectors has a third parameter, it is not clear what should be in it..

There is a playground: https://www.babylonjs-playground.com/#ADGVAT#1

 

Share this post


Link to post
Share on other sites

Hello, I thought you know the face direction; well anyways, in the skull example, first task would be to figure out the direction which we know is the face. As of now, I use pickInfo to find the index. Here check it out https://www.babylonjs-playground.com/#ADGVAT#2
You need to click on the face first then it will rotate to sphere's position.

Edit: for skull mesh, the front normal index is 49731(approx.), if you have this you can't skip the pickInfo part, here https://www.babylonjs-playground.com/#ADGVAT#3

Share this post


Link to post
Share on other sites
21 minutes ago, ssaket said:

Hello, I thought you know the face direction; well anyways, in the skull example, first task would be to figure out the direction which we know is the face. As of now, I use pickInfo to find the index. Here check it out https://www.babylonjs-playground.com/#ADGVAT#2
You need to click on the face first then it will rotate to sphere's position.

Edit: for skull mesh, the front normal index is 49731(approx.), if you have this you can't skip the pickInfo part, here https://www.babylonjs-playground.com/#ADGVAT#3

Thanks, this way really works. But the use of FacetData seems to me to be overcomplicated ... Is there really no simpler way, for example, using the initial rotation value (put it initially in the direction of the axis) . In my project, the mesh should move between different points and always look in the direction of its movement. Maybe I'm using something wrong.

Share this post


Link to post
Share on other sites

Not sure ! It won't be accurate also, 0 by default. How would you figure out the angle?

10 minutes ago, ParadoxMaster said:

for example, using the initial rotation value (put it initially in the direction of the axis)

 

Meanwhile you can try these resources :)  -
 https://www.babylonjs-playground.com/#1YTZAC#3

https://doc.babylonjs.com/how_to/pivot

https://doc.babylonjs.com/how_to/how_to_use_facetdata

Share this post


Link to post
Share on other sites

You may find this useful https://www.babylonjs-playground.com/#E0KDHN as well which rotates the mesh using lookAt

 

EDIT 21/12/2018

A bug in lookAt, to do with z -direction, was corrected in BJS 4.0 making the correct version of the above PG for version 4.0 and above https://www.babylonjs-playground.com/#E0KDHN#2

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.