1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

camera lookAt

This commit is contained in:
Kevin Levron 2021-03-05 09:10:20 +01:00
parent 9f036082e8
commit 1722a4e332

View File

@ -10,11 +10,15 @@ export default {
fov: { type: Number, default: 50 }, fov: { type: Number, default: 50 },
near: { type: Number, default: 0.1 }, near: { type: Number, default: 0.1 },
position: { type: [Object, Vector3], default: { x: 0, y: 0, z: 0 } }, position: { type: [Object, Vector3], default: { x: 0, y: 0, z: 0 } },
lookAt: { type: [Object, Vector3], default: null },
}, },
created() { created() {
this.camera = new PerspectiveCamera(this.fov, this.aspect, this.near, this.far); this.camera = new PerspectiveCamera(this.fov, this.aspect, this.near, this.far);
useBindProp(this, 'position', this.camera.position); useBindProp(this, 'position', this.camera.position);
if (this.lookAt) this.camera.lookAt(this.lookAt.x, this.lookAt.y, this.lookAt.z);
watch(() => this.lookAt, (v) => { this.camera.lookAt(v.x, v.y, v.z); }, { deep: true });
['aspect', 'far', 'fov', 'near'].forEach(p => { ['aspect', 'far', 'fov', 'near'].forEach(p => {
watch(() => this[p], () => { watch(() => this[p], () => {
this.camera[p] = this[p]; this.camera[p] = this[p];
@ -22,6 +26,7 @@ export default {
}); });
}); });
// this.camera.updateProjectionMatrix();
this.three.camera = this.camera; this.three.camera = this.camera;
}, },
render() { render() {