How to move a node along its axis?

Hi! How to change the local position of the node like if it were a user dragging the node in the veiwport window using a gizmo?

In other words, how do I move it taking into account the node's rotation? If I just use DzNode.setLocalPos() to move the node along, for example, the y-axis, adding DzVec3(0,5,0), it will just move the node up without taking into account its orientation.

Comments

  • f7eerf7eer Posts: 122
    edited June 24

    Here's a snippet of code that does the trick. It uses a quaternion, which is extraordinarily useful. oNode is the node you want to move on its rotated y-axis:

     

        // get the local DAZ rotation and position
        var dzRot = oNode.getLocalRot(); // returns a DzQuat (quaternion)
        var dzPos = oNode.getLocalPos(); // returns DzVec3
        
        var translationAxis = dzRot.getYAxis(); // returns DzVec3
        translationAxis.setLength ( 5 ); // Set it up to move it 5cm
        var dzPosNew = dzPos.add(translationAxis);
        
        oNode.setLocalPos(dzPosNew);

     

     

    txt
    txt
    snippet.txt
    370B
    Post edited by f7eer on
  • f7eerf7eer Posts: 122
    edited June 24

    delete

    Post edited by f7eer on
Sign In or Register to comment.