import * as RE from 'rogue-engine'
import * as THREE from 'three'

export default class GetForwardVector {
  object3d: THREE.Object3D
  vector: THREE.Vector3 = new THREE.Vector3()

  constructor(object3d: THREE.Object3D) {
    this.object3d = object3d
  }

  getForward(): THREE.Vector3 {		
    if(!this.object3d) {
      RE.Debug.logError("No Object3D provided to get forward vector from.")
      return new THREE.Vector3()
    }
  
    this.vector.setFromMatrixColumn( this.object3d.matrix, 0 );
		this.vector.crossVectors( this.object3d.up, this.vector );

		return this.vector.normalize()

	}

	getRight():THREE.Vector3 {
    if(!this.object3d) {
      RE.Debug.logError("No Object3D provided to get right vector from.")
      return new THREE.Vector3()
    }

		this.vector.setFromMatrixColumn( this.object3d.matrix, 0 );
		return this.vector.normalize()
	}
}
