ThreeJS源码学习7Camera

本文深入探讨了 three.js 库中的 Camera 类,它是 Object3D 的子类,主要负责场景的视角和投影。Camera 类包含了关键方法如 copy、clone 和 updateMatrixWorld,用于复制、克隆相机实例以及更新矩阵世界。通过 getWorldDirection 方法可以获取相机的全局方向。这些方法对于理解和操作 three.js 中的相机视角至关重要。
摘要由CSDN通过智能技术生成

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等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值