setCamera

(別名: set_camera)

def setup
  createCanvas(100, 100, WEBGL)
  normalMaterial
  @cam1 = createCamera
  @cam2 = createCamera
  @cam2.setPosition(30, 0, 50)
  @cam2.lookAt(0, 0, 0)
  @cam2.ortho
  @currentCamera = 2
end

def draw
  background(200)

  @cam1.lookAt(0, 0, 0)
  @cam1.setPosition(sin(frameCount / 60) * 500, 0, 300)

  # 120フレームごとにカメラを切替え
  if frameCount % 120 == 0
    if @currentCamera == 2
      setCamera(@cam1)
      @currentCamera = 1
    else
      setCamera(@cam2)
      @currentCamera = 2
    end
  end
  drawBoxes
end

def drawBoxes
  rotateX(frameCount * 0.01)
  translate(-100, 0, 0)
  box(20)
  6.times do
    translate(35, 0, 0)
    box(20)
  end
end

p5.jsリファレンス(参考情報)

[p5.js] setCamera

概要

指定されたカメラをアクティブなカメラとして設定します。

書式

setCamera(cam)

引数

引数名内容備考オプションデフォルト値
camp5cameraオブジェクト

戻値

なし

備考

関連