Camera.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Matrix4 } from '../math/Matrix4.js';
  2. import { Object3D } from '../core/Object3D.js';
  3. class Camera extends Object3D {
  4. constructor() {
  5. super();
  6. this.type = 'Camera';
  7. this.matrixWorldInverse = new Matrix4();
  8. this.projectionMatrix = new Matrix4();
  9. this.projectionMatrixInverse = new Matrix4();
  10. }
  11. copy( source, recursive ) {
  12. super.copy( source, recursive );
  13. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  14. this.projectionMatrix.copy( source.projectionMatrix );
  15. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  16. return this;
  17. }
  18. getWorldDirection( target ) {
  19. this.updateWorldMatrix( true, false );
  20. const e = this.matrixWorld.elements;
  21. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  22. }
  23. updateMatrixWorld( force ) {
  24. super.updateMatrixWorld( force );
  25. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  26. }
  27. updateWorldMatrix( updateParents, updateChildren ) {
  28. super.updateWorldMatrix( updateParents, updateChildren );
  29. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  30. }
  31. clone() {
  32. return new this.constructor().copy( this );
  33. }
  34. }
  35. Camera.prototype.isCamera = true;
  36. export { Camera };
粤ICP备19079148号