/**
 * 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 { csmMap , iterator } from '../type/csmmap' ; import { CubismMatrix44 } from './cubismmatrix44' ; /**
 * モデル座標設定用の4x4行列
 *
 * モデル座標設定用の4x4行列クラス
 */ export class CubismModelMatrix extends CubismMatrix44 { param w param h constructor ( w ? , h ? ) { super ( ) ; this . _width = w !== undefined ? w : 0.0 ; this . _height = h !== undefined ? h : 0.0 ; this . setHeight ( 2.0 ) ; } param w public setWidth ( w ) { const scaleX = w / this . _width ; const scaleY = scaleX ; this . scale ( scaleX , scaleY ) ; } param h public setHeight ( h ) { const scaleX = h / this . _height ; const scaleY = scaleX ; this . scale ( scaleX , scaleY ) ; } param x param y public setPosition ( x , y ) { this . translate ( x , y ) ; } param x param y note public setCenterPosition ( x , y ) { this . centerX ( x ) ; this . centerY ( y ) ; } param y public top ( y ) { this . setY ( y ) ; } param y public bottom ( y ) { const h = this . _height * this . getScaleY ( ) ; this . translateY ( y - h ) ; } param x public left ( x ) { this . setX ( x ) ; } param x public right ( x ) { const w = this . _width * this . getScaleX ( ) ; this . translateX ( x - w ) ; } param x public centerX ( x ) { const w = this . _width * this . getScaleX ( ) ; this . translateX ( x - w / 2.0 ) ; } param x public setX ( x ) { this . translateX ( x ) ; } param y public centerY ( y ) { const h = this . _height * this . getScaleY ( ) ; this . translateY ( y - h / 2.0 ) ; } param y public setY ( y ) { this . translateY ( y ) ; } param layout public setupFromLayout ( layout ) { const keyWidth = 'width' ; const keyHeight = 'height' ; const keyX = 'x' ; const keyY = 'y' ; const keyCenterX = 'center_x' ; const keyCenterY = 'center_y' ; const keyTop = 'top' ; const keyBottom = 'bottom' ; const keyLeft = 'left' ; const keyRight = 'right' ; for ( const ite = layout . begin ( ) ; ite . notEqual ( layout . end ( ) ) ; ite . preIncrement ( ) ) { const key = ite . ptr ( ) . first ; const value = ite . ptr ( ) . second ; if ( key == keyWidth ) { this . setWidth ( value ) ; } else if ( key == keyHeight ) { this . setHeight ( value ) ; } } for ( const ite = layout . begin ( ) ; ite . notEqual ( layout . end ( ) ) ; ite . preIncrement ( ) ) { const key = ite . ptr ( ) . first ; const value = ite . ptr ( ) . second ; if ( key == keyX ) { this . setX ( value ) ; } else if ( key == keyY ) { this . setY ( value ) ; } else if ( key == keyCenterX ) { this . centerX ( value ) ; } else if ( key == keyCenterY ) { this . centerY ( value ) ; } else if ( key == keyTop ) { this . top ( value ) ; } else if ( key == keyBottom ) { this . bottom ( value ) ; } else if ( key == keyLeft ) { this . left ( value ) ; } else if ( key == keyRight ) { this . right ( value ) ; } } } private _width : number ; private _height : number ; } import * as $ from './cubismmodelmatrix' ; export namespace Live2DCubismFramework { export const CubismModelMatrix = $ . CubismModelMatrix ; export type CubismModelMatrix = $ . CubismModelMatrix ; }