# Trying to rotate a mesh with dragging

**URL:** <https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219>\
**Category:** Questions\
**Created:** [January 15, 2024, 8:12am UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219 "2024-01-15T08:12:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lin\_Ardio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lin_ardio/32/35449_2.png) [@lin\_Ardio](https://forum.babylonjs.com/u/lin_Ardio)\
**Post date:** [January 15, 2024, 8:12am UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219/1 "2024-01-15T08:12:41Z")

</div>

Hi guys.I am trying to rotate a mesh with dragging.  
Here is the PG: [pointerRotateMesh | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#LX6DHU#1)  
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.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [January 15, 2024, 4:09pm UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219/2 "2024-01-15T16:09:06Z")

</div>

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)](https://playground.babylonjs.com/#LX6DHU#2) Or I might have misunderstood, apologies for that 🙂

---

<div class="post-metadata">

**Author:** ![lin\_Ardio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lin_ardio/32/35449_2.png) [@lin\_Ardio](https://forum.babylonjs.com/u/lin_Ardio)\
**Post date:** [January 16, 2024, 1:42am UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219/3 "2024-01-16T01:42:52Z")

</div>

Sorry I didn’t make it clear 🥲.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)](https://playground.babylonjs.com/#LX6DHU#8)

---

<div class="post-metadata">

**Author:** ![lin\_Ardio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lin_ardio/32/35449_2.png) [@lin\_Ardio](https://forum.babylonjs.com/u/lin_Ardio)\
**Post date:** [January 16, 2024, 3:05am UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219/4 "2024-01-16T03:05:53Z")

</div>

I make it,here’s the PG: [pointerRotateMesh2 | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#LX6DHU#9)

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [January 16, 2024, 11:55am UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219/5 "2024-01-16T11:55:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lin\_Ardio](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lin_ardio/32/35449_2.png) [@lin\_Ardio](https://forum.babylonjs.com/u/lin_Ardio)\
**Post date:** [January 17, 2024, 8:14am UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219/6 "2024-01-17T08:14:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [January 17, 2024, 11:19am UTC](https://forum.babylonjs.com/t/trying-to-rotate-a-mesh-with-dragging/47219/7 "2024-01-17T11:19:14Z")

</div>

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)](https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/lookat-function/framing-lookat-function.html)), then you can create the rotation using the `RotationAxis` method from the Quaternion class: [Quaternion | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/typedoc/classes/BABYLON.Quaternion#RotationAxis)
