Simplest way to get nice rotation behaviour a la ArcRotateCamera on a mesh

Hi all, I have a simple scene with a few objects, lights, etc, and an ArcRotateCamera that I can drag around to look at things from different angles. But really I want to pick one of the meshes at a time and rotate that, have other controls to switch the camera between targets, and just allow the camera controls for zooming.

Now I can do the first and trickiest part of that by watching pointermove events and creating a rotation from the accumulating X and Y movements of the mouse pointer, but this presents some issues: touch events seem to have a different scaling than mouse events, the rotation is not smoothed for me, and if I re-orient the camera through some other means then the rotation is wrong and must be transformed by the camera’s rotation matrix in some way I haven’t yet worked out how to do.

Is there a simple way to get all these niceties on a mesh: smoothing, harmonious touch events, accounting for the view orientation, etc?

With that done, what is the simplest way to leave the camera able to zoom, i.e. respond to pinch and scroll events, but without its other behaviours?


Would those not do the trick : Mesh Behaviors | Babylon.js Documentation ?

They can help manipulating meshes.

Possibly, but I didn’t see a way to disable the translational behaviour of the SixDofDragBehaviour - and indeed the example only seems to have translational (I can’t work out how to rotate the mesh without the use of the gizmo, and I don’t want to force the user to click on bits of a gizmo to perform the rotation) - is this buried somewhere? Or did you mean one of the other behaviours?

Yup there are no simple ways to do it. @Cedric might have a trick.

I can think of a quick way to do rotation smoothing. instead of setting the target angle, do a slerp interpolation between the current quaternion and the targeted quaternion.
do not interpolation angles because of periodicity. I do this kind of interpolation a lot.
You can also do that on positions or any other value.

Resurrecting this topic a year later to see if there are any fresh ideas. I can certainly interpolate myself btw it’s just a pain when all of this behaviour exists already but in a restrictive way. I still don’t know how to account for the camera’s rotation when translating screen coordinates to the rotation, nor how to do cross-platform zoom.

Hi @fish-face can you just describe a bit the behavior you want?
Do you want something like: left click + drag = rotate, mouse wheel = zoom but no panning?
I’ll also add @PolygonalSun to the thread since he’s the camera/input master

Yes, that’s right. I got an OK result by hand in the end without pre-defined behaviours, but the rotation maths is (as always) tricky to get right.

If anyone is interested I will try to tidy up the code and make a snippet.

1 Like

Sharing knowledge is always appreciated here :smiley:

1 Like