Trying to rotate a mesh with dragging

Hi guys.I am trying to rotate a mesh with dragging.
Here is the PG: pointerRotateMesh | Babylon.js Playground (babylonjs.com)
You can just press your mouse on a mesh and drag it to rotate.
I have completed the part of transverse rotation and tried to do the same to longitudinal rotation.
But I have no idea how to get the axis of the view.

Hello! What do you mean by the axis of the view? The camera?
Wouldn’t just applying the mouse y delta amount in the X axis be enough for the rotation you want? pointerRotateMesh | Babylon.js Playground (babylonjs.com) Or I might have misunderstood, apologies for that :slight_smile:

Sorry I didn’t make it clear :smiling_face_with_tear:.I want the mesh to rotate vertically.

When the camera move, the axis which mesh rotating around should change.

Camera’s position Axis
(10,5,0) (0,0,1)
(10,5,10) (-1,0,1)
(0,5,-10) (1,0,0)

Here’s the PG,it’s correct if box.rotation.y< Math.PI: pointerRotateMesh2 | Babylon.js Playground (babylonjs.com)

I make it,here’s the PG: pointerRotateMesh2 | Babylon.js Playground (babylonjs.com)

1 Like

Based on your examples, it looks like you want the rotation axis to be minus the camera’s right vector then?

Yep,that’s what I want.Do you have any idea? :smiley:

You compute the camera’s right vector using the forward and up directions (you can find an explanation of this in Placing a Camera: the LookAt Function (scratchapixel.com)), then you can create the rotation using the RotationAxis method from the Quaternion class: Quaternion | Babylon.js Documentation (babylonjs.com)

2 Likes