File

projects/atft/src/lib/camera/orthographic-camera.component.ts

Extends

AbstractCamera

Implements

OnChanges

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(rendererService: RendererService)
Parameters :
Name Type Optional
rendererService RendererService No

Inputs

zoom
Type : number
Default value : 4
layer
Type : number
Inherited from AbstractCamera
Defined in AbstractCamera:16
positionX
Type : number
Inherited from AbstractCamera
Defined in AbstractCamera:10
positionY
Type : number
Inherited from AbstractCamera
Defined in AbstractCamera:11
positionZ
Type : number
Inherited from AbstractCamera
Defined in AbstractCamera:12
zAxisUp
Type : boolean
Default value : false
Inherited from AbstractCamera
Defined in AbstractCamera:14

Methods

Protected createCamera
createCamera()
Inherited from AbstractCamera
Defined in AbstractCamera:22
Returns : void
ngOnChanges
ngOnChanges(changes: SimpleChanges)
Inherited from AbstractCamera
Defined in AbstractCamera:36
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
Public updateAspectRatio
updateAspectRatio(aspect: number)
Inherited from AbstractCamera
Defined in AbstractCamera:56
Parameters :
Name Type Optional
aspect number No
Returns : void
Protected updateZoom
updateZoom()
Returns : void
Protected applyPosition
applyPosition()
Inherited from AbstractCamera
Defined in AbstractCamera:59
Returns : void
Protected applyZAxisUp
applyZAxisUp()
Inherited from AbstractCamera
Defined in AbstractCamera:69
Returns : void
Public ngOnInit
ngOnInit()
Inherited from AbstractCamera
Defined in AbstractCamera:24
Returns : void

Properties

camera
Type : T
Inherited from AbstractCamera
Defined in AbstractCamera:8
import {Component, Input, OnChanges, SimpleChanges} from '@angular/core';
import * as THREE from 'three';
import {RendererService} from '../renderer/renderer.service';
import {provideParent} from '../util';
import {AbstractCamera} from './abstract-camera';

@Component({
  selector: 'atft-orthographic-camera',
  providers: [provideParent(OrthographicCameraComponent, AbstractCamera)],
  template: '<ng-content></ng-content>'
})
export class OrthographicCameraComponent extends AbstractCamera<THREE.OrthographicCamera> implements OnChanges {

  @Input() zoom = 4;

  constructor(
    protected override rendererService: RendererService
  ) {
    super(rendererService);
  }

  protected createCamera(): void {
    // console.log('OrthographicCameraComponent.createCamera');

    this.camera = new THREE.OrthographicCamera(
      window.innerWidth / -2,
      window.innerWidth / 2,
      window.innerHeight / -2,
      window.innerHeight / 2,
      0.1,
      10000
    );
    this.updateZoom();
  }

  override ngOnChanges(changes: SimpleChanges): void {
    if (!this.camera) {
      return;
    }
    let mustRerender = false;

    if (['zoom'].some(propName => propName in changes)) {
      this.updateZoom();
      mustRerender = true;
    }

    if (mustRerender) {
      this.rendererService.render();
    }
  }

  protected updateZoom() {
    this.camera.zoom = this.zoom;
  }

  public updateAspectRatio(aspect: number) {
    // console.log('OrthographicCameraComponent.updateAspectRatio: ' + aspect);
    const frustumSize = 1000;
    this.camera.left = -frustumSize * aspect / 2;
    this.camera.right = frustumSize * aspect / 2;
    this.camera.top = frustumSize / 2;
    this.camera.bottom = -frustumSize / 2;
    this.camera.updateProjectionMatrix();

    // TODO: separate component:
    this.camera.lookAt(new THREE.Vector3(0, 0, 0));
  }

}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""