GetForwardVector.ts 865 B

12345678910111213141516171819202122232425262728293031323334
  1. import * as RE from 'rogue-engine'
  2. import * as THREE from 'three'
  3. export default class GetForwardVector {
  4. object3d: THREE.Object3D
  5. vector: THREE.Vector3 = new THREE.Vector3()
  6. constructor(object3d: THREE.Object3D) {
  7. this.object3d = object3d
  8. }
  9. getForward(): THREE.Vector3 {
  10. if(!this.object3d) {
  11. RE.Debug.logError("No Object3D provided to get forward vector from.")
  12. return new THREE.Vector3()
  13. }
  14. this.vector.setFromMatrixColumn( this.object3d.matrix, 0 );
  15. this.vector.crossVectors( this.object3d.up, this.vector );
  16. return this.vector.normalize()
  17. }
  18. getRight():THREE.Vector3 {
  19. if(!this.object3d) {
  20. RE.Debug.logError("No Object3D provided to get right vector from.")
  21. return new THREE.Vector3()
  22. }
  23. this.vector.setFromMatrixColumn( this.object3d.matrix, 0 );
  24. return this.vector.normalize()
  25. }
  26. }