【问题标题】:Resetting the camera far plane重置相机远平面
【发布时间】:2015-10-09 03:17:39
【问题描述】:

我正在尝试更新使我的相机远剪辑平面坐在 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;

【问题讨论】:

  • 相机是否一直在看原点?如果是这样,请尝试:camera.far = camera.position.length(); camera.updateProjectionMatrix();
  • 优雅的解决方案,完美解决我的问题。谢谢@WestLangley 真的想多了。

标签: camera three.js


【解决方案1】:

如果要重置相机的far平面参数,可以使用此模式

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

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

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

three.js r.72

【讨论】:

    猜你喜欢
    • 2015-03-23
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 2015-05-08
    • 2013-09-20
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多