import { mat4 , vec2 , vec3 } from 'gl-matrix' ; import { m4 , v2 , v3 } from './gl-matrix-extensions' ; import { CameraModifier } from './cameramodifier' ; export class PanModifier extends CameraModifier { protected static readonly DEFAULT_SENSITIVITY = 0.002 ; protected _sensitivity : number = PanModifier . DEFAULT_SENSITIVITY ; protected _translation : vec3 = v3 ( ) ; param point initiate ( point ) { Object . assign ( this . _reference , this . _camera ) ; this . _initialPoint = point ; } param point process ( point ) { this . _currentPoint = point ; const magnitudes = vec2 . subtract ( v2 ( ) , this . _initialPoint , this . _currentPoint ) ; vec2 . scale ( magnitudes , magnitudes , window . devicePixelRatio * this . _sensitivity ) ; const centerToEye = vec3 . sub ( v3 ( ) , this . _reference . eye , this . _reference . center ) ; vec3 . normalize ( centerToEye , centerToEye ) ; const up = this . _reference . up ; vec3 . normalize ( up , up ) ; const right = vec3 . cross ( v3 ( ) , up , centerToEye ) ; const rightTranslation = vec3 . scale ( v3 ( ) , right , magnitudes [ 0 ] ) ; const upTranslation = vec3 . scale ( v3 ( ) , up , magnitudes [ 1 ] ) ; vec3 . negate ( upTranslation , upTranslation ) ; this . _translation = vec3 . add ( v3 ( ) , upTranslation , rightTranslation ) ; this . update ( ) ; } /**
     * Actually applies the trackball rotation to the given camera.
     */ update ( ) { if ( this . _camera === undefined ) { return ; } const T = mat4 . fromTranslation ( m4 ( ) , this . _translation ) ; const eye = vec3 . transformMat4 ( v3 ( ) , this . _reference . eye , T ) ; const center = vec3 . transformMat4 ( v3 ( ) , this . _reference . center , T ) ; this . _camera . eye = eye ; this . _camera . center = center ; } }