1

我有一个带有网格的平面/板,大约为 1100 x 1100。我有平移、缩放和旋转工作,除了板在平移后移回屏幕中心的事实。所以,如果我根本不平移电路板,那么一切正常。平移板后,当我尝试旋转板时,它会移回屏幕中心。我不知道如何更改相机的原点,使其围绕板的中心旋转。它似乎围绕着相机的中心旋转。

var 半径 = 1500, theta = 45 * 0.5, onMouseDownTheta = 45 * 0.5; 变量 fov = 45; var mouse2D = new THREE.Vector3(0, 10000, 0.5);

cameraX = 半径 * Math.sin(THREE.Math.degToRad(theta)); 相机Y = 1000;cameraZ = 半径 * Math.cos(THREE.Math.degToRad(theta));

camera = new THREE.PerspectiveCamera(fov, window.innerWidth / window.innerHeight, 1, 10000); camera.position.set(cameraX, cameraY, cameraZ);

场景 = 新的三个场景();camera.lookAt(scene.position);

使成为();

ThreeBoard.prototype.render = function() {

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);

};

4

0 回答 0