首页 文章

重置相机远平面

提问于
浏览
0

我正在尝试更新使我的相机远剪裁平面坐在Vector3(0,0,0)上无论相机有多近或远,我都设法找到一种动态更新远剪裁平面的方法但我无法让这架飞机面对我的相机 .

谢谢,C

var matrix = new THREE.Matrix4();
matrix.extractRotation(camera.matrix);

var direction = new THREE.Vector3();
direction.subVectors( new THREE.Vector3(0,0,0), camera.position );
direction.normalize();

var N = new THREE.Vector3(0, 1, 0);
N.applyMatrix4(matrix);

var planePos = new THREE.Vector3(0,0,0);

var clipPlane = new THREE.Plane();
clipPlane.setFromNormalAndCoplanarPoint(N, planePos);
clipPlane.applyMatrix4(camera.matrixWorldInverse);

clipPlane = new THREE.Vector4(clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.constant);

var q = new THREE.Vector4();
var projectionMatrix = camera.projectionMatrix;

q.x = (sgn(clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
q.y = (sgn(clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
q.z = -1.0;
q.w = (1.0 + projectionMatrix.elements[10]) / camera.projectionMatrix.elements[14];

// Calculate the scaled plane vector
var c = new THREE.Vector4();
c = clipPlane.multiplyScalar(2000.0 ); //clipPlane.multiplyScalar(2.0 / clipPlane.dot(q)); /// clipPlane.dot(q)

// Replace the third row of the projection matrix
projectionMatrix.elements[2] = c.x;
projectionMatrix.elements[6] = c.y;
projectionMatrix.elements[10] = c.z + 1.0;
projectionMatrix.elements[14] = c.w;

1 回答

  • 2

    如果要重置摄像机的 far plane参数,可以使用此模式

    camera.far = new_value;
    camera.updateProjectionMatrix();
    

    在您的特定情况下,您可以这样做:

    camera.far = camera.position.length();
    camera.updateProjectionMatrix();
    

    three.js r.72

相关问题