three.js所:绕原点平移相机后(three.js: Rotate around origin

2019-10-18 01:46发布

我有一个平面/板,具一格,也就是大约1100 X 1100我已经平移,缩放,以及不同的是,董事会已平移后移回到屏幕中心的事实旋转工作。 所以,如果我不平移板在所有然后一切正常。 我平移板后,当我尝试将它旋转向后移动到屏幕的中央。 我无法弄清楚如何改变相机的起源,使其围绕板的中心旋转。 现在看来似乎周围的摄像头的中心旋转。

VAR半径= 1500,θ-= 45 * 0.5,onMouseDownTheta = 45 * 0.5; VAR FOV = 45; VAR mouse2D =新THREE.Vector3(0,10000,0.5);

cameraX =半径* Math.sin(THREE.Math.degToRad(THETA)); cameraY = 1000; cameraZ =半径* Math.cos(THREE.Math.degToRad(THETA));

相机=新THREE.PerspectiveCamera(FOV,window.innerWidth / window.innerHeight,1,10000); camera.position.set(cameraX,cameraY,cameraZ);

场景=新THREE.Scene(); camera.lookAt(scene.position);

渲染();

ThreeBoard.prototype.render =函数(){

mouse2D.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse2D.y = - (event.clientY / window.innerHeight) * 2 + 1;

// rotate
if (isMouseDown && isShiftPressed && !isCtrlPressed) {
    theta = ((event.pageX - mouse2D.x) * 0.5) + onMouseDownTheta;

    cameraX = radius * Math.sin(THREE.Math.degToRad(theta));
    cameraZ = radius * Math.cos(THREE.Math.degToRad(theta));

    camera.position.set(cameraX, cameraY, cameraZ);

    camera.lookAt(scene.position);
}

// pan
if (isMouseDown && isShiftPressed && isCtrlPressed) {
    theta = ((event.pageX - mouse2D.x) * 0.5) + onMouseDownTheta;

    cameraX += 10 * mouse2D.x;
    // cameraY += 10;
    cameraZ -= 10 * mouse2D.y;

    camera.position.set(cameraX, cameraY, cameraZ);

    // camera.lookAt(scene.position);
}

renderer.render(scene, camera);

};

文章来源: three.js: Rotate around origin after panning camera