I have a group of cubes enclosed within an Object3D with the pivot point set as the origin:
https://i.sstatic.net/JLBr9.png
My objective is to rotate the cube in the opposite direction of the cursor's position. For instance, if the cursor is on the left side of the cube, the cube should spin counter-clockwise around the y-axis (green axis). If the cursor is above the cube, it should rotate counter-clockwise around the x-axis (red axis). I initially tried to achieve this by adding a "mousemove" event listener, but it only rotates when the mouse is in motion:
document.addEventListener("mousemove", onDocumentMouseMove, false);
var mouse = new THREE.Vector2();
function onDocumentMouseMove(event) {
event.preventDefault();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
{...rotations}
}
Is there a way to implement this functionality using three.js?