Jump to content

Align head of arrow with body


Statics
 Share

Recommended Posts

Hey, is there any way to get the arrow heads in this demo to align with the body of the arrow?

 

I can get the rotation right for some of the sectors such as +x,+y, and +z but the other sectors don't work. I'm fairly new to babylon and I don't know if there is a function to do this.

 

I realize it might be possible to do with multiple if statements but I would prefer not to do it that way.

 

http://www.babylonjs-playground.com/#XPA7I#1

 

Please let me know if there is any way to do this,

 

Thanks

Link to comment
Share on other sites

If you know the final orientation in terms of axis (or vectors) but you don't know what rotation to apply to your cylinder to align it with one of these final vectors, you could use the static RotationFromAxis() method.

Documented here ("Generating a rotation from a target system" part ) : http://doc.babylonjs.com/page.php?p=22411

Link to comment
Share on other sites

It also seems to work with lookAt:

var vector = new BABYLON.Vector3(magx, magy, magz)var draw_vector = BABYLON.Mesh.CreateLines("lines", [new BABYLON.Vector3(0, 0, 0),vector], scene);var head1 = BABYLON.Mesh.CreateCylinder("head1", 3, 0, 2, 10, 1, scene);head1.position = vector;head1.lookAt(vector.scale(2), 0, -Math.PI/2, 0);

http://www.babylonjs-playground.com/#XPA7I#2

Link to comment
Share on other sites

yep

lookAt() rotates the mesh by aligning its local z axis (if I remember well) to the target

 

RotationFromAxis(axis1, axis2, axis3) creates a angle triplet (pitch, yaw, roll) what can be used to rotate then a mesh and to align it with axis1, axis2 and axis3 along its own local x, y and z axis 

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