UNPKG

@visactor/vrender-core

Version:
75 lines (68 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.registerOrthoCamera = exports.OrthoCamera = void 0; const matrix_allocate_1 = require("../allocator/matrix-allocate"), matrix_1 = require("../common/matrix"), factory_1 = require("../factory"), matrix_2 = require("../common/matrix"); class OrthoCamera { set params(params) { this._params = Object.assign({}, params), this._projectionMatrixCached = this.forceGetProjectionMatrix(), this._viewMatrixCached = this.forceGetViewMatrix(); } get params() { return Object.assign({}, this._params); } constructor(params) { this.params = params; } getViewMatrix() { return this._viewMatrixCached || (this._viewMatrixCached = matrix_allocate_1.mat4Allocate.allocate()), this._viewMatrixCached; } forceGetViewMatrix() { this._viewMatrixCached || (this._viewMatrixCached = matrix_allocate_1.mat4Allocate.allocate()); const {pos: pos, center: center, up: up} = this.params.viewParams; return (0, matrix_1.lookAt)(this._viewMatrixCached, pos, center, up), this._vp || (this._vp = matrix_allocate_1.mat4Allocate.allocate()), this._vp = (0, matrix_2.multiplyMat4Mat4)(this._vp, this.getProjectionMatrix(), this.getViewMatrix()), this._viewMatrixCached; } getProjectionMatrix() { return this._projectionMatrixCached || (this._projectionMatrixCached = matrix_allocate_1.mat4Allocate.allocate()), this._projectionMatrixCached; } forceGetProjectionMatrix() { this._projectionMatrixCached || (this._projectionMatrixCached = matrix_allocate_1.mat4Allocate.allocate()); const {left: left, top: top, right: right, bottom: bottom} = this._params; return (0, matrix_1.ortho)(this._projectionMatrixCached, left, right, bottom, top, 0, -2e6), this._vp || (this._vp = matrix_allocate_1.mat4Allocate.allocate()), this._vp = (0, matrix_2.multiplyMat4Mat4)(this._vp, this.getProjectionMatrix(), this.getViewMatrix()), this._projectionMatrixCached; } getField() { const {fieldRatio: fieldRatio = .8, fieldDepth: fieldDepth, left: left, right: right} = this._params; return (null != fieldDepth ? fieldDepth : right - left) * fieldRatio; } getProjectionScale(z) { const field = this.getField(); return field / (field + z); } view(x, y, z) { const outP = [ 0, 0, 0 ]; return (0, matrix_1.transformMat4)(outP, [ x, y, z ], this._viewMatrixCached), outP; } vp(x, y, z) { const outP = [ 0, 0, 0 ], {pos: pos} = this._params.viewParams; (0, matrix_1.transformMat4)(outP, [ x, y, z ], this._viewMatrixCached), x = outP[0], y = outP[1], z = outP[2]; const sizeProjection = this.getProjectionScale(z); return { x: x * sizeProjection + pos[0], y: y * sizeProjection + pos[1] }; } } exports.OrthoCamera = OrthoCamera; const registerOrthoCamera = () => { factory_1.Factory.registerPlugin("OrthoCamera", OrthoCamera); }; exports.registerOrthoCamera = registerOrthoCamera; //# sourceMappingURL=camera.js.map