1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- ( function () {
- const _va = new THREE.Vector3(),
-
- _vb = new THREE.Vector3(),
-
- _vc = new THREE.Vector3(),
-
- _vr = new THREE.Vector3(),
-
- _vu = new THREE.Vector3(),
-
- _vn = new THREE.Vector3(),
-
- _vec = new THREE.Vector3(),
-
- _quat = new THREE.Quaternion();
-
- function frameCorners( camera, bottomLeftCorner, bottomRightCorner, topLeftCorner, estimateViewFrustum = false ) {
- const pa = bottomLeftCorner,
- pb = bottomRightCorner,
- pc = topLeftCorner;
- const pe = camera.position;
- const n = camera.near;
- const f = camera.far;
- _vr.copy( pb ).sub( pa ).normalize();
- _vu.copy( pc ).sub( pa ).normalize();
- _vn.crossVectors( _vr, _vu ).normalize();
- _va.copy( pa ).sub( pe );
- _vb.copy( pb ).sub( pe );
- _vc.copy( pc ).sub( pe );
- const d = - _va.dot( _vn );
- const l = _vr.dot( _va ) * n / d;
- const r = _vr.dot( _vb ) * n / d;
- const b = _vu.dot( _va ) * n / d;
- const t = _vu.dot( _vc ) * n / d;
-
- _quat.setFromUnitVectors( _vec.set( 0, 1, 0 ), _vu );
- camera.quaternion.setFromUnitVectors( _vec.set( 0, 0, 1 ).applyQuaternion( _quat ), _vn ).multiply( _quat );
- camera.projectionMatrix.set( 2.0 * n / ( r - l ), 0.0, ( r + l ) / ( r - l ), 0.0, 0.0, 2.0 * n / ( t - b ), ( t + b ) / ( t - b ), 0.0, 0.0, 0.0, ( f + n ) / ( n - f ), 2.0 * f * n / ( n - f ), 0.0, 0.0, - 1.0, 0.0 );
- camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();
- if ( estimateViewFrustum ) {
-
-
- camera.fov = THREE.MathUtils.RAD2DEG / Math.min( 1.0, camera.aspect ) * Math.atan( ( _vec.copy( pb ).sub( pa ).length() + _vec.copy( pc ).sub( pa ).length() ) / _va.length() );
- }
- }
- THREE.CameraUtils = {};
- THREE.CameraUtils.frameCorners = frameCorners;
- } )();
|