export class Camera { private camera : BABYLON . ArcRotateCamera ; private scene : BABYLON . Scene ; private followMesh : BABYLON . Mesh ; private canvas : any ; private radius : number = 55 ; constructor ( scene ) { this . scene = scene ; this . canvas = scene . getEngine ( ) . getRenderingCanvas ( ) ; } public init ( playerMesh ) { this . camera = new BABYLON . ArcRotateCamera ( "player_camera" , 1 , 1.4 , this . radius , playerMesh . position , this . scene ) ; this . camera . lowerRadiusLimit = 0.5 ; this . camera . upperRadiusLimit = 100 ; this . followMesh = playerMesh ; this . canvas . addEventListener ( "click" , ( evt ) => { if ( this . canvas . requestPointerLock ) { this . canvas . requestPointerLock ( ) ; } } , false ) ; } public getCamDirection ( ) { return this . camera . getTarget ( ) . subtract ( this . camera . position ) . normalize ( ) ; } public changeCameraRotation ( deltaAlpha = null , deltaBeta = null ) { if ( deltaAlpha !== null ) { let newAlpha = this . camera . alpha + deltaAlpha ; this . camera . alpha = newAlpha ; } } public followCamera ( ) { let newTarget = this . followMesh . position . clone ( ) ; newTarget . y += 2 ; let alpha = this . camera . alpha ; let beta = this . camera . beta ; this . camera . target = newTarget ; this . camera . radius = this . radius ; this . camera . beta = beta ; this . camera . alpha = alpha ; } }