ホーム / モジュール / アクター運動 / AirplaneModelController

AirplaneModelController

three

飛行運動状態を飛行機のビジュアル変換(位置・ヨー・ピッチ・ロール)に適用する。

カテゴリアクター運動
依存ティアthree
内部依存WorldBasis
関連モジュールなし
デモシーンflight · フライト ↓
このモジュールだけ取得
modules/actor-motion/aircraft/AirplaneModelController.js

内部依存もまとめて、相対ディレクトリ構造を保ってコピーします。

フライト

three

自動操縦——またはクリックして矢印キーで操作、スペースでブースト。

ソース

import { Matrix4 } from 'three';
import { DEFAULT_WORLD_BASIS } from '../../math/WorldBasis.js';

export class AirplaneModelController {
  constructor(planeModel = null, jetFlames = [], basis = DEFAULT_WORLD_BASIS) {
    this.planeModel = planeModel;
    this.jetFlames = jetFlames;
    this.basis = basis;

    this.modelMatrix = new Matrix4();
  }

  reset() {
    if (!this.planeModel) return;
    this.planeModel.position.set(0, 0, 0);
    this.planeModel.quaternion.identity();
  }

  step({
    position,
    yaw,
    pitch,
    roll,
    throttle,
    isBoosting,
    elapsedTimeSeconds,
    deltaSeconds = 1 / 60
  }) {
    if (!this.planeModel) return;

    this.planeModel.position.set(position.x, position.y, position.z);

    const frame = this.basis.yawPitchRollFrame(yaw, pitch, roll);
    this.modelMatrix.makeBasis(frame.right, frame.up, frame.back ?? frame.forward.clone().negate());
    this.planeModel.quaternion.setFromRotationMatrix(this.modelMatrix);

    for (const flame of this.jetFlames) {
      flame.step({
        throttle,
        isBoosting,
        timeSeconds: elapsedTimeSeconds,
        deltaSeconds
      });
    }
  }
}