GetForwardVector.ts 885 B

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