33 */
44
55import { PerspectiveCamera } from './PerspectiveCamera.js' ;
6- import { Vector3 } from '../math/Vector3.js' ;
76
87function ArrayCamera ( array ) {
98
@@ -17,70 +16,7 @@ ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototyp
1716
1817 constructor : ArrayCamera ,
1918
20- isArrayCamera : true ,
21-
22- /**
23- * Assumes 2 cameras that are perpendicular and share an X-axis, and that
24- * the cameras' projection and world matrices have already been set.
25- * And that near and far planes are identical for both cameras.
26- */
27- setProjectionFromUnion : function ( ) {
28-
29- var cameraLPos = new Vector3 ( ) ;
30- var cameraRPos = new Vector3 ( ) ;
31-
32- return function ( ) {
33-
34- cameraLPos . setFromMatrixPosition ( this . cameras [ 0 ] . matrixWorld ) ;
35- cameraRPos . setFromMatrixPosition ( this . cameras [ 1 ] . matrixWorld ) ;
36-
37- var ipd = cameraLPos . distanceTo ( cameraRPos ) ;
38-
39- var projL = this . cameras [ 0 ] . projectionMatrix ;
40- var projR = this . cameras [ 1 ] . projectionMatrix ;
41-
42- // VR systems will have identical far and near planes, and
43- // most likely identical top and bottom frustum extents.
44- // via: https://computergraphics.stackexchange.com/a/4765
45- var near = projL [ 14 ] / ( projL [ 10 ] - 1 ) ;
46- var far = projL [ 14 ] / ( projL [ 10 ] + 1 ) ;
47-
48- var leftFovL = ( projL [ 8 ] - 1 ) / projL [ 0 ] ;
49- var rightFovR = ( projR [ 8 ] + 1 ) / projR [ 0 ] ;
50- var leftL = leftFovL * near ;
51- var rightR = rightFovR * near ;
52- var topL = near * ( projL [ 9 ] + 1 ) / projL [ 5 ] ;
53- var topR = near * ( projR [ 9 ] + 1 ) / projR [ 5 ] ;
54- var bottomL = near * ( projL [ 9 ] - 1 ) / projL [ 5 ] ;
55- var bottomR = near * ( projR [ 9 ] - 1 ) / projR [ 5 ] ;
56-
57- // Calculate the new camera's position offset from the
58- // left camera.
59- var zOffset = ipd / ( leftFovL + rightFovR ) ;
60- var xOffset = zOffset * leftFovL ;
61-
62- // TODO: Better way to apply this offset?
63- this . cameras [ 0 ] . matrixWorld . decompose ( this . position , this . quaternion , this . scale ) ;
64- this . translateX ( xOffset ) ;
65- this . translateZ ( - zOffset ) ;
66- this . matrixWorld . compose ( this . position , this . quaternion , this . scale ) ;
67- this . matrixWorldInverse . getInverse ( this . matrixWorld ) ;
68-
69- // Find the union of the frustum values of the cameras and scale
70- // the values so that the near plane's position does not change in world space,
71- // although must now be relative to the new union camera.
72- var near2 = near + zOffset ;
73- var far2 = far + zOffset ;
74- var left = leftL - xOffset ;
75- var right = rightR + ( ipd - xOffset ) ;
76- var top = Math . max ( topL , topR ) ;
77- var bottom = Math . min ( bottomL , bottomR ) ;
78-
79- this . projectionMatrix . makePerspective ( left , right , top , bottom , near2 , far2 ) ;
80-
81- } ;
82-
83- } ( ) ,
19+ isArrayCamera : true
8420
8521} ) ;
8622
0 commit comments