Rotate about center of gltf model

Hello,

I am trying to rotate the element with the following transformation.

var angle = angulo;
      var trans = {
          id: "transformation",
          matrix: glMatrix.mat4.mul(
          glMatrix.mat4.create(),
          glMatrix.mat4.fromTranslation(glMatrix.mat4.create(), glMatrix.vec3.fromValues(planner.sceneTree.root.children[idMove].transformations[0].matrix[12], planner.sceneTree.root.children[idMove].transformations[0].matrix[13] , planner.sceneTree.root.children[idMove].transformations[0].matrix[14])),
          glMatrix.mat4.mul(
            glMatrix.mat4.create(),
            glMatrix.mat4.fromScaling(glMatrix.mat4.create(), glMatrix.vec3.fromValues(1,1,1)),
            glMatrix.mat4.fromRotation(glMatrix.mat4.create(), angle, glMatrix.vec3.fromValues(0,0,1)),
            )        
          ),
      };
    
    planner.sceneTree.root.children[idMove].transformations = [];
    planner.sceneTree.root.children[idMove].transformations.push(trans);
    await planner.viewer.updateNodeTransformation(planner.sceneTree.root.children[idMove]);

But it rotates around 0,0,0 and I would like it to be in the center of the model. Thank you so much

Hello @MUEBLES_TORGA_SL,

to rotate around a specific point in 3D, you need to:

  1. Translate the coordinate system so that the point around which you want to rotate becomes the origin.
  2. Perform the rotation.
  3. Translate the coordinate system back to its original position.

As this might not be straightforward, I created this small example that demonstrates this process.

Cheers, Michael

1 Like

Hello @MajorMeerkatThe3rd ,

I’m trying to make an interaction within a room.

I have used lines but apart from moving it along the wall I would also like to move it across the entire floor of the room.


I have used this code

dragManager1.addDragConstraint(
    new planeConstraint(glMatrix.vec3.fromValues(0, 0, 0), glMatrix.vec3.fromValues(0, 0, altura), {
      axis: glMatrix.vec3.fromValues(0, 0, 1),
      angle: 0
    })
  );
  
  dragManager1.addDragConstraint(
  new planeConstraint(glMatrix.vec3.fromValues(0, 0, 1), glMatrix.vec3.fromValues(0, 0, altura), {
    axis: glMatrix.vec3.fromValues(0, 0, 1),
      angle: 0
    })
  );

but I can’t limit it with the wall.

Hello @MUEBLES_TORGA_SL

while we currently do not support a restriction like that, in this example you can see how I manually restrict the dragging to a specific plane. This can be used very similarly in you use case. You can see this in the restrictPosition function of the example.

Cheers, Michael