import { Camera3D, float64, Vector3 } from 'godot'

export class CameraCache extends Object {
  private _camera: Camera3D
  get camera() { return this._camera }

  private _angle: float64

  get angle() {
    return this._camera.rotation.y
  }

  private _dirty: boolean = true

  constructor(initial_camera: Camera3D) {
    super()
    this._camera = initial_camera
    this._angle = this._camera.rotation.y
  }

  update_camera(camera: Camera3D) {
    this._camera = camera
    this._dirty = true
  }

  recalculate() {
    if (this._dirty) {
      this._angle = this._camera.rotation.y
      this._dirty = false
    }
  }

  transform_vec(vec: Vector3): Vector3 {
    return vec.rotated(Vector3.UP, this._angle)

  }
}


