/**
 * 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.
 */ /**
 * 4x4の行列
 *
 * 4x4行列の便利クラス。
 */ export class CubismMatrix44 { /**
     * コンストラクタ
     */ public constructor ( ) { this . _tr = new Float32Array ( 16 ) ; this . loadIdentity ( ) ; } param a param b return public static multiply ( a , b , dst ) { const c = new Float32Array ( [ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ] ) ; const n = 4 ; for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < n ; ++ j ) { for ( let k = 0 ; k < n ; ++ k ) { c [ j + i * 4 ] += a [ k + i * 4 ] * b [ j + k * 4 ] ; } } } for ( let i = 0 ; i < 16 ; ++ i ) { dst [ i ] = c [ i ] ; } } /**
     * 単位行列に初期化する
     */ public loadIdentity ( ) { const c = 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 , 0.0 , 0.0 , 0.0 , 1.0 ] ) ; this . setMatrix ( c ) ; } param tr public setMatrix ( tr ) { for ( let i = 0 ; i < 16 ; ++ i ) { this . _tr [ i ] = tr [ i ] ; } } return public getArray ( ) { return this . _tr ; } return public getScaleX ( ) { return this . _tr [ 0 ] ; } return public getScaleY ( ) { return this . _tr [ 5 ] ; } return public getTranslateX ( ) { return this . _tr [ 12 ] ; } return public getTranslateY ( ) { return this . _tr [ 13 ] ; } param src return public transformX ( src ) { return this . _tr [ 0 ] * src + this . _tr [ 12 ] ; } param src return public transformY ( src ) { return this . _tr [ 5 ] * src + this . _tr [ 13 ] ; } /**
     * X軸の値を現在の行列で逆計算
     */ public invertTransformX ( src ) { return ( src - this . _tr [ 12 ] ) / this . _tr [ 0 ] ; } /**
     * Y軸の値を現在の行列で逆計算
     */ public invertTransformY ( src ) { return ( src - this . _tr [ 13 ] ) / this . _tr [ 5 ] ; } param x param y public translateRelative ( x , y ) { 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 x param y public translate ( x , y ) { this . _tr [ 12 ] = x ; this . _tr [ 13 ] = y ; } param x public translateX ( x ) { this . _tr [ 12 ] = x ; } param y public translateY ( y ) { this . _tr [ 13 ] = y ; } param x param y public scaleRelative ( x , y ) { const tr1 = new Float32Array ( [ x , 0.0 , 0.0 , 0.0 , 0.0 , y , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 ] ) ; CubismMatrix44 . multiply ( tr1 , this . _tr , this . _tr ) ; } param x param y public scale ( x , y ) { this . _tr [ 0 ] = x ; this . _tr [ 5 ] = y ; } param m public multiplyByMatrix ( m ) { CubismMatrix44 . multiply ( m . getArray ( ) , this . _tr , this . _tr ) ; } /**
     * オブジェクトのコピーを生成する
     */ public clone ( ) { const cloneMatrix = new CubismMatrix44 ( ) ; for ( let i = 0 ; i < this . _tr . length ; i ++ ) { cloneMatrix . _tr [ i ] = this . _tr [ i ] ; } return cloneMatrix ; } protected _tr : Float32Array ; } import * as $ from './cubismmatrix44' ; export namespace Live2DCubismFramework { export const CubismMatrix44 = $ . CubismMatrix44 ; export type CubismMatrix44 = $ . CubismMatrix44 ; }