Camera.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author mikael emtinger / http://gomo.se/
  4. * @author WestLangley / http://github.com/WestLangley
  5. */
  6. import { Matrix4 } from '../math/Matrix4.js';
  7. import { Quaternion } from '../math/Quaternion.js';
  8. import { Object3D } from '../core/Object3D.js';
  9. import { Vector3 } from '../math/Vector3.js';
  10. function Camera() {
  11. Object3D.call( this );
  12. this.type = 'Camera';
  13. this.matrixWorldInverse = new Matrix4();
  14. this.projectionMatrix = new Matrix4();
  15. }
  16. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  17. constructor: Camera,
  18. isCamera: true,
  19. copy: function ( source, recursive ) {
  20. Object3D.prototype.copy.call( this, source, recursive );
  21. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  22. this.projectionMatrix.copy( source.projectionMatrix );
  23. return this;
  24. },
  25. getWorldDirection: function () {
  26. var quaternion = new Quaternion();
  27. return function getWorldDirection( target ) {
  28. if ( target === undefined ) {
  29. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  30. target = new Vector3();
  31. }
  32. this.getWorldQuaternion( quaternion );
  33. return target.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  34. };
  35. }(),
  36. updateMatrixWorld: function ( force ) {
  37. Object3D.prototype.updateMatrixWorld.call( this, force );
  38. this.matrixWorldInverse.getInverse( this.matrixWorld );
  39. },
  40. clone: function () {
  41. return new this.constructor().copy( this );
  42. }
  43. } );
  44. export { Camera };