Skip to content

Commit 828a56e

Browse files
authored
Expose camera component's horizontal-fov attribute (#73)
1 parent fadd06a commit 828a56e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ The `pc-camera` tag is used to define a camera component. It must be a direct ch
145145
| `flip-faces` | Boolean attribute. Controls whether the camera flips faces. If unspecified, faces are not flipped. |
146146
| `fov` | The field of view of the camera. If unspecified, `45` is used. |
147147
| `frustum-culling` | Boolean attribute. Controls whether the camera uses frustum culling. If unspecified, frustum culling is used. |
148+
| `horizontal-fov` | Valueless attribute. If present, the camera uses a horizontal field of view. If unspecified, the camera uses a vertical field of view. |
148149
| `near-clip` | The near clipping plane of the camera. If unspecified, `0.1` is used. |
149150
| `orthographic` | Valueless attribute. If present, the camera uses an orthographic projection. If unspecified, the camera uses a perspective projection. |
150151
| `ortho-height` | The height of the orthographic projection. If unspecified, `10` is used. |

src/components/camera-component.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class CameraComponentElement extends ComponentElement {
4141

4242
private _gamma: 'none' | 'srgb' = 'srgb';
4343

44+
private _horizontalFov = false;
45+
4446
private _nearClip = 0.1;
4547

4648
private _orthographic = false;
@@ -72,6 +74,7 @@ class CameraComponentElement extends ComponentElement {
7274
fov: this._fov,
7375
frustumCulling: this._frustumCulling,
7476
gammaCorrection: this._gamma === 'srgb' ? GAMMA_SRGB : GAMMA_NONE,
77+
horizontalFov: this._horizontalFov,
7578
nearClip: this._nearClip,
7679
orthographic: this._orthographic,
7780
orthoHeight: this._orthoHeight,
@@ -301,6 +304,26 @@ class CameraComponentElement extends ComponentElement {
301304
return this._gamma;
302305
}
303306

307+
/**
308+
* Sets whether the camera's field of view (fov) is horizontal or vertical. Defaults to false
309+
* (meaning it is vertical be default).
310+
* @param value - Whether the camera's field of view is horizontal.
311+
*/
312+
set horizontalFov(value: boolean) {
313+
this._horizontalFov = value;
314+
if (this.component) {
315+
this.component.horizontalFov = value;
316+
}
317+
}
318+
319+
/**
320+
* Gets whether the camera's field of view (fov) is horizontal or vertical.
321+
* @returns Whether the camera's field of view is horizontal.
322+
*/
323+
get horizontalFov(): boolean {
324+
return this._horizontalFov;
325+
}
326+
304327
/**
305328
* Sets the near clip distance of the camera.
306329
* @param value - The near clip distance.
@@ -447,6 +470,7 @@ class CameraComponentElement extends ComponentElement {
447470
'fov',
448471
'frustum-culling',
449472
'gamma',
473+
'horizontal-fov',
450474
'near-clip',
451475
'orthographic',
452476
'ortho-height',
@@ -491,6 +515,9 @@ class CameraComponentElement extends ComponentElement {
491515
case 'gamma':
492516
this.gamma = newValue as 'none' | 'srgb';
493517
break;
518+
case 'horizontal-fov':
519+
this.horizontalFov = this.hasAttribute('horizontal-fov');
520+
break;
494521
case 'near-clip':
495522
this.nearClip = parseFloat(newValue);
496523
break;

0 commit comments

Comments
 (0)