/**
 * 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 { CubismMath } from './cubismmath' ; const FrameRate = 30 ; const Epsilon = 0.01 ; /**
 * 顔の向きの制御機能
 *
 * 顔の向きの制御機能を提供するクラス。
 */ export class CubismTargetPoint { /**
     * コンストラクタ
     */ public constructor ( ) { this . _faceTargetX = 0.0 ; this . _faceTargetY = 0.0 ; this . _faceX = 0.0 ; this . _faceY = 0.0 ; this . _faceVX = 0.0 ; this . _faceVY = 0.0 ; this . _lastTimeSeconds = 0.0 ; this . _userTimeSeconds = 0.0 ; } /**
     * 更新処理
     */ public update ( deltaTimeSeconds ) { this . _userTimeSeconds += deltaTimeSeconds ; const faceParamMaxV = 40.0 / 10.0 ; const maxV = ( faceParamMaxV * 1.0 ) / FrameRate ; if ( this . _lastTimeSeconds == 0.0 ) { this . _lastTimeSeconds = this . _userTimeSeconds ; return ; } const deltaTimeWeight = ( this . _userTimeSeconds - this . _lastTimeSeconds ) * FrameRate ; this . _lastTimeSeconds = this . _userTimeSeconds ; const timeToMaxSpeed = 0.15 ; const frameToMaxSpeed = timeToMaxSpeed * FrameRate ; const maxA = ( deltaTimeWeight * maxV ) / frameToMaxSpeed ; const dx = this . _faceTargetX - this . _faceX ; const dy = this . _faceTargetY - this . _faceY ; if ( CubismMath . abs ( dx ) <= Epsilon && CubismMath . abs ( dy ) <= Epsilon ) { return ; } const d = CubismMath . sqrt ( dx * dx + dy * dy ) ; const vx = ( maxV * dx ) / d ; const vy = ( maxV * dy ) / d ; let ax = vx - this . _faceVX ; let ay = vy - this . _faceVY ; const a = CubismMath . sqrt ( ax * ax + ay * ay ) ; if ( a < - maxA || a > maxA ) { ax *= maxA / a ; ay *= maxA / a ; } this . _faceVX += ax ; this . _faceVY += ay ; { const maxV = 0.5 * ( CubismMath . sqrt ( maxA * maxA + 16.0 * maxA * d - 8.0 * maxA * d ) - maxA ) ; const curV = CubismMath . sqrt ( this . _faceVX * this . _faceVX + this . _faceVY * this . _faceVY ) ; if ( curV > maxV ) { this . _faceVX *= maxV / curV ; this . _faceVY *= maxV / curV ; } } this . _faceX += this . _faceVX ; this . _faceY += this . _faceVY ; } return public getX ( ) { return this . _faceX ; } return public getY ( ) { return this . _faceY ; } param x param y public set ( x , y ) { this . _faceTargetX = x ; this . _faceTargetY = y ; } private _faceTargetX : number ; private _faceTargetY : number ; private _faceX : number ; private _faceY : number ; private _faceVX : number ; private _faceVY : number ; private _lastTimeSeconds : number ; private _userTimeSeconds : number ; } import * as $ from './cubismtargetpoint' ; export namespace Live2DCubismFramework { export const CubismTargetPoint = $ . CubismTargetPoint ; export type CubismTargetPoint = $ . CubismTargetPoint ; }