@@ -51,6 +51,7 @@ class Ortho extends Component {
5151 this . scale = cfg . scale ;
5252 this . near = cfg . near ;
5353 this . far = cfg . far ;
54+ this . fitMode = cfg . fitMode ?? "auto" ;
5455
5556 this . _onCanvasBoundary = this . scene . canvas . on ( "boundary" , this . _needUpdate , this ) ;
5657 }
@@ -74,13 +75,13 @@ class Ortho extends Component {
7475 let top ;
7576 let bottom ;
7677
77- if ( boundaryWidth > boundaryHeight ) {
78+ if ( this . _fitMode === "horizontal" || ( ( this . _fitMode !== "vertical" ) && ( boundaryWidth > boundaryHeight ) ) ) {
7879 left = - halfSize ;
7980 right = halfSize ;
8081 top = halfSize / aspect ;
8182 bottom = - halfSize / aspect ;
82-
83- } else {
83+ }
84+ else {
8485 left = - halfSize * aspect ;
8586 right = halfSize * aspect ;
8687 top = halfSize ;
@@ -97,9 +98,45 @@ class Ortho extends Component {
9798 this . fire ( "matrix" , this . _state . matrix ) ;
9899 }
99100
101+ /**
102+ * Sets camera fit mode.
103+ *
104+ * If it's not set = automatic fit mode is enabled.
105+ *
106+ * Possible fit modes:
107+ *
108+ * \"auto\" = adjust in both dimensions, depending on the canvas width and height,
109+ *
110+ * \"vertical\" = tries to keep the vertical dimension constant, while adjusting the horizontal,
111+ *
112+ * \"horizontal\" = tries to keep the horizontal dimension constant, while adjusting the vertical.
113+ *
114+ * @param {String } value New fit mode value.
115+ */
116+ set fitMode ( value ) {
117+ if ( value === "auto" || value === "horizontal" || value === "vertical" ) {
118+ this . _fitMode = value ;
119+ }
120+ else {
121+ console . warn ( "Ortho.js Camera fitMode not recognized, setting to \"auto\"." ) ;
122+ this . _fitMode = "auto" ;
123+ }
124+
125+ this . _needUpdate ( 0 ) ;
126+ this . fire ( "fitMode" , this . _fitMode ) ;
127+ }
128+
129+ /**
130+ * Gets fit mode.
131+ *
132+ * @returns {String } Fit mode.
133+ */
134+ get fitMode ( ) {
135+ return this . _fitMode ;
136+ }
100137
101138 /**
102- * Sets scale factor for this Ortho's extents on X and Y axis.
139+ * Sets scale factor for this Ortho's extents on X and/or Y axis.
103140 *
104141 * Clamps to minimum value of ````0.01```.
105142 *
@@ -121,7 +158,7 @@ class Ortho extends Component {
121158 }
122159
123160 /**
124- * Gets scale factor for this Ortho's extents on X and Y axis.
161+ * Gets scale factor for this Ortho's extents on X and/or Y axis.
125162 *
126163 * Clamps to minimum value of ````0.01```.
127164 *
0 commit comments