UNPKG

@enable3d/three-graphics

Version:

3D library wrapping three.js and ammo.js

33 lines 1.45 kB
/** * @author Yannick Deubel (https://github.com/yandeu) * @copyright Copyright (c) 2020 Yannick Deubel; Project Url: https://github.com/enable3d/enable3d * @license {@link https://github.com/enable3d/enable3d/blob/master/LICENSE|LGPL-3.0} */ import { OrthographicCamera, PerspectiveCamera } from 'three'; export default class Cameras { perspectiveCamera(config = {}) { return Cameras.Perspective(config); } orthographicCamera(config = {}) { return Cameras.Orthographic(config); } static Perspective(config = {}) { // for phaser // aspect = scene.scale.gameSize.aspectRatio const { fov = 50, aspect = window.innerWidth / window.innerHeight, near = 0.1, far = 2000, x = 0, y = 5, z = 25 } = config; const camera = new PerspectiveCamera(fov, aspect, near, far); camera.position.set(x, y, z); return camera; } static Orthographic(config = {}) { // for phaser // const { width, height } = scene.cameras.main const width = window.innerWidth; const height = window.innerHeight; const { left = width / -2, right = width / 2, top = height / 2, bottom = height / -2, near = 1, far = 1000, x = 0, y = 0, z = 10 } = config; const camera = new OrthographicCamera(left, right, top, bottom, near, far); camera.position.set(x, y, z); return camera; } } //# sourceMappingURL=cameras.js.map