/**
 * Copyright(c) Live2D Inc. All rights reserved.
 *
 * Use of this source code is governed by the Live2D Open Software license
 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
 */ import { CubismMatrix44 } from './cubismmatrix44' ; /**
 * カメラの位置変更に使うと便利な4x4行列
 *
 * カメラの位置変更に使うと便利な4x4行列のクラス。
 */ export class CubismViewMatrix extends CubismMatrix44 { /**
     * コンストラクタ
     */ public constructor ( ) { super ( ) ; this . _screenLeft = 0.0 ; this . _screenRight = 0.0 ; this . _screenTop = 0.0 ; this . _screenBottom = 0.0 ; this . _maxLeft = 0.0 ; this . _maxRight = 0.0 ; this . _maxTop = 0.0 ; this . _maxBottom = 0.0 ; this . _maxScale = 0.0 ; this . _minScale = 0.0 ; } param x param y public adjustTranslate ( x , y ) { if ( this . _tr [ 0 ] * this . _maxLeft + ( this . _tr [ 12 ] + x ) > this . _screenLeft ) { x = this . _screenLeft - this . _tr [ 0 ] * this . _maxLeft - this . _tr [ 12 ] ; } if ( this . _tr [ 0 ] * this . _maxRight + ( this . _tr [ 12 ] + x ) < this . _screenRight ) { x = this . _screenRight - this . _tr [ 0 ] * this . _maxRight - this . _tr [ 12 ] ; } if ( this . _tr [ 5 ] * this . _maxTop + ( this . _tr [ 13 ] + y ) < this . _screenTop ) { y = this . _screenTop - this . _tr [ 5 ] * this . _maxTop - this . _tr [ 13 ] ; } if ( this . _tr [ 5 ] * this . _maxBottom + ( this . _tr [ 13 ] + y ) > this . _screenBottom ) { y = this . _screenBottom - this . _tr [ 5 ] * this . _maxBottom - this . _tr [ 13 ] ; } const tr1 = new Float32Array ( [ 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , x , y , 0.0 , 1.0 ] ) ; CubismMatrix44 . multiply ( tr1 , this . _tr , this . _tr ) ; } param cx param cy param scale public adjustScale ( cx , cy , scale ) { const maxScale = this . getMaxScale ( ) ; const minScale = this . getMinScale ( ) ; const targetScale = scale * this . _tr [ 0 ] ; if ( targetScale < minScale ) { if ( this . _tr [ 0 ] > 0.0 ) { scale = minScale / this . _tr [ 0 ] ; } } else if ( targetScale > maxScale ) { if ( this . _tr [ 0 ] > 0.0 ) { scale = maxScale / this . _tr [ 0 ] ; } } const tr1 = new Float32Array ( [ 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , cx , cy , 0.0 , 1.0 ] ) ; const tr2 = new Float32Array ( [ scale , 0.0 , 0.0 , 0.0 , 0.0 , scale , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 ] ) ; const tr3 = new Float32Array ( [ 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , - cx , - cy , 0.0 , 1.0 ] ) ; CubismMatrix44 . multiply ( tr3 , this . _tr , this . _tr ) ; CubismMatrix44 . multiply ( tr2 , this . _tr , this . _tr ) ; CubismMatrix44 . multiply ( tr1 , this . _tr , this . _tr ) ; } param left param right param bottom param top public setScreenRect ( left , right , bottom , top ) { this . _screenLeft = left ; this . _screenRight = right ; this . _screenBottom = bottom ; this . _screenTop = top ; } param left param right param bottom param top public setMaxScreenRect ( left , right , bottom , top ) { this . _maxLeft = left ; this . _maxRight = right ; this . _maxTop = top ; this . _maxBottom = bottom ; } param maxScale public setMaxScale ( maxScale ) { this . _maxScale = maxScale ; } param minScale public setMinScale ( minScale ) { this . _minScale = minScale ; } return public getMaxScale ( ) { return this . _maxScale ; } return public getMinScale ( ) { return this . _minScale ; } return return public isMaxScale ( ) { return this . getScaleX ( ) >= this . _maxScale ; } return return public isMinScale ( ) { return this . getScaleX ( ) <= this . _minScale ; } return public getScreenLeft ( ) { return this . _screenLeft ; } return public getScreenRight ( ) { return this . _screenRight ; } return public getScreenBottom ( ) { return this . _screenBottom ; } return public getScreenTop ( ) { return this . _screenTop ; } return public getMaxLeft ( ) { return this . _maxLeft ; } return public getMaxRight ( ) { return this . _maxRight ; } return public getMaxBottom ( ) { return this . _maxBottom ; } return public getMaxTop ( ) { return this . _maxTop ; } private _screenLeft : number ; private _screenRight : number ; private _screenTop : number ; private _screenBottom : number ; private _maxLeft : number ; private _maxRight : number ; private _maxTop : number ; private _maxBottom : number ; private _maxScale : number ; private _minScale : number ; } import * as $ from './cubismviewmatrix' ; export namespace Live2DCubismFramework { export const CubismViewMatrix = $ . CubismViewMatrix ; export type CubismViewMatrix = $ . CubismViewMatrix ; }