ThreeJS-Webpack-ES6-Boilerp.../src/js/app/camera.js

24 lines
770 B
JavaScript
Raw Normal View History

2016-09-12 19:54:07 +00:00
import THREE from 'three';
import Config from './../data/config';
export default class Camera {
constructor(renderer) {
const width = renderer.domElement.width;
const height = renderer.domElement.height;
this.threeCamera = new THREE.PerspectiveCamera(Config.camera.fov, width / height, Config.camera.near, Config.camera.far);
this.threeCamera.position.set(Config.camera.posX, Config.camera.posY, Config.camera.posZ);
this.updateSize(renderer);
// listeners
window.addEventListener('resize', () => this.updateSize(renderer), false);
}
updateSize(renderer) {
this.threeCamera.aspect = (renderer.domElement.width * Config.dpr) / (renderer.domElement.height * Config.dpr);
this.threeCamera.updateProjectionMatrix();
}
}