Camera
camera
three.js中的camera是object3D的子类。
function Camera() {
Object3D.call(this);
this.type = 'Camera';
this.matrixWorldInverse = new Matrix4();
this.projectionMatrix = new Matrix4();
this.projectionMatrixInverse = new Matrix4();
}
从代码中可以看到camera先继承了父类object3D的属性和方法。
Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
constructor: Camera,
isCamera: true,
copy: function copy(source, recursive) {
Object3D.prototype.copy.call(this, source, recursive);
this.matrixWorldInverse.copy(source.matrixWorldInverse);
this.projectionMatrix.copy(source.projectionMatrix);
this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
return this;
},
getWorldDirection: function getWorldDirection(target) {
if (target === undefined) {
console.warn('THREE.Camera: .getWorldDirection() target is now required');
target = new Vector3();
}
this.updateWorldMatrix(true, false);
var e = this.matrixWorld.elements;
return target.set(-e[8], -e[9], -e[10]).normalize();
},
updateMatrixWorld: function updateMatrixWorld(force) {
Object3D.prototype.updateMatrixWorld.call(this, force);
this.matrixWorldInverse.copy(this.matrixWorld).invert();
},
updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
this.matrixWorldInverse.copy(this.matrixWorld).invert();
},
clone: function clone() {
return new this.constructor().copy(this);
}
});
然后就是camera这个相机父类的方法定义:copy、clone和updateMatrixWorld等。