I’d like the model as well as the rotate arrow indicator both to rotate counter clockwise when one moves the mouse counter clockwise and opposite direction when the moves is rotated clockwise around the model’s Y axis. I’d like this regardless of the camera position.
I do want the rotation to happen only on mouse click and movement.
What I wanted to show from the jquery example was that it does a full circle rotation. And the rotation is around Y axis and the center of the arrows/model.
But I’m not able to do that. In my example it oscillates after half a rotation. I’ve tried setting setFromAxisAngle to be Y axis, and a few other settings, but it doesn’t rotate around the object’s center.
Wow, thanks. That works beautifully when the camera is positioned on top.
Is there a way though to set the rotation always to Y-Axis ? Currently if I change the camera position to view from a different angle, the rotation breaks (https://playcanvas.com/editor/scene/614499)
In my use case the rotation axis is always going to be the global Y axis.
Personally, I think that is the wrong control method to use if you have multiple camera angles and the axis of rotation is not directly towards the camera.
If you want to use the current control system, the only way I can think of is to get the mouse cursor screen position offset from the centre of the screen (assuming that the box is always centred) and then use that offset along the XZ plane of the box to calculate a point for the parent to look at.
And I want to offer users a way to rotate them on the X-Z plane, along the origin of the model and about the Y-axis.
And as you can see, there are 2 views, Top down view and Lateral view. So regardless of which camera is active I would want the rotation always along the global Y axis.
I would just have mouse move left/rotate to rotate the object. It makes more sense (want to rotate an object on the floor? Move mouse left/right) compared to rotating round a circle that is in screen space.
Another variation would be to get the screen position of the box. Then get the angle from that screen position to the mouse cursor. On mouse move, work out the out the different in angle and apply that to the box.
Also, Thanks for the revision, I think that will work perfectly for my use case.
There seems to be one small glitch though. It works well when I move the mouse under the object or over the object, but when the mouse is moved on the the box (second rotation in the video below), it rotates in the opposite direction than expected.
You have to bear in mind that you are in a 3D space and where the plane of intersection is. The mouse cursor may be ‘on’ the box, but the point of intersection may be behind it so it flips the look direction.
TBH, this version is not ‘great’ and you would need to do a variant of this: