Jump to content

move locally and compute the vertex of segment while moving


jangbi
 Share

Recommended Posts

Here's the demo.

https://www.babylonjs-playground.com/#LS4I1S

Firstly, I want to move the cylinder forward(in local axes), so i use mesh.translate(BABYLON.Vector3.Forward(), 1). The cylinder move 1 unit in the y axis instead of z axis(that's what i want), I can understand why the cylinder move in the y axis(because of the rotation), but I want to know how to move the cylinder on the x-z plane forward after rotation by using the local frame of reference.

Secondly, how to compute the segments' two end points dynamically, is my code right?

this.mesh.computeWorldMatrix();
let matrix = this.mesh.getWorldMatrix(true);
this.vertex1 = BABYLON.Vector3.TransformCoordinates(this.vertex1, matrix);
this.vertex2 = BABYLON.Vector3.TransformCoordinates(this.vertex2, matrix);

(My english is poor, please forgive me)

Link to comment
Share on other sites

@JohnK I've already read that page. Be more specifically, in this demo, i want to move the cylinder's location to (0,0,1), but not using the position.z += 1, use the local frame of reference and a local orientation vector to finish the translation.And calculate the correct segment's vertex position while need it.

Link to comment
Share on other sites

It seems to me that you want to move in world space not local space https://www.babylonjs-playground.com/#LS4I1S#1

or if you want to use local axes  then you need to move in the y direction https://www.babylonjs-playground.com/#LS4I1S#2

NOTE -  BABYLON.Vector3.Forward() = BABYLON.Axis.Z = (0, 0, 1)

This might be worth a read as well

 

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