ThreeJS DOC CN

照相机

Camera 是基础抽象类。当实例化一种相机的时候,这个类总是会被继承。

源码

// File:src/cameras/Camera.js

/**
 * @author mrdoob / http://mrdoob.com/
 * @author mikael emtinger / http://gomo.se/
 * @author WestLangley / http://github.com/WestLangley
*/

THREE.Camera = function () {

    THREE.Object3D.call( this ); // 继承

    this.type = 'Camera';

    this.matrixWorldInverse = new THREE.Matrix4();
    this.projectionMatrix = new THREE.Matrix4();

};

THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );

THREE.Camera.prototype.getWorldDirection = function () {

    var quaternion = new THREE.Quaternion();

    return function ( optionalTarget ) {

        var result = optionalTarget || new THREE.Vector3();

        this.getWorldQuaternion( quaternion );

        return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );

    }

}();

THREE.Camera.prototype.lookAt = function () {

    // This routine does not support cameras with rotated and/or translated parent(s)

    var m1 = new THREE.Matrix4();

    return function ( vector ) {

        m1.lookAt( this.position, vector, this.up );

        this.quaternion.setFromRotationMatrix( m1 );

    };

}();

THREE.Camera.prototype.clone = function ( camera ) {

    if ( camera === undefined ) camera = new THREE.Camera();

    THREE.Object3D.prototype.clone.call( this, camera );

    camera.matrixWorldInverse.copy( this.matrixWorldInverse );
    camera.projectionMatrix.copy( this.projectionMatrix );

    return camera;
};

构造器(Constructor)

Camera()

给属性 matrixWorldInverseprojectionMatrix 赋正确的类型。// 看源码继承自的 Object3D 中没有这两个属性。

属性

下面两个属性都是 Matrix4 的实例。

  • .matrixWorldInverse

    matrixWorld 的反转。matrixWorld 包含该台相机全局变换的 Matrix

  • .projectionMatrix

    投影矩阵,包含投影的相关信息

方法

.lookAt ( vector ) // 参数为 三维向量

参考