UNPKG

@awayjs/core

Version:
86 lines (85 loc) 3.49 kB
import { __extends } from "tslib"; import { Vector3D } from '../geom/Vector3D'; import { ProjectionBase } from './ProjectionBase'; import { CoordinateSystem } from './CoordinateSystem'; var OrthographicProjection = /** @class */ (function (_super) { __extends(OrthographicProjection, _super); function OrthographicProjection(scale, coordinateSystem) { if (scale === void 0) { scale = 1; } if (coordinateSystem === void 0) { coordinateSystem = CoordinateSystem.LEFT_HANDED; } var _this = _super.call(this, coordinateSystem) || this; _this.scale = scale; return _this; } /** * * @param position * @param target */ OrthographicProjection.prototype.project = function (position, target) { if (target === void 0) { target = null; } var v = this.viewMatrix3D.transformVector(position, target); v.y = -v.y; v.z = (v.z * (this._far - this._near) + this._far + this._near) / 2; v.w = 1; return v; }; /** * * @param nX * @param nY * @param sZ * @param target */ OrthographicProjection.prototype.unproject = function (nX, nY, sZ, target) { if (target === void 0) { target = null; } if (target == null) target = new Vector3D(); target.x = nX * sZ; target.y = -nY * sZ; target.z = (sZ * 2 - this._far - this._near) / (this._far - this._near); target.w = 1; this.inverseViewMatrix3D.transformVector(target, target); target.w = 1; return target; }; //@override OrthographicProjection.prototype.clone = function () { var clone = new OrthographicProjection(this.scale, this._coordinateSystem); clone._near = this._near; clone._far = this._far; clone._coordinateSystem = this._coordinateSystem; return clone; }; //@override OrthographicProjection.prototype._updateFrustumMatrix3D = function () { _super.prototype._updateFrustumMatrix3D.call(this); var raw = this._frustumMatrix3D._rawData; var scaleV = this._scale; var scaleH = this._scale / this._ratio; this._frustumRect.left = 0.5 * (this._originX - 1) / scaleH; this._frustumRect.top = 0.5 * (this._originY - 1) / scaleV; this._frustumRect.right = this._frustumRect.left + 1 / scaleH; this._frustumRect.bottom = this._frustumRect.top + 1 / scaleV; raw[0] = 2 * scaleH; //2/(right - left); raw[5] = 2 * scaleV; //2/(bottom - top); raw[12] = this._originX; //(right + left)/(right - left) raw[13] = this._originY; //(bottom + top)/(bottom - top); raw[10] = 2 / (this._far - this._near); raw[14] = -(this._far + this._near) / (this._far - this._near); raw[1] = raw[2] = raw[3] = raw[4] = raw[6] = raw[7] = raw[8] = raw[9] = raw[11] = 0; raw[15] = 1; }; OrthographicProjection.prototype._updateProperties = function () { _super.prototype._updateProperties.call(this); var rawData = this._frustumMatrix3D._rawData; this._near = -(rawData[14] + 1) / rawData[10]; this._far = -(rawData[14] - 1) / rawData[10]; this._originX = rawData[8]; this._originY = rawData[9]; this._scale = rawData[5] / 2; this._ratio = 0.5 * this._scale / rawData[0]; }; return OrthographicProjection; }(ProjectionBase)); export { OrthographicProjection };