3/15

日記

2026/03/15

クラス

クラスで使う変数は全部最初に定義していたけど、ある関数でしか使わないような変数はその関数の前に定義すればよかった。

resize() {}

private readonly strength = 〇〇
private targetVector = new THREE.Vector2()

update() {}

Three.js

復習: html要素を3D上に配置

  1. 3D空間のどこに配置するか (x,y,z)を決める。
  2. update関数内でそのpositionを配置した変数に
    new THREE.Vector3(position).project(camera)
    とすると、そのpositionのNDC空間が得られる。
  3. NDC空間を正規化して画面幅でかけたりしてtranslate(x,y,z)で要素を配置
  private tmpV = new THREE.Vector3();
  private updateControlsPosition() {
    this.tmpV.copy(this.faceControls.rotateWorldPosition);
    this.tmpV.project(this.camera);
    const rx = (this.tmpV.x * 0.5 + 0.5) * this.experience.config.width;
    const ry = (this.tmpV.y * -0.5 + 0.5) * this.experience.config.height;
    this.faceControls.rotateButton.style.transform = `translate(${rx}px, ${ry}px)`;
  }

内省

眠い。モチベーションか?
朝走った日はいいが、今日のような朝ストレッチだけする日にこそコーヒーを飲むべきだったのか。