Camera.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { Matrix4 } from '../math/Matrix4.js';
  2. import { Object3D } from '../core/Object3D.js';
  3. import { Vector3 } from '../math/Vector3.js';
  4. function Camera() {
  5. Object3D.call( this );
  6. this.type = 'Camera';
  7. this.matrixWorldInverse = new Matrix4();
  8. this.projectionMatrix = new Matrix4();
  9. this.projectionMatrixInverse = new Matrix4();
  10. }
  11. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12. constructor: Camera,
  13. isCamera: true,
  14. copy: function ( source, recursive ) {
  15. Object3D.prototype.copy.call( this, source, recursive );
  16. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  17. this.projectionMatrix.copy( source.projectionMatrix );
  18. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  19. return this;
  20. },
  21. getWorldDirection: function ( target ) {
  22. if ( target === undefined ) {
  23. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  24. target = new Vector3();
  25. }
  26. this.updateWorldMatrix( true, false );
  27. const e = this.matrixWorld.elements;
  28. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  29. },
  30. updateMatrixWorld: function ( force ) {
  31. Object3D.prototype.updateMatrixWorld.call( this, force );
  32. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  33. },
  34. updateWorldMatrix: function ( updateParents, updateChildren ) {
  35. Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren );
  36. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  37. },
  38. clone: function () {
  39. return new this.constructor().copy( this );
  40. }
  41. } );
  42. export { Camera };