ホーム / モジュール / カメラ / FirstPersonCameraRig

FirstPersonCameraRig

純ロジック

目標の視点位置と現在の前方向を追い、アクター固定の一人称視点運動を生成する。

カテゴリカメラ
依存ティア純ロジック
関連モジュールなし
デモシーンcamera-gallery · カメラリグ ↓
このモジュールだけ取得
modules/camera/FirstPersonCameraRig.js

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

カメラリグ

three

自動走行のショーケース——操作不要。

ソース

import { BaseCameraRig, CAMERA_HEIGHT_SOURCES, CAMERA_ROTATION_MODES } from './BaseCameraRig.js';
import { toVec3 } from '../math/Vector3Utils.js';
import { DEFAULT_WORLD_BASIS } from '../math/WorldBasis.js';

export class FirstPersonCameraRig extends BaseCameraRig {
  constructor({
    eyeHeight = 1.72,
    lookDistance = 1,
    heightVectorSource = CAMERA_HEIGHT_SOURCES.frameUp,
    basis = DEFAULT_WORLD_BASIS,
  }) {
    super({ basis, rotationMode: CAMERA_ROTATION_MODES.lookAt });
    this.eyeHeight = eyeHeight;
    this.lookDistance = lookDistance;
    this.heightVectorSource = heightVectorSource;
  }

  step({
    targetPosition,
    targetFrame,
    camera = null,
  }) {
    const frame = this.resolveTargetFrame(targetFrame);
    const heightVector = this.vectorFromSource(this.heightVectorSource, frame);
    const position = toVec3(targetPosition)
      .addScaledVector(heightVector, this.eyeHeight);

    this.setLookAtPose({
      position,
      lookAt: position.clone().addScaledVector(frame.forward, this.lookDistance),
      up: frame.up,
    });

    const pose = this.getPose();
    this.applyToCamera(camera, pose);
    return pose;
  }
}