如何使用正交投影执行缩放?

时间:2013-12-01 16:36:40

标签: javascript three.js

我只是尝试使用THREE.OrbitControls来执行缩放投影,但我没有得到我想要的行为。

我认为可以将viewSize更改为左,右,上,下以创建近似缩放的内容

任何人都有更好的主意吗?

3 个答案:

答案 0 :(得分:14)

是的,您可以使用以下模式实现OrthographicCamera的缩放效果:

camera.zoom = 1.5;
camera.updateProjectionMatrix();

这也适用于PerspectiveCamera

three.js r.70

答案 1 :(得分:3)

我有一个缩放场景的功能。请试一试。

function zoom_all(center,size) {

    // get the current lookAt vector of OrthographicCamera camera

    var vectorLookAt = new THREE.Vector3(0, 0, -1);
    vectorLookAt.applyQuaternion(camera.quaternion);
    vectorLookAt.normalize();
    // move back along lookat vector to set new position of camera
    vectorLookAt.multiplyScalar(-size);
    camera.position = new THREE.Vector3().addVectors(center, vectorLookAt);
    // get current size of camera
    var viewSize = 2 * camera.top;
    var aspectRatio = 2 * camera.right / viewSize; // get aspectRatio of camera
    // camera = new THREE.OrthographicCamera(
    //        -aspectRatio * viewSize / 2, aspectRatio * viewSize / 2,
    //        viewSize / 2, -viewSize / 2,
    //        0.1, 1000);
    // update new size for camera
    viewSize = size;
    // now update camera size
    camera.left = -aspectRatio * viewSize / 2;
    camera.right = aspectRatio * viewSize / 2;
    camera.top = viewSize / 2;
    camera.bottom = -viewSize / 2;
    camera.near = 0.1;
    camera.far = 2 * size;
    camera.updateProjectionMatrix();
    // you can set light to camera position
    spotLight.position.set(camera.position.x, camera.position.y, camera.position.z);
    // set center point for orbit control
    orbitControls.center.set(center.x, center.y, center.z);
    orbitControls.target.set(center.x, center.y, center.z);

}

答案 2 :(得分:1)

如果有人仍然感兴趣,我编辑了OrbitControls,以便根据WestLangley的答案使用正交相机:

https://github.com/traversc/OrbitControls-orthographic_camera_fix/blob/master/OrbitControls.js