mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
fixed eslint
This commit is contained in:
parent
b2b0d422ba
commit
bf03a4df85
20
.eslintrc.js
20
.eslintrc.js
@ -1,15 +1,17 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"jest": true,
|
||||
"es2021": true
|
||||
env: {
|
||||
browser: true,
|
||||
jest: true,
|
||||
es2021: true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 13,
|
||||
"sourceType": "module"
|
||||
extends: "eslint:recommended",
|
||||
parserOptions: {
|
||||
ecmaVersion: 13,
|
||||
sourceType: "module"
|
||||
},
|
||||
"rules": {
|
||||
rules: {
|
||||
"no-unused-vars": 0,
|
||||
"no-useless-escape": 0,
|
||||
"no-loss-of-precision": 0
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,110 +1,24 @@
|
||||
//'use strict';
|
||||
|
||||
//import { Globe } from '../../src/og/Globe.js';
|
||||
//import { GlobusTerrain } from '../../src/og/terrain/GlobusTerrain.js';
|
||||
//import { BilTerrain } from '../../src/og/terrain/BilTerrain.js';
|
||||
//import { MapboxTerrain } from '../../src/og/terrain/MapboxTerrain.js';
|
||||
//import { EmptyTerrain } from '../../src/og/terrain/EmptyTerrain.js';
|
||||
//import { XYZ } from '../../src/og/layer/XYZ.js';
|
||||
//import { WMS } from '../../src/og/layer/WMS.js';
|
||||
import { Globe } from "../../src/og/Globe.js";
|
||||
import { Entity } from "../../src/og/entity/Entity.js";
|
||||
import { XYZ } from "../../src/og/layer/XYZ.js";
|
||||
import { CanvasTiles } from "../../src/og/layer/CanvasTiles.js";
|
||||
//import { Vector } from '../../src/og/layer/Vector.js';
|
||||
//import { Entity } from '../../src/og/entity/Entity.js';
|
||||
import { DebugInfo } from "../../src/og/control/DebugInfo.js";
|
||||
//import { KeyboardNavigation } from '../../src/og/control/KeyboardNavigation.js';
|
||||
import { ToggleWireframe } from "../../src/og/control/ToggleWireframe.js";
|
||||
//import * as math from '../../src/og/math.js';
|
||||
//import { LayerSwitcher } from '../../src/og/control/LayerSwitcher.js';
|
||||
//import { Popup } from '../../src/og/Popup.js';
|
||||
import { LonLat } from "../../src/og/LonLat.js";
|
||||
//import { Vec3 } from '../../src/og/math/Vec3.js';
|
||||
//import { ScaleControl } from '../../src/og/control/ScaleControl.js';
|
||||
//import { stringTemplate } from '../../src/og/utils/shared.js';
|
||||
//import { SegmentBoundVisualization } from '../../src/og/control/SegmentBoundVisualization.js';
|
||||
|
||||
//function toQuadKey(x, y, z) {
|
||||
// var index = '';
|
||||
// for (var i = z; i > 0; i--) {
|
||||
// var b = 0;
|
||||
// var mask = 1 << (i - 1);
|
||||
// if ((x & mask) !== 0) b++;
|
||||
// if ((y & mask) !== 0) b += 2;
|
||||
// index += b.toString();
|
||||
// }
|
||||
// return index;
|
||||
//};
|
||||
|
||||
//let bing = new XYZ("sat", {
|
||||
// shininess: 20,
|
||||
// isBaseLayer: false,
|
||||
// subdomains: ['t0', 't1', 't2', 't3'],
|
||||
// url: "https://ecn.{s}.tiles.virtualearth.net/tiles/a{quad}.jpeg?n=z&g=7146",
|
||||
// visibility: true,
|
||||
// attribution: `Bing`,
|
||||
// maxNativeZoom: 19,
|
||||
// defaultTextures: [{ color: "#001522" }, { color: "#E4E6F3" }],
|
||||
// urlRewrite: function (s, u) {
|
||||
// return stringTemplate(u, {
|
||||
// 's': this._getSubdomain(),
|
||||
// 'quad': toQuadKey(s.tileX, s.tileY, s.tileZoom)
|
||||
// });
|
||||
// }
|
||||
//});
|
||||
|
||||
//// document.getElementById("ambient-r").addEventListener("input", function (e) {
|
||||
//// osm.ambient.x = this.value;
|
||||
//// document.querySelector(".value.ambient-r").innerHTML = this.value;
|
||||
//// });
|
||||
//// document.getElementById("ambient-g").addEventListener("input", function (e) {
|
||||
//// osm.ambient.y = this.value;
|
||||
//// document.querySelector(".value.ambient-g").innerHTML = this.value;
|
||||
//// });
|
||||
//// document.getElementById("ambient-b").addEventListener("input", function (e) {
|
||||
//// osm.ambient.z = this.value;
|
||||
//// document.querySelector(".value.ambient-b").innerHTML = this.value;
|
||||
//// });
|
||||
|
||||
//// document.getElementById("diffuse-r").addEventListener("input", function (e) {
|
||||
//// osm.diffuse.x = this.value;
|
||||
//// document.querySelector(".value.diffuse-r").innerHTML = this.value;
|
||||
//// });
|
||||
//// document.getElementById("diffuse-g").addEventListener("input", function (e) {
|
||||
//// osm.diffuse.y = this.value;
|
||||
//// document.querySelector(".value.diffuse-g").innerHTML = this.value;
|
||||
//// });
|
||||
//// document.getElementById("diffuse-b").addEventListener("input", function (e) {
|
||||
//// osm.diffuse.z = this.value;
|
||||
//// document.querySelector(".value.diffuse-b").innerHTML = this.value;
|
||||
//// });
|
||||
|
||||
//// document.getElementById("specular-r").addEventListener("input", function (e) {
|
||||
//// osm.specular.x = this.value;
|
||||
//// document.querySelector(".value.specular-r").innerHTML = this.value;
|
||||
//// });
|
||||
//// document.getElementById("specular-g").addEventListener("input", function (e) {
|
||||
//// osm.specular.y = this.value;
|
||||
//// document.querySelector(".value.specular-g").innerHTML = this.value;
|
||||
//// });
|
||||
//// document.getElementById("specular-b").addEventListener("input", function (e) {
|
||||
//// osm.specular.z = this.value;
|
||||
//// document.querySelector(".value.specular-b").innerHTML = this.value;
|
||||
//// });
|
||||
|
||||
//// document.getElementById("shininess").addEventListener("input", function (e) {
|
||||
//// osm.shininess = this.value;
|
||||
//// document.querySelector(".value.shininess").innerHTML = this.value;
|
||||
//// });
|
||||
|
||||
let cnv = document.createElement("canvas");
|
||||
let ctx = cnv.getContext("2d");
|
||||
cnv.width = 256;
|
||||
cnv.height = 256;
|
||||
import { Vector } from "../../src/og/layer/Vector.js";
|
||||
import { GlobusTerrain } from "../../src/og/terrain/GlobusTerrain.js";
|
||||
import { EmptyTerrain } from "../../src/og/terrain/EmptyTerrain.js";
|
||||
import { labelXYZ } from "./labelXYZ.js";
|
||||
|
||||
const tg = new CanvasTiles("Tile grid", {
|
||||
visibility: true,
|
||||
isBaseLayer: false,
|
||||
zIndex: 100,
|
||||
drawTile: function (material, applyCanvas) {
|
||||
//
|
||||
// This is important create canvas here!
|
||||
//
|
||||
let cnv = document.createElement("canvas");
|
||||
let ctx = cnv.getContext("2d");
|
||||
cnv.width = 256;
|
||||
cnv.height = 256;
|
||||
|
||||
//Clear canvas
|
||||
ctx.clearRect(0, 0, cnv.width, cnv.height);
|
||||
|
||||
@ -117,276 +31,44 @@ const tg = new CanvasTiles("Tile grid", {
|
||||
|
||||
let size;
|
||||
|
||||
//Draw text
|
||||
if (material.segment.tileZoom > 17) {
|
||||
size = "18";
|
||||
} else if (material.segment.tileZoom > 14) {
|
||||
size = "26";
|
||||
if (material.segment.isPole) {
|
||||
let ext = material.segment.getExtentLonLat();
|
||||
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillRect(0, 0, 256, 256);
|
||||
//ctx.font = 'normal ' + 29 + 'px Verdana';
|
||||
//ctx.textAlign = 'center';
|
||||
//ctx.fillText(`${ext.northEast.lon.toFixed(3)} ${ext.northEast.lat.toFixed(3)}`, cnv.width / 2, cnv.height / 2 + 20);
|
||||
//ctx.fillText(`${ext.southWest.lon.toFixed(3)} ${ext.southWest.lat.toFixed(3)}`, cnv.width / 2, cnv.height / 2 - 20);
|
||||
} else {
|
||||
size = "32";
|
||||
ctx.fillRect(0, 0, 256, 256);
|
||||
//Draw text
|
||||
// if (material.segment.tileZoom > 14) {
|
||||
// size = "26";
|
||||
// } else {
|
||||
// size = "32";
|
||||
// }
|
||||
// ctx.fillStyle = 'black';
|
||||
// ctx.font = 'normal ' + size + 'px Verdana';
|
||||
// ctx.textAlign = 'center';
|
||||
// ctx.fillText(material.segment.tileX + "," + material.segment.tileY + "," + material.segment.tileZoom, cnv.width / 2, cnv.height / 2);
|
||||
}
|
||||
ctx.fillStyle = "black";
|
||||
ctx.font = "normal " + size + "px Verdana";
|
||||
ctx.textAlign = "center";
|
||||
ctx.fillText(
|
||||
material.segment.tileX + "," + material.segment.tileY + "," + material.segment.tileZoom,
|
||||
cnv.width / 2,
|
||||
cnv.height / 2
|
||||
);
|
||||
|
||||
//Draw canvas tile
|
||||
applyCanvas(cnv);
|
||||
}
|
||||
});
|
||||
|
||||
//let osm = new XYZ("OSM", {
|
||||
// 'isBaseLayer': true,
|
||||
// 'url': "//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
// 'visibility': true,
|
||||
// 'attribution': 'Data @ OpenStreetMap contributors, ODbL'
|
||||
//});
|
||||
|
||||
////let wien = new XYZ("512", {
|
||||
//// 'isBaseLayer': true,
|
||||
//// 'url': "//maps.wien.gv.at/basemap/bmaphidpi/normal/google3857/{z}/{y}/{x}.jpeg",
|
||||
//// 'visibility': false
|
||||
////});
|
||||
|
||||
////let sat = new XYZ("MapQuest Satellite", {
|
||||
//// shininess: 20,
|
||||
//// specular: [0.00048, 0.00037, 0.00035],
|
||||
//// diffuse: [0.88, 0.85, 0.8],
|
||||
//// ambient: [0.15, 0.1, 0.23],
|
||||
//// isBaseLayer: true,
|
||||
//// url: "//api.mapbox.com/styles/v1/mapbox/satellite-v9/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoibWdldmxpY2hzY2FuZXgiLCJhIjoiY2pwcGdsaXlnMDQzdDQybXhsOWZlbXBvdSJ9.fR2YE-ehJA4iajaJBAPKvw",
|
||||
//// visibility: false,
|
||||
//// attribution: `@2014 MapQuest - Portions @2014 "Map data @
|
||||
//// <a target="_blank" href="//www.openstreetmap.org/">OpenStreetMap</a> and contributors,
|
||||
//// <a target="_blank" href="//opendatacommons.org/licenses/odbl/"> CC-BY-SA</a>"`
|
||||
////});
|
||||
|
||||
//let sat = new XYZ("Google Satellite", {
|
||||
// shininess: 20,
|
||||
// specular: [0.00048, 0.00037, 0.00035],
|
||||
// diffuse: [0.88, 0.85, 0.8],
|
||||
// ambient: [0.15, 0.1, 0.23],
|
||||
// isBaseLayer: true,
|
||||
// url: "https://khms1.googleapis.com/kh?v=894&hl=en-GB&x={x}&y={y}&z={z}",
|
||||
// visibility: false,
|
||||
// attribution: ``
|
||||
//});
|
||||
|
||||
//let thames = new XYZ("Reconstructed Lakebed", {
|
||||
// fading: true,
|
||||
// isBaseLayer: false,
|
||||
// visibility: true,
|
||||
// url: "http://alacst.ddns.net:8181/Tiles/1xoverlay/{z}/{x}/{y}.png",
|
||||
// // extent: [[-1.1210868226, 51.5993282113], [-1.11506810397, 51.6072360341]]
|
||||
// extent: [[-1.12047, 51.60076], [-1.11807, 51.60285]]
|
||||
//});
|
||||
|
||||
//let emptyTerrain = new EmptyTerrain(),
|
||||
// globusTerrain = new GlobusTerrain(),
|
||||
// mapboxTerrain = new MapboxTerrain(),
|
||||
// bilTerrain = new BilTerrain({
|
||||
// maxZoom: 19,
|
||||
// url: "//127.0.0.1:8080/geoserver/",
|
||||
// //url: "//95.211.82.211:8080/geoserver/og/",
|
||||
// //layers: "og:n44_e009_1arc_v3",
|
||||
// layers: "test:geotiff_coverage_2",
|
||||
// //layers: "arizona:3",
|
||||
// //imageSize: 129,
|
||||
// gridSizeByZoom: [64, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 16, 32, 16, 32, 16, 32, 16, 32, 16, 8, 4],
|
||||
// //extent: [[8.9, 44.0], [10.0, 45]]
|
||||
// });
|
||||
|
||||
//window.globe = new Globe({
|
||||
// 'name': "Earth",
|
||||
// 'target': "earth",
|
||||
// 'terrain': /*bilTerrain/*/globusTerrain/*new MapboxTerrain(null, {
|
||||
// url: "//alacst.ddns.net:8181/Tiles/testtile129/{z}/{x}/{y}.png",
|
||||
// //url: "//alacst.ddns.net:8181/Tiles/129terrain/{z}/{x}/{y}.png",
|
||||
// minZoom: 9,
|
||||
// maxZoom: 23,
|
||||
// gridSizeByZoom: [64, 32, 32, 16, 16, 16, 16, 32, 64, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 64, 32, 16],
|
||||
// sourceImageSize: 129,
|
||||
// equalizeVertices: false
|
||||
// })*/,
|
||||
// 'layers': [osm, tg, sat],
|
||||
// 'viewExtent': [89.83484, 25.69255, 90.34796, 26.44652]
|
||||
//});
|
||||
|
||||
//window.setEmptyTerrain = function () {
|
||||
// window.globe.planet.setTerrain(emptyTerrain);
|
||||
//};
|
||||
|
||||
//window.setOpenglobusTerrain = function () {
|
||||
// window.globe.planet.setTerrain(globusTerrain);
|
||||
//};
|
||||
|
||||
//window.setBilTerrain = function () {
|
||||
// window.globe.planet.setTerrain(bilTerrain);
|
||||
//};
|
||||
|
||||
//window.setMapboxTerrain = function () {
|
||||
// window.globe.planet.setTerrain(mapboxTerrain);
|
||||
//};
|
||||
|
||||
////window.globe = new Globe({
|
||||
//// 'name': "Earth",
|
||||
//// 'target': "earth",
|
||||
//// 'terrain': new GlobusTerrain(),
|
||||
//// 'layers': [osm, sat, tg, states, modis],
|
||||
//// 'viewExtent': [7.86, 44.24, 11.29, 45.0]
|
||||
////});
|
||||
|
||||
////window.globe = new Globe({
|
||||
//// target: "earth",
|
||||
//// name: "Bil Terrain Source",
|
||||
//// terrain: new BilTerrain({
|
||||
//// url: "//95.211.82.211:8080/geoserver/og/",
|
||||
//// layers: "og:n44_e009_1arc_v3",
|
||||
//// imageSize: 128,
|
||||
//// gridSizeByZoom: [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 64, 64, 32, 32, 32, 16, 8],
|
||||
//// extent: [[8.9, 44.0], [10.0, 45]]
|
||||
//// }),
|
||||
//// viewExtent: [7.86, 44.24, 11.29, 45.0],
|
||||
//// layers: [osm, sat, tg, states, modis]
|
||||
////});
|
||||
|
||||
////globe.planet.addControl(new SegmentBoundVisualization());
|
||||
//globe.planet.addControl(new KeyboardNavigation());
|
||||
//globe.planet.addControl(new LayerSwitcher());
|
||||
////globe.planet.addControl(new ScaleControl());
|
||||
|
||||
//let e1 = new Entity({
|
||||
// 'name': 'strip1',
|
||||
// 'strip': {
|
||||
// 'color': [0 / 255, 38 / 255, 255 / 255],
|
||||
// 'opacity': 0.27,
|
||||
// 'path': [
|
||||
// [[586523.0151173624, 4392830.957760274, 4570544.574074627], [587043.0890180465, 4396726.110503412, 4574597.306676116]],
|
||||
// [[693687.4135420445, 4446600.854589337, 4502800.243641092], [694306.9328021071, 4450572.030680254, 4506821.6103556845]],
|
||||
// [[695057.6327224943, 4446368.161289945, 4502875.06522507], [695283.9105581088, 4447815.688108607, 4504340.988014539]],
|
||||
// [[695379.6262299116, 4446451.841945512, 4502776.850023308], [695603.3364033864, 4447882.307370998, 4504225.435734251]]
|
||||
// ],
|
||||
// }
|
||||
//});
|
||||
|
||||
//let e2 = new Entity({
|
||||
// 'name': 'strip2',
|
||||
// 'strip': {
|
||||
// 'color': [0 / 255, 38 / 255, 255 / 255],
|
||||
// 'opacity': 0.27,
|
||||
// 'path': [
|
||||
// [[661936.3048841777, 4745603.382222995, 4189411.525681237], [1339051.734436527, 9600030.082993329, 8474892.113242555]],
|
||||
// [[1126928.1072783293, 4760811.647727539, 4071007.90108061], [2277324.752646721, 9620768.297494425, 8226795.481871399]]
|
||||
// ],
|
||||
// }
|
||||
//});
|
||||
|
||||
//let stripLayer = new Vector("test layer", {
|
||||
// 'entities': [e1, e2],
|
||||
// 'pickingEnabled': true,
|
||||
// 'visibility': true
|
||||
//});
|
||||
|
||||
//globe.planet.addLayer(stripLayer);
|
||||
|
||||
////new Vector("Markers", {
|
||||
//// clampToGround: false,
|
||||
//// polygonOffsetUnits: 0
|
||||
////})
|
||||
//// .addTo(globe.planet)
|
||||
//// .add(new Entity({
|
||||
//// lonlat: [5.73, 45.183, 273.5],
|
||||
//// label: {
|
||||
//// text: "Hi, Globus!",
|
||||
//// outline: 0.77,
|
||||
//// outlineColor: "rgba(255,255,255,.4)",
|
||||
//// size: 27,
|
||||
//// color: "black",
|
||||
//// face: "Lucida Console",
|
||||
//// offset: [10, -2]
|
||||
//// },
|
||||
//// billboard: {
|
||||
//// src: "./marker.png",
|
||||
//// width: 64,
|
||||
//// height: 64,
|
||||
//// offset: [0, 32]
|
||||
//// }
|
||||
//// }));
|
||||
|
||||
////globe.planet.viewExtentArr([-1.13284, 51.59951, -1.10951, 51.60386]);
|
||||
|
||||
////let myPopup = new Popup({
|
||||
//// planet: globe.planet,
|
||||
//// content: `Simple HTML popup<br>See <a href="//openglobus.org/examples/billboardsOnTHeGround/billboardsOnTHeGround.html">popup example</a>`,
|
||||
//// offset: [0, 0],
|
||||
//// lonLat: [5.73, 45.183, 273.5],
|
||||
//// visibility: true
|
||||
////});
|
||||
|
||||
////window.myPopup = myPopup;
|
||||
|
||||
////globe.planet.viewLonLat(new LonLat(-112.99778159686288, 37.23755430287543, 8952.673764926381));
|
||||
|
||||
////import { Globe } from '../../src/og/Globe.js';
|
||||
////import { XYZ } from '../../src/og/layer/XYZ.js';
|
||||
////import { GlobusTerrain } from '../../src/og/terrain/GlobusTerrain.js';
|
||||
////import { Vec3 } from '../../src/og/math/Vec3.js';
|
||||
////import { LonLat } from '../../src/og/LonLat.js';
|
||||
////import { Vector } from '../../src/og/layer/Vector.js';
|
||||
////import { Entity } from '../../src/og/entity/Entity.js';
|
||||
////import { wgs84 } from '../../src/og/ellipsoid/wgs84.js';
|
||||
|
||||
////var osm = new XYZ("OpenStreetMap", {
|
||||
//// isBaseLayer: true,
|
||||
//// url: "//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
//// visibility: true,
|
||||
//// attribution: 'Data @ OpenStreetMap contributors, ODbL'
|
||||
////});
|
||||
|
||||
////let size = 1000000;
|
||||
////let ellipsoid = wgs84;
|
||||
////let startlonlat = new LonLat(51.5, 7, 0);
|
||||
////let endlonlat = new LonLat(51.5, 7, 1000);
|
||||
////let startPos = ellipsoid.lonLatToCartesian(startlonlat);
|
||||
////let endPos = ellipsoid.lonLatToCartesian(endlonlat);
|
||||
|
||||
////let e = new Entity({
|
||||
//// 'ray': {
|
||||
//// 'startPosition': startPos,
|
||||
//// 'endPosition': endPos,
|
||||
//// 'length': size,
|
||||
//// 'startColor': "red",
|
||||
//// 'endColor': "green",
|
||||
//// 'thickness': 10
|
||||
//// }
|
||||
////});
|
||||
|
||||
////let rayLayer = new Vector("rays", {
|
||||
//// 'polygonOffsetUnits': 0
|
||||
////});
|
||||
|
||||
////rayLayer.add(e);
|
||||
|
||||
////var globus = new Globe({
|
||||
//// "target": "earth",
|
||||
//// "name": "Earth",
|
||||
//// "terrain": new GlobusTerrain(),
|
||||
//// "layers": [osm, rayLayer],
|
||||
//// "sun": {
|
||||
//// "active": true
|
||||
//// }
|
||||
////});
|
||||
|
||||
import { Globe } from "../../src/og/Globe.js";
|
||||
import { Entity } from "../../src/og/entity/Entity.js";
|
||||
import { XYZ } from "../../src/og/layer/XYZ.js";
|
||||
import { Vector } from "../../src/og/layer/Vector.js";
|
||||
import { GlobusTerrain } from "../../src/og/terrain/GlobusTerrain.js";
|
||||
import { EmptyTerrain } from "../../src/og/terrain/EmptyTerrain.js";
|
||||
const labelLayer = new labelXYZ("labelLayer", {
|
||||
isBaseLayer: false,
|
||||
visibility: true,
|
||||
// zIndex: GlobeConst.labelZIndex,
|
||||
url: "//t.ssl.ak.dynamic.tiles.virtualearth.net/comp/ch/{key}?mkt=en-us&it=Z%2CGF%2CL&shading=hill&og=1471&n=z&ur=JP&js=1&cstl=in&st=me|lv:0_pp|lv:1_cr|lv:1_ad|lv:1&nvlos=1&vpt=e,p&pll=1&ell=1",
|
||||
countryLayerData: "//assets.msn.com/weathermapdata/1/static/3d/label.0.1/country-{}.json",
|
||||
height: 16,
|
||||
size: 11.5,
|
||||
color: "white"
|
||||
});
|
||||
|
||||
var osm = new XYZ("OpenStreetMap", {
|
||||
isBaseLayer: true,
|
||||
@ -398,87 +80,14 @@ var osm = new XYZ("OpenStreetMap", {
|
||||
var globus = new Globe({
|
||||
target: "earth",
|
||||
name: "Earth",
|
||||
terrain: /*new EmptyTerrain({
|
||||
gridSizeByZoom: [32, 16, 16, 8, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
|
||||
}),/*/ new GlobusTerrain(),
|
||||
useEarthNavigation: true,
|
||||
layers: [osm /*, tg*/]
|
||||
//'viewExtent': [-1.12135, 51.60133, -1.11704, 51.60224]
|
||||
maxAltitude: 15000000,
|
||||
minAltitude: 4200000,
|
||||
terrain: new EmptyTerrain({
|
||||
gridSizeByZoom: [32, 32, 32, 32, 16, 8, 8]
|
||||
}),
|
||||
layers: [labelLayer, tg],
|
||||
useNightTexture: false,
|
||||
useSpecularTexture: false
|
||||
});
|
||||
|
||||
fetch("./szint.json")
|
||||
.then((r) => {
|
||||
return r.json();
|
||||
})
|
||||
.then((data) => {
|
||||
var countries = new Vector("Countries", {
|
||||
visibility: true,
|
||||
isBaseLayer: false,
|
||||
diffuse: [0, 0, 0],
|
||||
ambient: [1, 1, 1]
|
||||
});
|
||||
|
||||
countries.addTo(globus.planet);
|
||||
|
||||
var f = data.features;
|
||||
for (var i = 0; i < f.length; i++) {
|
||||
var fi = f[i];
|
||||
countries.add(
|
||||
new Entity({
|
||||
geometry: {
|
||||
type: fi.geometry.type,
|
||||
coordinates: fi.geometry.coordinates,
|
||||
style: {
|
||||
fillColor: "rgba(255,255,0,1.0)",
|
||||
lineColor: "rgba(255,255,0,1.0)"
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
//countries.events.on("mouseleave", function (e) {
|
||||
// e.pickingObject.geometry.setFillColor(1, 1, 1, 0.6);
|
||||
// e.pickingObject.geometry.setLineColor(0.2, 0.6, 0.8, 1.0);
|
||||
//});
|
||||
//countries.events.on("mouseenter", function (e) {
|
||||
// e.pickingObject.geometry.bringToFront();
|
||||
// e.pickingObject.geometry.setFillColor(1, 0, 0, 0.4);
|
||||
// e.pickingObject.geometry.setLineColor(1, 0, 0, 1.0);
|
||||
//});
|
||||
//countries.events.on("lclick", function (e) {
|
||||
// globus.planet.flyExtent(e.pickingObject.geometry.getExtent());
|
||||
//});
|
||||
//countries.events.on("touchstart", function (e) {
|
||||
// globus.planet.flyExtent(e.pickingObject.geometry.getExtent());
|
||||
//});
|
||||
});
|
||||
|
||||
globus.planet.addControl(
|
||||
new DebugInfo({
|
||||
watch: [
|
||||
{
|
||||
label: "metersInMinSize",
|
||||
frame: () => globus.planet.renderer.controls.scaleControl._metersInMinSize
|
||||
},
|
||||
{
|
||||
label: "meters in pixel",
|
||||
frame: () => globus.planet.renderer.controls.scaleControl._mPx
|
||||
}
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
//setTimeout(() => {
|
||||
//globus.planet.camera.setLonLat(new LonLat(10, 10, 4500000));
|
||||
//}, 1000);
|
||||
|
||||
//globus.planet.camera.update()
|
||||
|
||||
globus.planet.addControl(
|
||||
new ToggleWireframe({
|
||||
isActive: false
|
||||
})
|
||||
);
|
||||
|
||||
window.globus = globus;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import * as jd from './jd.js';
|
||||
import * as jd from "./jd.js";
|
||||
|
||||
/**
|
||||
* Angle between J2000 mean equator and the ecliptic plane.
|
||||
@ -16,7 +16,7 @@ export const J2000_OBLIQUITY = 23.4392911;
|
||||
* @const
|
||||
* @type{Number}
|
||||
*/
|
||||
export const AU_TO_METERS = 1.49597870e+11;
|
||||
export const AU_TO_METERS = 1.4959787e11;
|
||||
|
||||
/**
|
||||
* Terestrial and atomic time difference.
|
||||
@ -45,7 +45,7 @@ export const SUN_GRAVITATIONAL_PARAMETER = 1.32712440018e20;
|
||||
* @returns {Number} - returns barycentric dynamical time.
|
||||
*/
|
||||
export function TAItoTDB(tai) {
|
||||
tai += og.astro.TDT_TAI * jd.ONE_BY_SECONDS_PER_DAY;
|
||||
tai += TDT_TAI * jd.ONE_BY_SECONDS_PER_DAY;
|
||||
var g = 6.239996 + 0.0172019696544 * (tai - jd.J2000);
|
||||
return tai + 0.001658 * Math.sin(g + 1.671e-2 * Math.sin(g)) * jd.ONE_BY_SECONDS_PER_DAY;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
* @module og/astro/jd
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import { binarySearch } from '../utils/shared.js';
|
||||
import { binarySearch } from "../utils/shared.js";
|
||||
|
||||
/**
|
||||
* Seconds in millisecond.
|
||||
@ -172,8 +172,13 @@ export function T(jd) {
|
||||
export function getDayNumber(year, month, day) {
|
||||
var a = ((month - 14) / 12) | 0;
|
||||
var b = year + 4800 + a;
|
||||
return (((1461 * b) / 4) | 0) + (((367 * (month - 2 - 12 * a)) / 12) | 0) -
|
||||
(((3 * (((b + 100) / 100) | 0)) / 4) | 0) + day - 32075;
|
||||
return (
|
||||
(((1461 * b) / 4) | 0) +
|
||||
(((367 * (month - 2 - 12 * a)) / 12) | 0) -
|
||||
(((3 * (((b + 100) / 100) | 0)) / 4) | 0) +
|
||||
day -
|
||||
32075
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +195,8 @@ export function DateToUTC(date) {
|
||||
}
|
||||
|
||||
var secondsOfDay =
|
||||
date.getUTCSeconds() + hour * SECONDS_PER_HOUR +
|
||||
date.getUTCSeconds() +
|
||||
hour * SECONDS_PER_HOUR +
|
||||
date.getUTCMinutes() * SECONDS_PER_MINUTE +
|
||||
date.getUTCMilliseconds() * SECONDS_PER_MILLISECOND;
|
||||
|
||||
@ -198,7 +204,7 @@ export function DateToUTC(date) {
|
||||
dayNumber--;
|
||||
}
|
||||
|
||||
var extraDays = secondsOfDay * ONE_BY_SECONDS_PER_DAY | 0;
|
||||
var extraDays = (secondsOfDay * ONE_BY_SECONDS_PER_DAY) | 0;
|
||||
dayNumber += extraDays;
|
||||
secondsOfDay -= SECONDS_PER_DAY * extraDays;
|
||||
|
||||
@ -300,7 +306,7 @@ export function UTCtoDate(utc) {
|
||||
}
|
||||
|
||||
var L = (julianDayNumber + 68569) | 0;
|
||||
var N = (4 * L / 146097) | 0;
|
||||
var N = ((4 * L) / 146097) | 0;
|
||||
L = (L - (((146097 * N + 3) / 4) | 0)) | 0;
|
||||
var I = ((4000 * (L + 1)) / 1461001) | 0;
|
||||
L = (L - (((1461 * I) / 4) | 0) + 31) | 0;
|
||||
@ -310,12 +316,12 @@ export function UTCtoDate(utc) {
|
||||
var month = (J + 2 - 12 * L) | 0;
|
||||
var year = (100 * (N - 49) + I + L) | 0;
|
||||
|
||||
var hour = secondsOfDay * ONE_BY_SECONDS_PER_HOUR | 0;
|
||||
var hour = (secondsOfDay * ONE_BY_SECONDS_PER_HOUR) | 0;
|
||||
var remainingSeconds = secondsOfDay - hour * SECONDS_PER_HOUR;
|
||||
var minute = remainingSeconds * ONE_BY_SECONDS_PER_MINUTE | 0;
|
||||
var minute = (remainingSeconds * ONE_BY_SECONDS_PER_MINUTE) | 0;
|
||||
remainingSeconds = remainingSeconds - minute * SECONDS_PER_MINUTE;
|
||||
var second = remainingSeconds | 0;
|
||||
var millisecond = (remainingSeconds - second) * MILLISECONDS_PER_SECOND | 0;
|
||||
var millisecond = ((remainingSeconds - second) * MILLISECONDS_PER_SECOND) | 0;
|
||||
|
||||
hour += 12;
|
||||
if (hour > 23) {
|
||||
@ -331,11 +337,10 @@ export function UTCtoDate(utc) {
|
||||
* @returns {Date} JavaScript Date object
|
||||
*/
|
||||
export function TAItoDate(tai) {
|
||||
|
||||
var utc = TAItoUTC(tai);
|
||||
if (!utc) {
|
||||
utc = TAItoUTC(addSeconds(tai, -1));
|
||||
og.console.logWrn("TAItoDate:336 - can't conv utc.");
|
||||
console.warn("TAItoDate:336 - can't conv utc.");
|
||||
}
|
||||
|
||||
return UTCtoDate(utc);
|
||||
@ -399,7 +404,7 @@ export function addDays(jd, days) {
|
||||
export function getMilliseconds(jd) {
|
||||
var s = jd - (jd | 0);
|
||||
s *= SECONDS_PER_DAY;
|
||||
return (s - (s | 0)) * MILLISECONDS_PER_SECOND | 0;
|
||||
return ((s - (s | 0)) * MILLISECONDS_PER_SECOND) | 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -421,12 +426,12 @@ export function getHours(jd) {
|
||||
var julianDayNumber = jd | 0;
|
||||
var secondsOfDay = (jd - julianDayNumber) * SECONDS_PER_DAY;
|
||||
|
||||
var hour = secondsOfDay * ONE_BY_SECONDS_PER_HOUR | 0;
|
||||
var hour = (secondsOfDay * ONE_BY_SECONDS_PER_HOUR) | 0;
|
||||
var remainingSeconds = secondsOfDay - hour * SECONDS_PER_HOUR;
|
||||
var minute = remainingSeconds * ONE_BY_SECONDS_PER_MINUTE | 0;
|
||||
var minute = (remainingSeconds * ONE_BY_SECONDS_PER_MINUTE) | 0;
|
||||
remainingSeconds = remainingSeconds - minute * SECONDS_PER_MINUTE;
|
||||
var second = remainingSeconds | 0;
|
||||
var millisecond = (remainingSeconds - second) * MILLISECONDS_PER_SECOND | 0;
|
||||
var millisecond = ((remainingSeconds - second) * MILLISECONDS_PER_SECOND) | 0;
|
||||
|
||||
hour += 12 + minute / 60 + second / 3600 + millisecond / 1000;
|
||||
if (hour > 23) {
|
||||
@ -443,7 +448,7 @@ export function getHours(jd) {
|
||||
*/
|
||||
export function getMinutes(jd) {
|
||||
var s = jd - (jd | 0);
|
||||
return s * MINUTES_PER_DAY | 0;
|
||||
return (s * MINUTES_PER_DAY) | 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -507,7 +512,7 @@ const leapSecondsTable = [
|
||||
__ls(2453736.5, 33.0), // 2006-01-01T00:00:00.000Z
|
||||
__ls(2454832.5, 34.0), // 2009-01-01T00:00:00.000Z
|
||||
__ls(2456109.5, 35.0), // 2012-07-01T00:00:00.000Z
|
||||
__ls(2457204.5, 36.0) // 2015-07-01T00:00:00.000Z
|
||||
__ls(2457204.5, 36.0) // 2015-07-01T00:00:00.000Z
|
||||
];
|
||||
|
||||
export const J2000TAI = UTCtoTAI(J2000);
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
* @module og/astro/orbit
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import * as math from '../math.js';
|
||||
import { Mat3 } from '../math/Mat3.js';
|
||||
import * as math from "../math.js";
|
||||
import { Mat3 } from "../math/Mat3.js";
|
||||
|
||||
export function getEccentricAnomaly(M, ecc) {
|
||||
if (ecc == 0.0) {
|
||||
@ -22,14 +22,14 @@ export function getEccentricAnomaly(M, ecc) {
|
||||
// Extremely stable Laguerre-Conway method for solving Kepler's
|
||||
// equation. Only use this for high-eccentricity orbits, as it
|
||||
// requires more calcuation.
|
||||
let E = M + 0.85 * ecc * sign(sin(M));
|
||||
let E = M + 0.85 * ecc * Math.sign(Math.sin(M));
|
||||
return math.solve_iteration_fixed(solveKeplerLaguerreConway(ecc, M), E, 8);
|
||||
} else if (ecc == 1.0) {
|
||||
// TODO: Parabolic orbit
|
||||
return M;
|
||||
} else {
|
||||
// Laguerre-Conway method for hyperbolic (ecc > 1) orbits.
|
||||
let E = log(2 * M / ecc + 1.85);
|
||||
let E = Math.log((2 * M) / ecc + 1.85);
|
||||
return math.solve_iteration_fixed(solveKeplerLaguerreConwayHyp(ecc, M), E, 30);
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,7 @@ function solveKeplerLaguerreConway(ecc, M) {
|
||||
var f = x - s - M;
|
||||
var f1 = 1 - c;
|
||||
var f2 = s;
|
||||
x += -5 * f / (f1 + Math.sign(f1) * Math.sqrt(abs(16 * f1 * f1 - 20 * f * f2)));
|
||||
x += (-5 * f) / (f1 + Math.sign(f1) * Math.sqrt(Math.abs(16 * f1 * f1 - 20 * f * f2)));
|
||||
return x;
|
||||
};
|
||||
}
|
||||
@ -69,7 +69,7 @@ function solveKeplerLaguerreConwayHyp(ecc, M) {
|
||||
var f = s - x - M;
|
||||
var f1 = c - 1;
|
||||
var f2 = s;
|
||||
x += -5 * f / (f1 + Math.sign(f1) * Math.sqrt(Math.abs(16 * f1 * f1 - 20 * f * f2)));
|
||||
x += (-5 * f) / (f1 + Math.sign(f1) * Math.sqrt(Math.abs(16 * f1 * f1 - 20 * f * f2)));
|
||||
return x;
|
||||
};
|
||||
}
|
||||
@ -77,7 +77,7 @@ function solveKeplerLaguerreConwayHyp(ecc, M) {
|
||||
export function getEllipticalEccentricAnomaly(meanAnomaly, eccentricity) {
|
||||
var tol = 0.00000001745;
|
||||
var iterations = 20;
|
||||
var e = meanAnomaly - 2.0 * Math.PI * (meanAnomaly / (2.0 * Math.PI) | 0);
|
||||
var e = meanAnomaly - 2.0 * Math.PI * ((meanAnomaly / (2.0 * Math.PI)) | 0);
|
||||
var err = 1;
|
||||
while (Math.abs(err) > tol && iterations > 0) {
|
||||
err = e - eccentricity * Math.sin(e) - meanAnomaly;
|
||||
@ -91,8 +91,10 @@ export function getEllipticalEccentricAnomaly(meanAnomaly, eccentricity) {
|
||||
export function getTrueAnomaly(eccentricAnomaly, eccentricity) {
|
||||
var revs = Math.floor(eccentricAnomaly / math.TWO_PI);
|
||||
eccentricAnomaly -= revs * math.TWO_PI;
|
||||
var trueAnomaly = Math.atan2(Math.sin(eccentricAnomaly) * Math.sqrt(1 - eccentricity * eccentricity),
|
||||
Math.cos(eccentricAnomaly) - eccentricity);
|
||||
var trueAnomaly = Math.atan2(
|
||||
Math.sin(eccentricAnomaly) * Math.sqrt(1 - eccentricity * eccentricity),
|
||||
Math.cos(eccentricAnomaly) - eccentricity
|
||||
);
|
||||
trueAnomaly = math.zeroTwoPI(trueAnomaly);
|
||||
if (eccentricAnomaly < 0) {
|
||||
trueAnomaly -= math.TWO_PI;
|
||||
@ -118,4 +120,4 @@ export function getPerifocalToCartesianMatrix(argumentOfPeriapsis, inclination,
|
||||
res._m[7] = -cosraan * sini;
|
||||
res._m[8] = cosi;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,20 +2,29 @@
|
||||
* @module og/astro/rotation
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
export function getRotationMatrix(rightAscension, declination) {
|
||||
xAxis.x = Math.cos(rightAscension + og.math.PI_TWO);
|
||||
xAxis.y = Math.sin(rightAscension + og.math.PI_TWO);
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import { Mat3 } from "../math/Mat3.js";
|
||||
import { PI_TWO } from "../math.js";
|
||||
|
||||
export function getRotationMatrix(rightAscension, declination, res) {
|
||||
let xAxis = new Vec3(),
|
||||
zAxis = new Vec3();
|
||||
|
||||
res = res || new Mat3();
|
||||
|
||||
xAxis.x = Math.cos(rightAscension + PI_TWO);
|
||||
xAxis.y = Math.sin(rightAscension + PI_TWO);
|
||||
xAxis.z = 0.0;
|
||||
|
||||
var cosDec = Math.cos(declination);
|
||||
let cosDec = Math.cos(declination);
|
||||
|
||||
zAxis.x = cosDec * Math.cos(rightAscension);
|
||||
zAxis.y = cosDec * Math.sin(rightAscension);
|
||||
zAxis.z = Math.sin(declination);
|
||||
|
||||
var yAxis = zAxis.cross(xAxis);
|
||||
let yAxis = zAxis.cross(xAxis);
|
||||
|
||||
res._m[0] = xAxis.x;
|
||||
res._m[1] = yAxis.x;
|
||||
@ -27,5 +36,5 @@ export function getRotationMatrix(rightAscension, declination) {
|
||||
res._m[7] = yAxis.z;
|
||||
res._m[8] = zAxis.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -2,26 +2,31 @@
|
||||
* @module og/control/EarthCoordinates
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import { Control } from './Control.js';
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
function dec2deg(base) {
|
||||
var t;
|
||||
var degrees = base < 0 ? Math.ceil(base) : Math.floor(base);
|
||||
var minutes = Math.floor(t = Math.abs((base - degrees)) * 60);
|
||||
var minutes = Math.floor((t = Math.abs(base - degrees) * 60));
|
||||
var seconds = Math.floor((t - minutes) * 6000);
|
||||
seconds = seconds / 100.00;
|
||||
return (numToFixedString(degrees, 3) + "\u00B0" +
|
||||
numToFixedString(minutes, 2) + "\u0027" +
|
||||
numToFixedString(seconds.toFixed(2), 2) + "\u0022");
|
||||
seconds = seconds / 100.0;
|
||||
return (
|
||||
numToFixedString(degrees, 3) +
|
||||
"\u00B0" +
|
||||
numToFixedString(minutes, 2) +
|
||||
"\u0027" +
|
||||
numToFixedString(seconds.toFixed(2), 2) +
|
||||
"\u0022"
|
||||
);
|
||||
}
|
||||
|
||||
function numToFixedString(num, fixed) {
|
||||
var dl = num.toString().split('.')[0].length;
|
||||
var dl = num.toString().split(".")[0].length;
|
||||
var white = " ";
|
||||
for (var i = dl; i < fixed; i++) {
|
||||
white += ' ';
|
||||
white += " ";
|
||||
}
|
||||
return white + num.toString();
|
||||
}
|
||||
@ -39,11 +44,7 @@ function toMercator(ll) {
|
||||
return m.lat.toFixed(5) + ", " + m.lon.toFixed(5);
|
||||
}
|
||||
|
||||
const DisplayTypesConverters = [
|
||||
toDecimal,
|
||||
toDegrees,
|
||||
toMercator
|
||||
];
|
||||
const DisplayTypesConverters = [toDecimal, toDegrees, toMercator];
|
||||
|
||||
/**
|
||||
* Control displays mouse or screen center Earth coordinates.
|
||||
@ -55,7 +56,7 @@ const DisplayTypesConverters = [
|
||||
*/
|
||||
class EarthCoordinates extends Control {
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} [options] - Options:
|
||||
*/
|
||||
constructor(options) {
|
||||
@ -91,12 +92,18 @@ class EarthCoordinates extends Control {
|
||||
*/
|
||||
|
||||
var pad = false;
|
||||
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
||||
if (
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent
|
||||
)
|
||||
) {
|
||||
pad = true;
|
||||
}
|
||||
|
||||
this._center = options.center || pad;
|
||||
|
||||
this._centerDiv = null;
|
||||
|
||||
/**
|
||||
* Current position.
|
||||
* @public
|
||||
@ -106,12 +113,11 @@ class EarthCoordinates extends Control {
|
||||
}
|
||||
|
||||
oninit() {
|
||||
this._display = document.createElement('div');
|
||||
this._display.className = 'ogEarthCoordinatesControl';
|
||||
this._display = document.createElement("div");
|
||||
this._display.className = "ogEarthCoordinatesControl";
|
||||
var that = this;
|
||||
|
||||
function _refresh(el) {
|
||||
|
||||
if (that._displayType >= DisplayTypesConverters.length) {
|
||||
that._displayType = 0;
|
||||
}
|
||||
@ -136,19 +142,19 @@ class EarthCoordinates extends Control {
|
||||
|
||||
_refresh(this._display);
|
||||
|
||||
let centerDiv = document.createElement('div');
|
||||
centerDiv.className = 'ogCenterIcon';
|
||||
centerDiv.innerHTML = '<svg width="12" height="12"><g><path stroke-width="1" stroke-opacity="1" d="M6 0L6 12M0 6L12 6" stroke="#009DFF"></path></g></svg>';
|
||||
this.renderer.div.appendChild(centerDiv);
|
||||
this._centerDiv = document.createElement("div");
|
||||
this._centerDiv.className = "ogCenterIcon";
|
||||
this._centerDiv.innerHTML =
|
||||
'<svg width="12" height="12"><g><path stroke-width="1" stroke-opacity="1" d="M6 0L6 12M0 6L12 6" stroke="#009DFF"></path></g></svg>';
|
||||
this.renderer.div.appendChild(this._centerDiv);
|
||||
|
||||
if (this._center) {
|
||||
this.renderer.activeCamera.events.on("moveend", this._grabCoordinates, this);
|
||||
centerDiv.style.display = "block";
|
||||
this._centerDiv.style.display = "block";
|
||||
} else {
|
||||
this.renderer.events.on("mousemove", this._onMouseMove, this);
|
||||
centerDiv.style.display = "none";
|
||||
this._centerDiv.style.display = "none";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,19 +168,28 @@ class EarthCoordinates extends Control {
|
||||
if (center) {
|
||||
this.renderer.events.off("mousemove", this._onMouseMove);
|
||||
this.renderer.activeCamera.events.on("moveend", this._grabCoordinates, this);
|
||||
centerDiv.style.display = "block";
|
||||
this._centerDiv.style.display = "block";
|
||||
} else {
|
||||
this.renderer.events.off("draw", this._draw);
|
||||
this.renderer.events.on("mousemove", this._onMouseMove, this);
|
||||
centerDiv.style.display = "none";
|
||||
this._centerDiv.style.display = "none";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_showPosition() {
|
||||
if (this.position) {
|
||||
this.position.height = ((this.position.height > 10000 || this.position.height < -10000) ? 0 : this.position.height);
|
||||
this._display.innerHTML = "Lat/Lon: " + this._converter(this.position) + " h(m): " + (this.position.height > 0 ? "~" + (Math.round(this.position.height) / 1000).toFixed(3) * 1000 : "-");
|
||||
this.position.height =
|
||||
this.position.height > 10000 || this.position.height < -10000
|
||||
? 0
|
||||
: this.position.height;
|
||||
this._display.innerHTML =
|
||||
"Lat/Lon: " +
|
||||
this._converter(this.position) +
|
||||
" h(m): " +
|
||||
(this.position.height > 0
|
||||
? "~" + (Math.round(this.position.height) / 1000).toFixed(3) * 1000
|
||||
: "-");
|
||||
} else {
|
||||
this._display.innerHTML = "Lat/Lon: " + "_____________________";
|
||||
}
|
||||
@ -189,9 +204,11 @@ class EarthCoordinates extends Control {
|
||||
_onMouseMove() {
|
||||
var r = this.renderer;
|
||||
var ms = r.events.mouseState;
|
||||
if (!(ms.leftButtonDown || ms.rightButtonDown) &&
|
||||
if (
|
||||
!(ms.leftButtonDown || ms.rightButtonDown) &&
|
||||
r.controlsBag.scaleRot <= 0 &&
|
||||
!r.activeCamera._flying) {
|
||||
!r.activeCamera._flying
|
||||
) {
|
||||
this.position = this.planet.getLonLatFromPixelTerrain(ms, true);
|
||||
this._showPosition();
|
||||
}
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
* @module og/entity/BaseBillboard
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import * as utils from '../utils/shared.js';
|
||||
import { Vec3 } from '../math/Vec3.js';
|
||||
import * as utils from "../utils/shared.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
/**
|
||||
* Base prototype for billboard and label classes.
|
||||
@ -38,9 +38,9 @@ class BaseBillboard {
|
||||
this._position = utils.createVector3(options.position);
|
||||
|
||||
this._positionHigh = new Vec3();
|
||||
|
||||
|
||||
this._positionLow = new Vec3();
|
||||
|
||||
|
||||
Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
|
||||
|
||||
/**
|
||||
@ -121,9 +121,10 @@ class BaseBillboard {
|
||||
setPosition(x, y, z) {
|
||||
this._position.x = x;
|
||||
this._position.y = y;
|
||||
this._position.z = z;
|
||||
Vec3.doubleToTwoFloats(position, this._positionHigh, this._positionLow);
|
||||
this._handler && this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
this._position.z = z;
|
||||
Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
|
||||
this._handler &&
|
||||
this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,7 +137,8 @@ class BaseBillboard {
|
||||
this._position.y = position.y;
|
||||
this._position.z = position.z;
|
||||
Vec3.doubleToTwoFloats(position, this._positionHigh, this._positionLow);
|
||||
this._handler && this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
this._handler &&
|
||||
this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,7 +160,7 @@ class BaseBillboard {
|
||||
setOffset(x, y, z) {
|
||||
this._offset.x = x;
|
||||
this._offset.y = y;
|
||||
(z != undefined) && (this._offset.z = z);
|
||||
z != undefined && (this._offset.z = z);
|
||||
this._handler && this._handler.setOffsetArr(this._handlerIndex, this._offset);
|
||||
}
|
||||
|
||||
@ -170,7 +172,7 @@ class BaseBillboard {
|
||||
setOffset3v(offset) {
|
||||
this._offset.x = offset.x;
|
||||
this._offset.y = offset.y;
|
||||
(offset.z != undefined) && (this._offset.z = offset.z);
|
||||
offset.z != undefined && (this._offset.z = offset.z);
|
||||
this._handler && this._handler.setOffsetArr(this._handlerIndex, offset);
|
||||
}
|
||||
|
||||
@ -224,7 +226,7 @@ class BaseBillboard {
|
||||
this._color.x = r;
|
||||
this._color.y = g;
|
||||
this._color.z = b;
|
||||
(a != undefined) && (this._color.w = a);
|
||||
a != undefined && (this._color.w = a);
|
||||
this._handler && this._handler.setRgbaArr(this._handlerIndex, this._color);
|
||||
}
|
||||
|
||||
@ -237,7 +239,7 @@ class BaseBillboard {
|
||||
this._color.x = color.x;
|
||||
this._color.y = color.y;
|
||||
this._color.z = color.z;
|
||||
(color.w != undefined) && (this._color.w = color.w);
|
||||
color.w != undefined && (this._color.w = color.w);
|
||||
this._handler && this._handler.setRgbaArr(this._handlerIndex, color);
|
||||
}
|
||||
|
||||
@ -332,4 +334,4 @@ class BaseBillboard {
|
||||
}
|
||||
}
|
||||
|
||||
export { BaseBillboard };
|
||||
export { BaseBillboard };
|
||||
|
||||
@ -2,21 +2,21 @@
|
||||
* @module og/entity/Entity
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import * as mercator from '../mercator.js';
|
||||
import * as utils from '../utils/shared.js';
|
||||
import { Billboard } from './Billboard.js';
|
||||
import { Strip } from './Strip.js';
|
||||
import { Extent } from '../Extent.js';
|
||||
import { Geometry } from './Geometry.js';
|
||||
import { Label } from './Label.js';
|
||||
import { LonLat } from '../LonLat.js';
|
||||
import { Polyline } from './Polyline.js';
|
||||
import { Ray } from './Ray.js';
|
||||
import { PointCloud } from './PointCloud.js';
|
||||
import { Sphere } from '../shapes/Sphere.js';
|
||||
import { Vec3 } from '../math/Vec3.js';
|
||||
import * as mercator from "../mercator.js";
|
||||
import * as utils from "../utils/shared.js";
|
||||
import { Billboard } from "./Billboard.js";
|
||||
import { Strip } from "./Strip.js";
|
||||
import { Extent } from "../Extent.js";
|
||||
import { Geometry } from "./Geometry.js";
|
||||
import { Label } from "./Label.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import { Polyline } from "./Polyline.js";
|
||||
import { Ray } from "./Ray.js";
|
||||
import { PointCloud } from "./PointCloud.js";
|
||||
import { Sphere } from "../shapes/Sphere.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
/**
|
||||
* Entity instances aggregate multiple forms of visualization into a single high-level object.
|
||||
@ -41,7 +41,6 @@ import { Vec3 } from '../math/Vec3.js';
|
||||
*/
|
||||
class Entity {
|
||||
constructor(options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
options.properties = options.properties || {};
|
||||
@ -168,56 +167,56 @@ class Entity {
|
||||
* @public
|
||||
* @type {Billboard}
|
||||
*/
|
||||
this.billboard = this._createOptionFeature('billboard', options.billboard);
|
||||
this.billboard = this._createOptionFeature("billboard", options.billboard);
|
||||
|
||||
/**
|
||||
* Text label entity.
|
||||
* @public
|
||||
* @type {Label}
|
||||
*/
|
||||
this.label = this._createOptionFeature('label', options.label);
|
||||
this.label = this._createOptionFeature("label", options.label);
|
||||
|
||||
/**
|
||||
* Shape entity.
|
||||
* @public
|
||||
* @type {shape.BaseShape}
|
||||
*/
|
||||
this.shape = this._createOptionFeature('sphere', options.sphere || options.box);
|
||||
this.shape = this._createOptionFeature("sphere", options.sphere || options.box);
|
||||
|
||||
/**
|
||||
* Polyline entity.
|
||||
* @public
|
||||
* @type {Polyline}
|
||||
*/
|
||||
this.polyline = this._createOptionFeature('polyline', options.polyline);
|
||||
this.polyline = this._createOptionFeature("polyline", options.polyline);
|
||||
|
||||
/**
|
||||
* Ray entity.
|
||||
* @public
|
||||
* @type {ray}
|
||||
*/
|
||||
this.ray = this._createOptionFeature('ray', options.ray);
|
||||
this.ray = this._createOptionFeature("ray", options.ray);
|
||||
|
||||
/**
|
||||
* PointCloud entity.
|
||||
* @public
|
||||
* @type {PointCloud}
|
||||
*/
|
||||
this.pointCloud = this._createOptionFeature('pointCloud', options.pointCloud);
|
||||
this.pointCloud = this._createOptionFeature("pointCloud", options.pointCloud);
|
||||
|
||||
/**
|
||||
* Geometry entity(available for vector layer only).
|
||||
* @public
|
||||
* @type {Geometry}
|
||||
*/
|
||||
this.geometry = this._createOptionFeature('geometry', options.geometry);
|
||||
this.geometry = this._createOptionFeature("geometry", options.geometry);
|
||||
|
||||
/**
|
||||
* Strip entity.
|
||||
* @public
|
||||
* @type {Strip}
|
||||
*/
|
||||
this.strip = this._createOptionFeature('strip', options.strip);
|
||||
this.strip = this._createOptionFeature("strip", options.strip);
|
||||
}
|
||||
|
||||
static get _staticCounter() {
|
||||
@ -325,7 +324,6 @@ class Entity {
|
||||
* @param {number} z - 3d space Z - position.
|
||||
*/
|
||||
setCartesian(x, y, z) {
|
||||
|
||||
var p = this._cartesian;
|
||||
|
||||
p.x = x;
|
||||
@ -348,7 +346,6 @@ class Entity {
|
||||
var ec = this._entityCollection;
|
||||
|
||||
if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
|
||||
|
||||
this._lonlat = ec.renderNode.ellipsoid.cartesianToLonLat(p);
|
||||
|
||||
if (Math.abs(this._lonlat.lat) < mercator.MAX_LAT) {
|
||||
@ -368,7 +365,6 @@ class Entity {
|
||||
* @param {boolean} skipLonLat - skip geodetic calculation.
|
||||
*/
|
||||
_setCartesian3vSilent(cartesian, skipLonLat) {
|
||||
|
||||
var p = this._cartesian;
|
||||
|
||||
p.x = cartesian.x;
|
||||
@ -385,13 +381,12 @@ class Entity {
|
||||
this.shape && this.shape.setPosition3v(p);
|
||||
|
||||
for (var i = 0; i < this.childrenNodes.length; i++) {
|
||||
this.childrenNodes[i].setCartesian(x, y, z);
|
||||
this.childrenNodes[i].setCartesian(p.x, p.y, p.z);
|
||||
}
|
||||
|
||||
var ec = this._entityCollection;
|
||||
|
||||
if (!skipLonLat && ec && ec.renderNode && ec.renderNode.ellipsoid) {
|
||||
|
||||
this._lonlat = ec.renderNode.ellipsoid.cartesianToLonLat(p);
|
||||
|
||||
if (Math.abs(this._lonlat.lat) < mercator.MAX_LAT) {
|
||||
@ -425,7 +420,6 @@ class Entity {
|
||||
|
||||
var ec = this._entityCollection;
|
||||
if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
|
||||
|
||||
if (Math.abs(lonlat.lat) < mercator.MAX_LAT) {
|
||||
this._lonlatMerc = lonlat.forwardMercator();
|
||||
} else {
|
||||
@ -613,6 +607,7 @@ class Entity {
|
||||
} else if (this._entityCollection) {
|
||||
return this._entityCollection.events;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -633,7 +628,6 @@ class Entity {
|
||||
* @public
|
||||
*/
|
||||
setPickingColor() {
|
||||
|
||||
var c = this._pickingColor;
|
||||
|
||||
// billboard
|
||||
|
||||
@ -2,12 +2,12 @@
|
||||
* @module og/entity/Geometry
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import * as utils from '../utils/shared.js';
|
||||
import { Extent } from '../Extent.js';
|
||||
import { Vec4 } from '../math/Vec4.js';
|
||||
import { LonLat } from '../LonLat.js';
|
||||
import * as utils from "../utils/shared.js";
|
||||
import { Extent } from "../Extent.js";
|
||||
import { Vec4 } from "../math/Vec4.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
|
||||
const GeometryType = {
|
||||
POINT: 1,
|
||||
@ -58,15 +58,27 @@ class Geometry {
|
||||
|
||||
this._type = (options.type && Geometry.getType(options.type)) || GeometryType.POINT;
|
||||
this._coordinates = [];
|
||||
this._extent = Geometry.getExtent({
|
||||
type: options.type || "Point",
|
||||
coordinates: options.coordinates || []
|
||||
}, this._coordinates);
|
||||
this._extent = Geometry.getExtent(
|
||||
{
|
||||
type: options.type || "Point",
|
||||
coordinates: options.coordinates || []
|
||||
},
|
||||
this._coordinates
|
||||
);
|
||||
|
||||
this._style = options.style || {};
|
||||
this._style.fillColor = utils.createColorRGBA(options.style.fillColor, new Vec4(0.19, 0.62, 0.85, 0.4));
|
||||
this._style.lineColor = utils.createColorRGBA(options.style.lineColor, new Vec4(0.19, 0.62, 0.85, 1));
|
||||
this._style.strokeColor = utils.createColorRGBA(options.style.strokeColor, new Vec4(1, 1, 1, 0.95));
|
||||
this._style.fillColor = utils.createColorRGBA(
|
||||
options.style.fillColor,
|
||||
new Vec4(0.19, 0.62, 0.85, 0.4)
|
||||
);
|
||||
this._style.lineColor = utils.createColorRGBA(
|
||||
options.style.lineColor,
|
||||
new Vec4(0.19, 0.62, 0.85, 1)
|
||||
);
|
||||
this._style.strokeColor = utils.createColorRGBA(
|
||||
options.style.strokeColor,
|
||||
new Vec4(1, 1, 1, 0.95)
|
||||
);
|
||||
this._style.lineWidth = options.style.lineWidth || 3;
|
||||
this._style.strokeWidth = options.style.strokeWidth || 0;
|
||||
|
||||
@ -110,9 +122,7 @@ class Geometry {
|
||||
res.northEast.lon = lon;
|
||||
res.northEast.lat = lat;
|
||||
outCoordinates && (outCoordinates[0] = lon) && (outCoordinates[1] = lat);
|
||||
|
||||
} else if (t === GeometryType.LINESTRING) {
|
||||
|
||||
let c = geometryObj.coordinates;
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
let lon = c[i][0],
|
||||
@ -123,9 +133,7 @@ class Geometry {
|
||||
if (lat > res.northEast.lat) res.northEast.lat = lat;
|
||||
outCoordinates && (outCoordinates[i] = [lon, lat]);
|
||||
}
|
||||
|
||||
} else if (t === GeometryType.POLYGON) {
|
||||
|
||||
let c = geometryObj.coordinates;
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
let ci = c[i];
|
||||
@ -141,9 +149,7 @@ class Geometry {
|
||||
outCoordinates && (outCoordinates[i][j] = [lon, lat]);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (t === GeometryType.MULTIPOLYGON) {
|
||||
|
||||
let p = geometryObj.coordinates;
|
||||
for (let i = 0; i < p.length; i++) {
|
||||
let pi = p[i];
|
||||
@ -163,9 +169,7 @@ class Geometry {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (t === GeometryType.MULTILINESTRING) {
|
||||
|
||||
let c = geometryObj.coordinates;
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
let ci = c[i];
|
||||
@ -181,10 +185,9 @@ class Geometry {
|
||||
outCoordinates && (outCoordinates[i][j] = [lon, lat]);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
res.southWest.lon = res.southWest.lat = res.northEast.lon = res.northEast.lat = 0.0;
|
||||
outCoordinates && (outCoordinates[0] = lon) && (outCoordinates[1] = lat);
|
||||
outCoordinates && (outCoordinates[0] = 0) && (outCoordinates[1] = 0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -31,9 +31,9 @@ window.dZ = 1.1;
|
||||
*/
|
||||
class LabelHandler extends BillboardHandler {
|
||||
/**
|
||||
*
|
||||
* @param {*} entityCollection
|
||||
* @param {*} maxLetters
|
||||
*
|
||||
* @param {*} entityCollection
|
||||
* @param {*} maxLetters
|
||||
*/
|
||||
constructor(entityCollection, maxLetters = 21) {
|
||||
super(entityCollection);
|
||||
@ -1156,8 +1156,6 @@ class LabelHandler extends BillboardHandler {
|
||||
}
|
||||
|
||||
setFontIndexArr(index, fontIndex) {
|
||||
fontIndex = fontIndex;
|
||||
|
||||
var i = index * 6 * this._maxLetters;
|
||||
var a = this._fontIndexArr;
|
||||
|
||||
|
||||
@ -1,17 +1,9 @@
|
||||
import { Entity } from './Entity';
|
||||
import { EntityCollection } from './EntityCollection';
|
||||
import { Billboard } from './Billboard';
|
||||
import { Geometry } from './Geometry';
|
||||
import { Label } from './Label';
|
||||
import { PointCloud } from './PointCloud';
|
||||
import { Polyline } from './Polyline';
|
||||
import { Entity } from "./Entity.js";
|
||||
import { EntityCollection } from "./EntityCollection.js";
|
||||
import { Billboard } from "./Billboard.js";
|
||||
import { Geometry } from "./Geometry.js";
|
||||
import { Label } from "./Label.js";
|
||||
import { PointCloud } from "./PointCloud.js";
|
||||
import { Polyline } from "./Polyline.js";
|
||||
|
||||
export {
|
||||
Entity,
|
||||
EntityCollection,
|
||||
Billboard,
|
||||
Geometry,
|
||||
Label,
|
||||
PointCloud,
|
||||
Polyline
|
||||
};
|
||||
export { Entity, EntityCollection, Billboard, Geometry, Label, PointCloud, Polyline };
|
||||
|
||||
@ -77,7 +77,7 @@ export const EPSILON20 = 1e-20;
|
||||
* @param {number} base - Base value.
|
||||
* @returns {number} -
|
||||
* @example
|
||||
* og.math.log(64, 2)
|
||||
* log(64, 2)
|
||||
* //returns 6
|
||||
*/
|
||||
export function log(n, base) {
|
||||
@ -92,7 +92,7 @@ export function log(n, base) {
|
||||
* @param {number} max - Maximal edge.
|
||||
* @returns {number} -
|
||||
* @example
|
||||
* og.math.clamp(12, 1, 5)
|
||||
* clamp(12, 1, 5)
|
||||
* //returns 5
|
||||
*/
|
||||
export function clamp(number, min, max) {
|
||||
@ -200,9 +200,9 @@ export function mod(m, n) {
|
||||
* @returns {number} -
|
||||
*/
|
||||
export function zeroTwoPI(a) {
|
||||
var mod = og.math.mod(a, og.math.TWO_PI);
|
||||
if (Math.abs(mod) < og.math.EPSILON14 && Math.abs(a) > og.math.EPSILON14) {
|
||||
return og.math.TWO_PI;
|
||||
var mod = mod(a, TWO_PI);
|
||||
if (Math.abs(mod) < EPSILON14 && Math.abs(a) > EPSILON14) {
|
||||
return TWO_PI;
|
||||
}
|
||||
return mod;
|
||||
}
|
||||
@ -235,7 +235,7 @@ export function frac(x) {
|
||||
* @returns {number} -
|
||||
*/
|
||||
export function log2(x) {
|
||||
return Math.log(x) / og.math.LOG2;
|
||||
return Math.log(x) / LOG2;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -346,7 +346,7 @@ export function norm_lon(lon) {
|
||||
* @returns {number} -
|
||||
*/
|
||||
export function negativePItoPI(a) {
|
||||
return og.math.zeroTwoPI(a + Math.PI) - Math.PI;
|
||||
return zeroTwoPI(a + Math.PI) - Math.PI;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import { Mat3 } from './Mat3.js';
|
||||
import { Quat } from './Quat.js';
|
||||
import { Vec3 } from './Vec3.js';
|
||||
import { Vec4 } from './Vec4.js';
|
||||
import { Mat3 } from "./Mat3.js";
|
||||
import { Quat } from "./Quat.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
import { Vec4 } from "./Vec4.js";
|
||||
|
||||
/**
|
||||
* Class represents a 4x4 matrix.
|
||||
@ -18,7 +18,7 @@ export class Mat4 {
|
||||
*/
|
||||
this._m = new Array(16);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns identity matrix instance.
|
||||
* @static
|
||||
@ -26,10 +26,22 @@ export class Mat4 {
|
||||
*/
|
||||
static get identity() {
|
||||
var res = new Mat4();
|
||||
res._m[0] = 1; res._m[1] = 0; res._m[2] = 0; res._m[3] = 0;
|
||||
res._m[4] = 0; res._m[5] = 1; res._m[6] = 0; res._m[7] = 0;
|
||||
res._m[8] = 0; res._m[9] = 0; res._m[10] = 1; res._m[11] = 0;
|
||||
res._m[12] = 0; res._m[13] = 0; res._m[14] = 0; res._m[15] = 1;
|
||||
res._m[0] = 1;
|
||||
res._m[1] = 0;
|
||||
res._m[2] = 0;
|
||||
res._m[3] = 0;
|
||||
res._m[4] = 0;
|
||||
res._m[5] = 1;
|
||||
res._m[6] = 0;
|
||||
res._m[7] = 0;
|
||||
res._m[8] = 0;
|
||||
res._m[9] = 0;
|
||||
res._m[10] = 1;
|
||||
res._m[11] = 0;
|
||||
res._m[12] = 0;
|
||||
res._m[13] = 0;
|
||||
res._m[14] = 0;
|
||||
res._m[15] = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -107,7 +119,9 @@ export class Mat4 {
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
mulVec3(p) {
|
||||
var d = p.x, e = p.y, g = p.z;
|
||||
var d = p.x,
|
||||
e = p.y,
|
||||
g = p.z;
|
||||
return new Vec3(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
|
||||
@ -122,7 +136,10 @@ export class Mat4 {
|
||||
* @returns {Vec4} -
|
||||
*/
|
||||
mulVec4(p) {
|
||||
var d = p.x, e = p.y, g = p.z, f = p.w;
|
||||
var d = p.x,
|
||||
e = p.y,
|
||||
g = p.z,
|
||||
f = p.w;
|
||||
return new Vec4(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
|
||||
@ -138,9 +155,15 @@ export class Mat4 {
|
||||
*/
|
||||
toInverseMatrix3() {
|
||||
var a = this._m;
|
||||
var c = a[0], d = a[1], e = a[2],
|
||||
g = a[4], f = a[5], h = a[6],
|
||||
i = a[8], j = a[9], k = a[10],
|
||||
var c = a[0],
|
||||
d = a[1],
|
||||
e = a[2],
|
||||
g = a[4],
|
||||
f = a[5],
|
||||
h = a[6],
|
||||
i = a[8],
|
||||
j = a[9],
|
||||
k = a[10],
|
||||
l = k * f - h * j,
|
||||
o = -k * g + h * i,
|
||||
m = j * g - f * i,
|
||||
@ -171,10 +194,22 @@ export class Mat4 {
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
inverseTo(res) {
|
||||
var c = this._m[0], d = this._m[1], e = this._m[2], g = this._m[3],
|
||||
f = this._m[4], h = this._m[5], i = this._m[6], j = this._m[7],
|
||||
k = this._m[8], l = this._m[9], o = this._m[10], m = this._m[11],
|
||||
n = this._m[12], p = this._m[13], r = this._m[14], s = this._m[15],
|
||||
var c = this._m[0],
|
||||
d = this._m[1],
|
||||
e = this._m[2],
|
||||
g = this._m[3],
|
||||
f = this._m[4],
|
||||
h = this._m[5],
|
||||
i = this._m[6],
|
||||
j = this._m[7],
|
||||
k = this._m[8],
|
||||
l = this._m[9],
|
||||
o = this._m[10],
|
||||
m = this._m[11],
|
||||
n = this._m[12],
|
||||
p = this._m[13],
|
||||
r = this._m[14],
|
||||
s = this._m[15],
|
||||
A = c * h - d * f,
|
||||
B = c * i - e * f,
|
||||
t = c * j - g * f,
|
||||
@ -187,13 +222,26 @@ export class Mat4 {
|
||||
C = l * r - o * p,
|
||||
D = l * s - m * p,
|
||||
E = o * s - m * r,
|
||||
q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x),
|
||||
res = res || new Mat4();
|
||||
q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x);
|
||||
|
||||
res._m[0] = (h * E - i * D + j * C) * q; res._m[1] = (-d * E + e * D - g * C) * q; res._m[2] = (p * w - r * v + s * u) * q; res._m[3] = (-l * w + o * v - m * u) * q;
|
||||
res._m[4] = (-f * E + i * z - j * y) * q; res._m[5] = (c * E - e * z + g * y) * q; res._m[6] = (-n * w + r * t - s * B) * q; res._m[7] = (k * w - o * t + m * B) * q;
|
||||
res._m[8] = (f * D - h * z + j * x) * q; res._m[9] = (-c * D + d * z - g * x) * q; res._m[10] = (n * v - p * t + s * A) * q; res._m[11] = (-k * v + l * t - m * A) * q;
|
||||
res._m[12] = (-f * C + h * y - i * x) * q; res._m[13] = (c * C - d * y + e * x) * q; res._m[14] = (-n * u + p * B - r * A) * q; res._m[15] = (k * u - l * B + o * A) * q;
|
||||
res = res || new Mat4();
|
||||
|
||||
res._m[0] = (h * E - i * D + j * C) * q;
|
||||
res._m[1] = (-d * E + e * D - g * C) * q;
|
||||
res._m[2] = (p * w - r * v + s * u) * q;
|
||||
res._m[3] = (-l * w + o * v - m * u) * q;
|
||||
res._m[4] = (-f * E + i * z - j * y) * q;
|
||||
res._m[5] = (c * E - e * z + g * y) * q;
|
||||
res._m[6] = (-n * w + r * t - s * B) * q;
|
||||
res._m[7] = (k * w - o * t + m * B) * q;
|
||||
res._m[8] = (f * D - h * z + j * x) * q;
|
||||
res._m[9] = (-c * D + d * z - g * x) * q;
|
||||
res._m[10] = (n * v - p * t + s * A) * q;
|
||||
res._m[11] = (-k * v + l * t - m * A) * q;
|
||||
res._m[12] = (-f * C + h * y - i * x) * q;
|
||||
res._m[13] = (c * C - d * y + e * x) * q;
|
||||
res._m[14] = (-n * u + p * B - r * A) * q;
|
||||
res._m[15] = (k * u - l * B + o * A) * q;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -204,10 +252,22 @@ export class Mat4 {
|
||||
*/
|
||||
transposeTo() {
|
||||
var res = new Mat4();
|
||||
res._m[0] = this._m[0]; res._m[1] = this._m[4]; res._m[2] = this._m[8]; res._m[3] = this._m[12];
|
||||
res._m[4] = this._m[1]; res._m[5] = this._m[5]; res._m[6] = this._m[9]; res._m[7] = this._m[13];
|
||||
res._m[8] = this._m[2]; res._m[9] = this._m[6]; res._m[10] = this._m[10]; res._m[11] = this._m[14];
|
||||
res._m[12] = this._m[3]; res._m[13] = this._m[7]; res._m[14] = this._m[11]; res._m[15] = this._m[15];
|
||||
res._m[0] = this._m[0];
|
||||
res._m[1] = this._m[4];
|
||||
res._m[2] = this._m[8];
|
||||
res._m[3] = this._m[12];
|
||||
res._m[4] = this._m[1];
|
||||
res._m[5] = this._m[5];
|
||||
res._m[6] = this._m[9];
|
||||
res._m[7] = this._m[13];
|
||||
res._m[8] = this._m[2];
|
||||
res._m[9] = this._m[6];
|
||||
res._m[10] = this._m[10];
|
||||
res._m[11] = this._m[14];
|
||||
res._m[12] = this._m[3];
|
||||
res._m[13] = this._m[7];
|
||||
res._m[14] = this._m[11];
|
||||
res._m[15] = this._m[15];
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -217,10 +277,22 @@ export class Mat4 {
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
setIdentity() {
|
||||
this._m[0] = 1; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
|
||||
this._m[4] = 0; this._m[5] = 1; this._m[6] = 0; this._m[7] = 0;
|
||||
this._m[8] = 0; this._m[9] = 0; this._m[10] = 1; this._m[11] = 0;
|
||||
this._m[12] = 0; this._m[13] = 0; this._m[14] = 0; this._m[15] = 1;
|
||||
this._m[0] = 1;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
this._m[3] = 0;
|
||||
this._m[4] = 0;
|
||||
this._m[5] = 1;
|
||||
this._m[6] = 0;
|
||||
this._m[7] = 0;
|
||||
this._m[8] = 0;
|
||||
this._m[9] = 0;
|
||||
this._m[10] = 1;
|
||||
this._m[11] = 0;
|
||||
this._m[12] = 0;
|
||||
this._m[13] = 0;
|
||||
this._m[14] = 0;
|
||||
this._m[15] = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -231,21 +303,57 @@ export class Mat4 {
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
mul(mx) {
|
||||
let d = this._m[0], e = this._m[1], g = this._m[2], f = this._m[3],
|
||||
h = this._m[4], i = this._m[5], j = this._m[6], k = this._m[7],
|
||||
l = this._m[8], o = this._m[9], m = this._m[10], n = this._m[11],
|
||||
p = this._m[12], r = this._m[13], s = this._m[14], a = this._m[15];
|
||||
let d = this._m[0],
|
||||
e = this._m[1],
|
||||
g = this._m[2],
|
||||
f = this._m[3],
|
||||
h = this._m[4],
|
||||
i = this._m[5],
|
||||
j = this._m[6],
|
||||
k = this._m[7],
|
||||
l = this._m[8],
|
||||
o = this._m[9],
|
||||
m = this._m[10],
|
||||
n = this._m[11],
|
||||
p = this._m[12],
|
||||
r = this._m[13],
|
||||
s = this._m[14],
|
||||
a = this._m[15];
|
||||
|
||||
let A = mx._m[0], B = mx._m[1], t = mx._m[2], u = mx._m[3],
|
||||
v = mx._m[4], w = mx._m[5], x = mx._m[6], y = mx._m[7],
|
||||
z = mx._m[8], C = mx._m[9], D = mx._m[10], E = mx._m[11],
|
||||
q = mx._m[12], F = mx._m[13], G = mx._m[14], b = mx._m[15];
|
||||
let A = mx._m[0],
|
||||
B = mx._m[1],
|
||||
t = mx._m[2],
|
||||
u = mx._m[3],
|
||||
v = mx._m[4],
|
||||
w = mx._m[5],
|
||||
x = mx._m[6],
|
||||
y = mx._m[7],
|
||||
z = mx._m[8],
|
||||
C = mx._m[9],
|
||||
D = mx._m[10],
|
||||
E = mx._m[11],
|
||||
q = mx._m[12],
|
||||
F = mx._m[13],
|
||||
G = mx._m[14],
|
||||
b = mx._m[15];
|
||||
|
||||
var res = new Mat4();
|
||||
res._m[0] = A * d + B * h + t * l + u * p; res._m[1] = A * e + B * i + t * o + u * r; res._m[2] = A * g + B * j + t * m + u * s; res._m[3] = A * f + B * k + t * n + u * a;
|
||||
res._m[4] = v * d + w * h + x * l + y * p; res._m[5] = v * e + w * i + x * o + y * r; res._m[6] = v * g + w * j + x * m + y * s; res._m[7] = v * f + w * k + x * n + y * a;
|
||||
res._m[8] = z * d + C * h + D * l + E * p; res._m[9] = z * e + C * i + D * o + E * r; res._m[10] = z * g + C * j + D * m + E * s; res._m[11] = z * f + C * k + D * n + E * a;
|
||||
res._m[12] = q * d + F * h + G * l + b * p; res._m[13] = q * e + F * i + G * o + b * r; res._m[14] = q * g + F * j + G * m + b * s; res._m[15] = q * f + F * k + G * n + b * a;
|
||||
res._m[0] = A * d + B * h + t * l + u * p;
|
||||
res._m[1] = A * e + B * i + t * o + u * r;
|
||||
res._m[2] = A * g + B * j + t * m + u * s;
|
||||
res._m[3] = A * f + B * k + t * n + u * a;
|
||||
res._m[4] = v * d + w * h + x * l + y * p;
|
||||
res._m[5] = v * e + w * i + x * o + y * r;
|
||||
res._m[6] = v * g + w * j + x * m + y * s;
|
||||
res._m[7] = v * f + w * k + x * n + y * a;
|
||||
res._m[8] = z * d + C * h + D * l + E * p;
|
||||
res._m[9] = z * e + C * i + D * o + E * r;
|
||||
res._m[10] = z * g + C * j + D * m + E * s;
|
||||
res._m[11] = z * f + C * k + D * n + E * a;
|
||||
res._m[12] = q * d + F * h + G * l + b * p;
|
||||
res._m[13] = q * e + F * i + G * o + b * r;
|
||||
res._m[14] = q * g + F * j + G * m + b * s;
|
||||
res._m[15] = q * f + F * k + G * n + b * a;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -256,7 +364,9 @@ export class Mat4 {
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
translate(v) {
|
||||
var d = v.x, e = v.y, b = v.z;
|
||||
var d = v.x,
|
||||
e = v.y,
|
||||
b = v.z;
|
||||
var a = this._m;
|
||||
a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
|
||||
a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
|
||||
@ -292,10 +402,22 @@ export class Mat4 {
|
||||
s = Math.sin(angle);
|
||||
var rot = new Mat4();
|
||||
var mx = rot._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
mx[0] = c + (1 - c) * u.x * u.x;
|
||||
mx[1] = (1 - c) * u.y * u.x - s * u.z;
|
||||
mx[2] = (1 - c) * u.z * u.x + s * u.y;
|
||||
mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z;
|
||||
mx[5] = c + (1 - c) * u.y * u.y;
|
||||
mx[6] = (1 - c) * u.z * u.y - s * u.x;
|
||||
mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y;
|
||||
mx[9] = (1 - c) * u.y * u.z + s * u.x;
|
||||
mx[10] = c + (1 - c) * u.z * u.z;
|
||||
mx[11] = 0;
|
||||
mx[12] = 0;
|
||||
mx[13] = 0;
|
||||
mx[14] = 0;
|
||||
mx[15] = 1;
|
||||
return this.mul(rot);
|
||||
}
|
||||
|
||||
@ -310,10 +432,22 @@ export class Mat4 {
|
||||
var c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var mx = this._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
mx[0] = c + (1 - c) * u.x * u.x;
|
||||
mx[1] = (1 - c) * u.y * u.x - s * u.z;
|
||||
mx[2] = (1 - c) * u.z * u.x + s * u.y;
|
||||
mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z;
|
||||
mx[5] = c + (1 - c) * u.y * u.y;
|
||||
mx[6] = (1 - c) * u.z * u.y - s * u.x;
|
||||
mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y;
|
||||
mx[9] = (1 - c) * u.y * u.z + s * u.x;
|
||||
mx[10] = c + (1 - c) * u.z * u.z;
|
||||
mx[11] = 0;
|
||||
mx[12] = 0;
|
||||
mx[13] = 0;
|
||||
mx[14] = 0;
|
||||
mx[15] = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -337,9 +471,18 @@ export class Mat4 {
|
||||
*/
|
||||
scale(v) {
|
||||
var mx = this._m;
|
||||
mx[0] = mx[0] * v.x; mx[1] = mx[1] * v.x; mx[2] = mx[2] * v.x; mx[3] = mx[3] * v.x;
|
||||
mx[4] = mx[4] * v.y; mx[5] = mx[5] * v.y; mx[6] = mx[6] * v.y; mx[7] = mx[7] * v.y;
|
||||
mx[8] = mx[8] * v.z; mx[9] = mx[9] * v.z; mx[10] = mx[10] * v.z; mx[11] = mx[11] * v.z;
|
||||
mx[0] = mx[0] * v.x;
|
||||
mx[1] = mx[1] * v.x;
|
||||
mx[2] = mx[2] * v.x;
|
||||
mx[3] = mx[3] * v.x;
|
||||
mx[4] = mx[4] * v.y;
|
||||
mx[5] = mx[5] * v.y;
|
||||
mx[6] = mx[6] * v.y;
|
||||
mx[7] = mx[7] * v.y;
|
||||
mx[8] = mx[8] * v.z;
|
||||
mx[9] = mx[9] * v.z;
|
||||
mx[10] = mx[10] * v.z;
|
||||
mx[11] = mx[11] * v.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -355,13 +498,15 @@ export class Mat4 {
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
setPerspective(left, right, bottom, top, near, far) {
|
||||
var h = right - left, i = top - bottom, j = far - near;
|
||||
this._m[0] = near * 2 / h;
|
||||
var h = right - left,
|
||||
i = top - bottom,
|
||||
j = far - near;
|
||||
this._m[0] = (near * 2) / h;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
this._m[3] = 0;
|
||||
this._m[4] = 0;
|
||||
this._m[5] = near * 2 / i;
|
||||
this._m[5] = (near * 2) / i;
|
||||
this._m[6] = 0;
|
||||
this._m[7] = 0;
|
||||
this._m[8] = (right + left) / h;
|
||||
@ -387,7 +532,6 @@ export class Mat4 {
|
||||
* @return {Mat4} -
|
||||
*/
|
||||
setOrtho(left, right, bottom, top, near, far) {
|
||||
|
||||
var lr = 1.0 / (left - right),
|
||||
bt = 1.0 / (bottom - top),
|
||||
nf = 1.0 / (near - far),
|
||||
@ -455,5 +599,5 @@ export class Mat4 {
|
||||
* @returns {Mat4} -
|
||||
*/
|
||||
export function mat4() {
|
||||
return new og.Mat4();
|
||||
return new Mat4();
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import * as math from '../math.js';
|
||||
import { Mat3 } from './Mat3.js';
|
||||
import { Mat4 } from './Mat4.js';
|
||||
import { Vec3 } from './Vec3.js';
|
||||
import * as math from "../math.js";
|
||||
import { Mat3 } from "./Mat3.js";
|
||||
import { Mat4 } from "./Mat4.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
|
||||
/**
|
||||
* A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.
|
||||
@ -14,7 +14,6 @@ import { Vec3 } from './Vec3.js';
|
||||
* @param {Number} [w=0.0] The W component.
|
||||
*/
|
||||
export class Quat {
|
||||
|
||||
/**
|
||||
* @param {Number} [x=0.0] The X component.
|
||||
* @param {Number} [y=0.0] The Y component.
|
||||
@ -109,11 +108,7 @@ export class Quat {
|
||||
var v = axis.normal();
|
||||
var half_angle = angle * 0.5;
|
||||
var sin_a = Math.sin(half_angle);
|
||||
return new Quat(
|
||||
v.x * sin_a,
|
||||
v.y * sin_a,
|
||||
v.z * sin_a,
|
||||
Math.cos(half_angle));
|
||||
return new Quat(v.x * sin_a, v.y * sin_a, v.z * sin_a, Math.cos(half_angle));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,50 +119,29 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
static getLookRotation(forward, up) {
|
||||
|
||||
var f = forward.normal().negate();
|
||||
var s = (up.cross(f)).normalize();
|
||||
var s = up.cross(f).normalize();
|
||||
var u = f.cross(s);
|
||||
|
||||
var z = 1.0 + s.x + u.y + f.z;
|
||||
|
||||
if (z > 0.000001) {
|
||||
let fd = 1.0 / (2.0 * Math.sqrt(z));
|
||||
return new Quat(
|
||||
(f.y - u.z) * fd,
|
||||
(s.z - f.x) * fd,
|
||||
(u.x - s.y) * fd,
|
||||
0.25 / fd
|
||||
);
|
||||
return new Quat((f.y - u.z) * fd, (s.z - f.x) * fd, (u.x - s.y) * fd, 0.25 / fd);
|
||||
}
|
||||
|
||||
if (s.x > u.y && s.x > f.z) {
|
||||
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + s.x - u.y - f.z));
|
||||
return new Quat(
|
||||
0.25 / fd,
|
||||
(u.x + s.y) * fd,
|
||||
(s.z + f.x) * fd,
|
||||
(f.y - u.z) * fd
|
||||
);
|
||||
return new Quat(0.25 / fd, (u.x + s.y) * fd, (s.z + f.x) * fd, (f.y - u.z) * fd);
|
||||
}
|
||||
|
||||
if (u.y > f.z) {
|
||||
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + u.y - s.x - f.z));
|
||||
return new Quat(
|
||||
(u.x + s.y) * fd,
|
||||
0.25 / fd,
|
||||
(f.y + u.z) * fd,
|
||||
(s.z - f.x) * fd
|
||||
);
|
||||
return new Quat((u.x + s.y) * fd, 0.25 / fd, (f.y + u.z) * fd, (s.z - f.x) * fd);
|
||||
}
|
||||
|
||||
let fd = 1.0 / (2.0 * Math.sqrt(1.0 + f.z - s.x - u.y));
|
||||
return new Quat(
|
||||
(s.z + f.x) * fd,
|
||||
(f.y + u.z) * fd,
|
||||
0.25 / fd,
|
||||
(u.x - s.y) * fd
|
||||
);
|
||||
return new Quat((s.z + f.x) * fd, (f.y + u.z) * fd, 0.25 / fd, (u.x - s.y) * fd);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,10 +154,10 @@ export class Quat {
|
||||
static getLookAtSourceDest(sourcePoint, destPoint) {
|
||||
var forwardVector = destPoint.subA(sourcePoint).normalize();
|
||||
var dot = Vec3.FORWARD.dot(forwardVector);
|
||||
if (Math.abs(dot - (-1.0)) < 0.000001) {
|
||||
if (Math.abs(dot - -1.0) < 0.000001) {
|
||||
return Quat.axisAngleToQuat(Vec3.UP, Math.PI);
|
||||
}
|
||||
if (Math.abs(dot - (1.0)) < 0.000001) {
|
||||
if (Math.abs(dot - 1.0) < 0.000001) {
|
||||
return new Quat(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
var rotAngle = Math.acos(dot);
|
||||
@ -219,7 +193,7 @@ export class Quat {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute rotation between two vectors with around vector up
|
||||
* Compute rotation between two vectors with around vector up
|
||||
* for exactly opposite vectors. If vectors exaclty in the same
|
||||
* direction than returns identity Quat.
|
||||
* @static
|
||||
@ -231,7 +205,7 @@ export class Quat {
|
||||
static getRotationBetweenVectorsUp(source, dest, up) {
|
||||
var dot = source.dot(dest);
|
||||
if (Math.abs(dot + 1.0) < 0.000001) {
|
||||
// vector source and dest point exactly in the opposite direction,
|
||||
// vector source and dest point exactly in the opposite direction,
|
||||
// so it is a 180 degrees turn around the up-axis
|
||||
return Quat.axisAngleToQuat(up, Math.PI);
|
||||
}
|
||||
@ -244,7 +218,7 @@ export class Quat {
|
||||
var rotAxis = source.cross(dest).normalize();
|
||||
return Quat.axisAngleToQuat(rotAxis, rotAngle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the components are zero.
|
||||
* @public
|
||||
@ -355,7 +329,10 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
scale(scale) {
|
||||
this.x *= scale; this.y *= scale; this.z *= scale; this.w *= scale;
|
||||
this.x *= scale;
|
||||
this.y *= scale;
|
||||
this.z *= scale;
|
||||
this.w *= scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -398,9 +375,8 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setLookRotation(forward, up) {
|
||||
|
||||
var f = forward.normal().negate();
|
||||
var s = (up.cross(f)).normalize();
|
||||
var s = up.cross(f).normalize();
|
||||
var u = f.cross(s);
|
||||
|
||||
var z = 1.0 + s.x + u.y + f.z;
|
||||
@ -437,7 +413,7 @@ export class Quat {
|
||||
/**
|
||||
* Gets spherical coordinates.
|
||||
* @public
|
||||
* @returns {Object} Returns object with latitude, longitude and alpha.
|
||||
* @returns {Object} Returns object with latitude, longitude and alpha.
|
||||
*/
|
||||
toSphericalCoords() {
|
||||
var cos_a = this.w;
|
||||
@ -450,7 +426,8 @@ export class Quat {
|
||||
var ty = this.y / sin_a;
|
||||
var tz = this.z / sin_a;
|
||||
|
||||
var lon, lat = -Math.asin(ty);
|
||||
var lon,
|
||||
lat = -Math.asin(ty);
|
||||
if (tx * tx + tz * tz < 0.0005) {
|
||||
lon = 0;
|
||||
} else {
|
||||
@ -484,15 +461,19 @@ export class Quat {
|
||||
* @returns {Object} -
|
||||
*/
|
||||
getAxisAngle() {
|
||||
var vl = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
let x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
var vl = Math.sqrt(x * x + y * y + z * z);
|
||||
var axis, angle;
|
||||
if (vl > 0.0000001) {
|
||||
var ivl = 1.0 / vl;
|
||||
axis = new Vec3(x * ivl, y * ivl, z * ivl);
|
||||
if (this.w < 0) {
|
||||
angle = 2.0 * Math.atan2(-vl, -w); // -PI,0
|
||||
if (w < 0) {
|
||||
angle = 2.0 * Math.atan2(-vl, -w); // -PI,0
|
||||
} else {
|
||||
angle = 2.0 * Math.atan2(vl, w); // 0,PI
|
||||
angle = 2.0 * Math.atan2(vl, w); // 0,PI
|
||||
}
|
||||
} else {
|
||||
axis = new Vec3(0, 0, 0);
|
||||
@ -539,8 +520,10 @@ export class Quat {
|
||||
* @returns {Object} -
|
||||
*/
|
||||
getEulerAngles() {
|
||||
|
||||
let x = this.x, y = this.y, z = this.z, w = this.w;
|
||||
let x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
|
||||
let sqy = y * y;
|
||||
|
||||
@ -567,7 +550,9 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
setFromMatrix4(m) {
|
||||
var tr, s, q = [];
|
||||
var tr,
|
||||
s,
|
||||
q = [];
|
||||
var i, j, k;
|
||||
m = m._m;
|
||||
|
||||
@ -589,7 +574,7 @@ export class Quat {
|
||||
j = nxt[i];
|
||||
k = nxt[j];
|
||||
|
||||
s = Math.sqrt((m[i * 5] - (m[j * 5] + m[k * 5])) + 1.0);
|
||||
s = Math.sqrt(m[i * 5] - (m[j * 5] + m[k * 5]) + 1.0);
|
||||
|
||||
q[i] = s * 0.5;
|
||||
|
||||
@ -626,7 +611,24 @@ export class Quat {
|
||||
var yz = this.y * zs;
|
||||
var zz = this.z * zs;
|
||||
var m = out || new Mat4();
|
||||
return m.set([1 - (yy + zz), xy - wz, xz + wy, 0, xy + wz, 1 - (xx + zz), yz - wx, 0, xz - wy, yz + wx, 1 - (xx + yy), 0, 0, 0, 0, 1]);
|
||||
return m.set([
|
||||
1 - (yy + zz),
|
||||
xy - wz,
|
||||
xz + wy,
|
||||
0,
|
||||
xy + wz,
|
||||
1 - (xx + zz),
|
||||
yz - wx,
|
||||
0,
|
||||
xz - wy,
|
||||
yz + wx,
|
||||
1 - (xx + yy),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -658,9 +660,15 @@ export class Quat {
|
||||
h = g * h;
|
||||
g = g * i;
|
||||
|
||||
mx[0] = 1 - (l + e); mx[1] = k - g; mx[2] = c + h;
|
||||
mx[3] = k + g; mx[4] = 1 - (j + e); mx[5] = d - f;
|
||||
mx[6] = c - h; mx[7] = d + f; mx[8] = 1 - (j + l);
|
||||
mx[0] = 1 - (l + e);
|
||||
mx[1] = k - g;
|
||||
mx[2] = c + h;
|
||||
mx[3] = k + g;
|
||||
mx[4] = 1 - (j + e);
|
||||
mx[5] = d - f;
|
||||
mx[6] = c - h;
|
||||
mx[7] = d + f;
|
||||
mx[8] = 1 - (j + l);
|
||||
|
||||
return m;
|
||||
}
|
||||
@ -672,7 +680,6 @@ export class Quat {
|
||||
* @returns {Vec3} -
|
||||
*/
|
||||
mulVec3(v) {
|
||||
|
||||
// t = 2 * cross(q.xyz, v)
|
||||
// v' = v + q.w * t + cross(q.xyz, t)
|
||||
|
||||
@ -694,7 +701,8 @@ export class Quat {
|
||||
return new Vec3(
|
||||
i * a + d * -b + j * -h - k * -f,
|
||||
j * a + d * -f + k * -b - i * -h,
|
||||
k * a + d * -h + i * -f - j * -b);
|
||||
k * a + d * -h + i * -f - j * -b
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -704,13 +712,20 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
mul(q) {
|
||||
var d = this.x, e = this.y, g = this.z, a = this.w;
|
||||
var f = q.x, h = q.y, i = q.z, b = q.w;
|
||||
var d = this.x,
|
||||
e = this.y,
|
||||
g = this.z,
|
||||
a = this.w;
|
||||
var f = q.x,
|
||||
h = q.y,
|
||||
i = q.z,
|
||||
b = q.w;
|
||||
return new Quat(
|
||||
d * b + a * f + e * i - g * h,
|
||||
e * b + a * h + g * f - d * i,
|
||||
g * b + a * i + d * h - e * f,
|
||||
a * b - d * f - e * h - g * i);
|
||||
a * b - d * f - e * h - g * i
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -720,8 +735,14 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
mulA(q) {
|
||||
var d = this.x, e = this.y, g = this.z, a = this.w;
|
||||
var f = q.x, h = q.y, i = q.z, b = q.w;
|
||||
var d = this.x,
|
||||
e = this.y,
|
||||
g = this.z,
|
||||
a = this.w;
|
||||
var f = q.x,
|
||||
h = q.y,
|
||||
i = q.z,
|
||||
b = q.w;
|
||||
this.x = d * b + a * f + e * i - g * h;
|
||||
this.y = e * b + a * h + g * f - d * i;
|
||||
this.z = g * b + a * i + d * h - e * f;
|
||||
@ -738,7 +759,7 @@ export class Quat {
|
||||
return new Quat(-this.x, -this.y, -this.z, this.w);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Computes the inverse of the Quat.
|
||||
* @public
|
||||
* @returns {Quat} -
|
||||
@ -754,7 +775,10 @@ export class Quat {
|
||||
* @returns {number} -
|
||||
*/
|
||||
magnitude() {
|
||||
var b = this.x, c = this.y, d = this.z, a = this.w;
|
||||
var b = this.x,
|
||||
c = this.y,
|
||||
d = this.z,
|
||||
a = this.w;
|
||||
return Math.sqrt(b * b + c * c + d * d + a * a);
|
||||
}
|
||||
|
||||
@ -764,7 +788,10 @@ export class Quat {
|
||||
* @returns {number} -
|
||||
*/
|
||||
magnitude2() {
|
||||
var b = this.x, c = this.y, d = this.z, a = this.w;
|
||||
var b = this.x,
|
||||
c = this.y,
|
||||
d = this.z,
|
||||
a = this.w;
|
||||
return b * b + c * c + d * d + a * a;
|
||||
}
|
||||
|
||||
@ -784,7 +811,10 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
normalize() {
|
||||
var c = this.x, d = this.y, e = this.z, g = this.w,
|
||||
var c = this.x,
|
||||
d = this.y,
|
||||
e = this.z,
|
||||
g = this.w,
|
||||
f = Math.sqrt(c * c + d * d + e * e + g * g);
|
||||
if (f === 0.0) {
|
||||
this.x = 0;
|
||||
@ -823,9 +853,14 @@ export class Quat {
|
||||
* @returns {Quat} -
|
||||
*/
|
||||
slerp(b, t) {
|
||||
|
||||
var ax = this.x, ay = this.y, az = this.z, aw = this.w,
|
||||
bx = b.x, by = b.y, bz = b.z, bw = b.w;
|
||||
var ax = this.x,
|
||||
ay = this.y,
|
||||
az = this.z,
|
||||
aw = this.w,
|
||||
bx = b.x,
|
||||
by = b.y,
|
||||
bz = b.z,
|
||||
bw = b.w;
|
||||
|
||||
var omega, cosom, sinom, scale0, scale1;
|
||||
|
||||
@ -839,7 +874,7 @@ export class Quat {
|
||||
bw = -bw;
|
||||
}
|
||||
|
||||
if ((1.0 - cosom) > 0.000001) {
|
||||
if (1.0 - cosom > 0.000001) {
|
||||
omega = Math.acos(cosom);
|
||||
sinom = Math.sin(omega);
|
||||
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
||||
@ -864,7 +899,10 @@ export class Quat {
|
||||
* @returns {Number} -
|
||||
*/
|
||||
getRoll(reprojectAxis) {
|
||||
var x = this.x, y = this.y, z = this.z, w = this.w;
|
||||
var x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
if (reprojectAxis) {
|
||||
var fTy = 2.0 * y;
|
||||
var fTz = 2.0 * z;
|
||||
@ -885,7 +923,10 @@ export class Quat {
|
||||
* @returns {number} -
|
||||
*/
|
||||
getPitch(reprojectAxis) {
|
||||
var x = this.x, y = this.y, z = this.z, w = this.w;
|
||||
var x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
if (reprojectAxis) {
|
||||
var fTx = 2.0 * x;
|
||||
var fTz = 2.0 * z;
|
||||
@ -906,7 +947,10 @@ export class Quat {
|
||||
* @returns {number} -
|
||||
*/
|
||||
getYaw(reprojectAxis) {
|
||||
var x = this.x, y = this.y, z = this.z, w = this.w;
|
||||
var x = this.x,
|
||||
y = this.y,
|
||||
z = this.z,
|
||||
w = this.w;
|
||||
if (reprojectAxis) {
|
||||
var fTx = 2.0 * x;
|
||||
var fTy = 2.0 * y;
|
||||
@ -934,4 +978,3 @@ export class Quat {
|
||||
export function quat(x, y, z, w) {
|
||||
return new Quat(x, y, z, w);
|
||||
}
|
||||
|
||||
|
||||
@ -2,9 +2,10 @@
|
||||
* @module og/math/Vec4
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from './Vec3.js';
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
import { frac } from "../math.js";
|
||||
|
||||
/**
|
||||
* Class represents a 4d vector.
|
||||
@ -15,9 +16,7 @@ import { Vec3 } from './Vec3.js';
|
||||
* @param {number} [w] - Fourth value.
|
||||
*/
|
||||
export class Vec4 {
|
||||
|
||||
constructor(x, y, z, w) {
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {number}
|
||||
@ -46,15 +45,17 @@ export class Vec4 {
|
||||
/**
|
||||
* Identity vector [0,0,0,1].
|
||||
* @const
|
||||
* @type {math.Vec4}
|
||||
* @type {Vec4}
|
||||
*/
|
||||
static get identity() { return new Vec4(0, 0, 0, 1) }
|
||||
static get identity() {
|
||||
return new Vec4(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates 4d vector from array.
|
||||
* @function
|
||||
* @param {Array.<number>} - (exactly 4 entries)
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
static fromVec(arr) {
|
||||
return new Vec4(arr[0], arr[1], arr[2], arr[3]);
|
||||
@ -72,7 +73,7 @@ export class Vec4 {
|
||||
/**
|
||||
* Returns clone vector.
|
||||
* @public
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
clone(v) {
|
||||
return new Vec4(this.x, this.y, this.z, this.w);
|
||||
@ -81,7 +82,7 @@ export class Vec4 {
|
||||
/**
|
||||
* Compares with vector. Returns true if it equals another.
|
||||
* @public
|
||||
* @param {math.Vec4} p - Vector to compare.
|
||||
* @param {Vec4} p - Vector to compare.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equal(v) {
|
||||
@ -90,8 +91,8 @@ export class Vec4 {
|
||||
|
||||
/**
|
||||
* Copy input vector's values.
|
||||
* @param {math.Vec4} v - Vector to copy.
|
||||
* @returns {math.Vec4}
|
||||
* @param {Vec4} v - Vector to copy.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
copy(v) {
|
||||
this.x = v.x;
|
||||
@ -127,7 +128,7 @@ export class Vec4 {
|
||||
* @param {number} y - Value Y.
|
||||
* @param {number} z - Value Z.
|
||||
* @param {number} w - Value W.
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
set(x, y, z, w) {
|
||||
this.x = x;
|
||||
@ -140,8 +141,8 @@ export class Vec4 {
|
||||
/**
|
||||
* Adds vector to the current.
|
||||
* @public
|
||||
* @param {math.Vec4}
|
||||
* @returns {math.Vec4}
|
||||
* @param {Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
addA(v) {
|
||||
this.x += v.x;
|
||||
@ -154,8 +155,8 @@ export class Vec4 {
|
||||
/**
|
||||
* Subtract vector from the current.
|
||||
* @public
|
||||
* @param {math.Vec4} v - Subtract vector.
|
||||
* @returns {math.Vec4}
|
||||
* @param {Vec4} v - Subtract vector.
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
subA(v) {
|
||||
this.x -= v.x;
|
||||
@ -169,7 +170,7 @@ export class Vec4 {
|
||||
* Scale current vector.
|
||||
* @public
|
||||
* @param {number} scale - Scale value.
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
scale(scale) {
|
||||
this.x *= scale;
|
||||
@ -182,7 +183,7 @@ export class Vec4 {
|
||||
/**
|
||||
* Makes vector affinity. Thereby fourh component becomes to 1.0.
|
||||
* @public
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
affinity() {
|
||||
var iw = 1 / this.w;
|
||||
@ -206,7 +207,7 @@ export class Vec4 {
|
||||
/**
|
||||
* Vector's edge function that returns vector where each component is 0.0 if it's smaller then edge and otherwise 1.0.
|
||||
* @public
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
getStep(edge) {
|
||||
return new Vec4(
|
||||
@ -220,15 +221,10 @@ export class Vec4 {
|
||||
/**
|
||||
* The vector fract function returns the vector of fractional parts of each value, i.e. x minus floor(x).
|
||||
* @public
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
getFrac(v) {
|
||||
return new Vec4(
|
||||
og.math.frac(v.x),
|
||||
og.math.frac(v.y),
|
||||
og.math.frac(v.z),
|
||||
og.math.frac(v.w)
|
||||
);
|
||||
return new Vec4(frac(v.x), frac(v.y), frac(v.z), frac(v.w));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -258,8 +254,8 @@ export class Vec4 {
|
||||
* @param {number} [y] - Second value.
|
||||
* @param {number} [z] - Third value.
|
||||
* @param {number} [w] - Fourth value.
|
||||
* @returns {math.Vec4}
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
export function vec4(x, y, z, w) {
|
||||
return new og.math.Vec4(x, y, z, w);
|
||||
return new Vec4(x, y, z, w);
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import { Sphere } from "../bv/Sphere.js";
|
||||
import { Box } from "../bv/Box.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import * as segmentHelper from "../segment/segmentHelper.js";
|
||||
import { getMatrixSubArray } from "../utils/shared.js";
|
||||
|
||||
export const MAX_NORMAL_ZOOM = 7;
|
||||
|
||||
@ -376,8 +377,8 @@ class Segment {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {boolean} forceLoading
|
||||
*
|
||||
* @param {boolean} forceLoading
|
||||
*/
|
||||
loadTerrain(forceLoading) {
|
||||
if (this.tileZoom < this.planet.terrain.minZoom) {
|
||||
|
||||
@ -1,176 +0,0 @@
|
||||
/* eslint-disable no-mixed-operators */
|
||||
goog.provide('og.utils.getPolyCenter');
|
||||
|
||||
/*
|
||||
ISC License
|
||||
Copyright (c) 2016 Mapbox
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
with or without fee is hereby granted, provided that the above copyright notice
|
||||
and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
||||
OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
SOFTWARE.
|
||||
|
||||
https://github.com/mapbox/polylabel
|
||||
*/
|
||||
|
||||
og.utils.getPolyCenter = function (polygon) {
|
||||
|
||||
function polylabel(polygon, precision, debug) {
|
||||
precision = precision || 1.0;
|
||||
|
||||
// find the bounding box of the outer ring
|
||||
var minX, minY, maxX, maxY;
|
||||
for (var i = 0; i < polygon[0].length; i++) {
|
||||
var p = polygon[0][i];
|
||||
if (!i || p[0] < minX) minX = p[0];
|
||||
if (!i || p[1] < minY) minY = p[1];
|
||||
if (!i || p[0] > maxX) maxX = p[0];
|
||||
if (!i || p[1] > maxY) maxY = p[1];
|
||||
}
|
||||
|
||||
var width = maxX - minX;
|
||||
var height = maxY - minY;
|
||||
var cellSize = Math.min(width, height);
|
||||
var h = cellSize / 2;
|
||||
|
||||
// a priority queue of cells in order of their "potential" (max distance to polygon)
|
||||
var cellQueue = new Queue(null, compareMax);
|
||||
|
||||
if (cellSize === 0) return [minX, minY];
|
||||
|
||||
// cover polygon with initial cells
|
||||
for (var x = minX; x < maxX; x += cellSize) {
|
||||
for (var y = minY; y < maxY; y += cellSize) {
|
||||
cellQueue.push(new Cell(x + h, y + h, h, polygon));
|
||||
}
|
||||
}
|
||||
|
||||
// take centroid as the first best guess
|
||||
var bestCell = getCentroidCell(polygon);
|
||||
|
||||
// special case for rectangular polygons
|
||||
var bboxCell = new Cell(minX + width / 2, minY + height / 2, 0, polygon);
|
||||
if (bboxCell.d > bestCell.d) bestCell = bboxCell;
|
||||
|
||||
var numProbes = cellQueue.length;
|
||||
|
||||
while (cellQueue.length) {
|
||||
// pick the most promising cell from the queue
|
||||
var cell = cellQueue.pop();
|
||||
|
||||
// update the best cell if we found a better one
|
||||
if (cell.d > bestCell.d) {
|
||||
bestCell = cell;
|
||||
if (debug) console.log('found best %d after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
|
||||
}
|
||||
|
||||
// do not drill down further if there's no chance of a better solution
|
||||
if (cell.max - bestCell.d <= precision) continue;
|
||||
|
||||
// split the cell into four cells
|
||||
h = cell.h / 2;
|
||||
cellQueue.push(new Cell(cell.x - h, cell.y - h, h, polygon));
|
||||
cellQueue.push(new Cell(cell.x + h, cell.y - h, h, polygon));
|
||||
cellQueue.push(new Cell(cell.x - h, cell.y + h, h, polygon));
|
||||
cellQueue.push(new Cell(cell.x + h, cell.y + h, h, polygon));
|
||||
numProbes += 4;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
console.log('num probes: ' + numProbes);
|
||||
console.log('best distance: ' + bestCell.d);
|
||||
}
|
||||
|
||||
return [bestCell.x, bestCell.y];
|
||||
}
|
||||
|
||||
function compareMax(a, b) {
|
||||
return b.max - a.max;
|
||||
}
|
||||
|
||||
function Cell(x, y, h, polygon) {
|
||||
this.x = x; // cell center x
|
||||
this.y = y; // cell center y
|
||||
this.h = h; // half the cell size
|
||||
this.d = pointToPolygonDist(x, y, polygon); // distance from cell center to polygon
|
||||
this.max = this.d + this.h * Math.SQRT2; // max distance to polygon within a cell
|
||||
}
|
||||
|
||||
// signed distance from point to polygon outline (negative if point is outside)
|
||||
function pointToPolygonDist(x, y, polygon) {
|
||||
var inside = false;
|
||||
var minDistSq = Infinity;
|
||||
|
||||
for (var k = 0; k < polygon.length; k++) {
|
||||
var ring = polygon[k];
|
||||
|
||||
for (var i = 0, len = ring.length, j = len - 1; i < len; j = i++) {
|
||||
var a = ring[i];
|
||||
var b = ring[j];
|
||||
|
||||
if ((a[1] > y !== b[1] > y) &&
|
||||
(x < (b[0] - a[0]) * (y - a[1]) / (b[1] - a[1]) + a[0])) inside = !inside;
|
||||
|
||||
minDistSq = Math.min(minDistSq, getSegDistSq(x, y, a, b));
|
||||
}
|
||||
}
|
||||
|
||||
return (inside ? 1 : -1) * Math.sqrt(minDistSq);
|
||||
}
|
||||
|
||||
// get polygon centroid
|
||||
function getCentroidCell(polygon) {
|
||||
var area = 0;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var points = polygon[0];
|
||||
|
||||
for (var i = 0, len = points.length, j = len - 1; i < len; j = i++) {
|
||||
var a = points[i];
|
||||
var b = points[j];
|
||||
var f = a[0] * b[1] - b[0] * a[1];
|
||||
x += (a[0] + b[0]) * f;
|
||||
y += (a[1] + b[1]) * f;
|
||||
area += f * 3;
|
||||
}
|
||||
if (area === 0) return new Cell(points[0][0], points[0][1], 0, polygon);
|
||||
return new Cell(x / area, y / area, 0, polygon);
|
||||
}
|
||||
|
||||
// get squared distance from a point to a segment
|
||||
function getSegDistSq(px, py, a, b) {
|
||||
|
||||
var x = a[0];
|
||||
var y = a[1];
|
||||
var dx = b[0] - x;
|
||||
var dy = b[1] - y;
|
||||
|
||||
if (dx !== 0 || dy !== 0) {
|
||||
|
||||
var t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
|
||||
|
||||
if (t > 1) {
|
||||
x = b[0];
|
||||
y = b[1];
|
||||
|
||||
} else if (t > 0) {
|
||||
x += dx * t;
|
||||
y += dy * t;
|
||||
}
|
||||
}
|
||||
|
||||
dx = px - x;
|
||||
dy = py - y;
|
||||
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
return polylabel(polygon, 1);
|
||||
};
|
||||
@ -2,9 +2,9 @@
|
||||
* @module og/webgl/Framebuffer
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import { ImageCanvas } from '../ImageCanvas.js';
|
||||
import { ImageCanvas } from "../ImageCanvas.js";
|
||||
|
||||
/**
|
||||
* Class represents framebuffer.
|
||||
@ -21,9 +21,7 @@ import { ImageCanvas } from '../ImageCanvas.js';
|
||||
* @param {Boolean} [options.useDepth] - Using depth buffer during the rendering.
|
||||
*/
|
||||
export class Framebuffer {
|
||||
|
||||
constructor(handler, options = {}) {
|
||||
|
||||
/**
|
||||
* WebGL handler.
|
||||
* @public
|
||||
@ -49,20 +47,27 @@ export class Framebuffer {
|
||||
|
||||
this._filter = options.filter || "NEAREST";
|
||||
|
||||
this._internalFormatArr = options.internalFormat instanceof Array ? options.internalFormat : [options.internalFormat || "RGBA"];
|
||||
this._internalFormatArr =
|
||||
options.internalFormat instanceof Array
|
||||
? options.internalFormat
|
||||
: [options.internalFormat || "RGBA"];
|
||||
|
||||
this._formatArr = options.format instanceof Array ? options.format : [options.format || "RGBA"];
|
||||
this._formatArr =
|
||||
options.format instanceof Array ? options.format : [options.format || "RGBA"];
|
||||
|
||||
this._typeArr = options.type instanceof Array ? options.type : [options.type || "UNSIGNED_BYTE"];
|
||||
this._typeArr =
|
||||
options.type instanceof Array ? options.type : [options.type || "UNSIGNED_BYTE"];
|
||||
|
||||
this._attachmentArr = options.attachment instanceof Array ?
|
||||
options.attachment.map((a, i) => {
|
||||
let res = a.toUpperCase();
|
||||
if (res === "COLOR_ATTACHMENT") {
|
||||
return `${res}${i.toString()}`;
|
||||
}
|
||||
return res;
|
||||
}) : [options.attachment || "COLOR_ATTACHMENT0"];
|
||||
this._attachmentArr =
|
||||
options.attachment instanceof Array
|
||||
? options.attachment.map((a, i) => {
|
||||
let res = a.toUpperCase();
|
||||
if (res === "COLOR_ATTACHMENT") {
|
||||
return `${res}${i.toString()}`;
|
||||
}
|
||||
return res;
|
||||
})
|
||||
: [options.attachment || "COLOR_ATTACHMENT0"];
|
||||
|
||||
/**
|
||||
* Framebuffer width.
|
||||
@ -78,12 +83,13 @@ export class Framebuffer {
|
||||
*/
|
||||
this._height = options.height || handler.canvas.height;
|
||||
|
||||
this._depthComponent = options.depthComponent != undefined ? options.depthComponent : "DEPTH_COMPONENT16";
|
||||
this._depthComponent =
|
||||
options.depthComponent != undefined ? options.depthComponent : "DEPTH_COMPONENT16";
|
||||
|
||||
this._useDepth = options.useDepth != undefined ? options.useDepth : true;
|
||||
|
||||
/**
|
||||
* Framebuffer activity.
|
||||
* Framebuffer activity.
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
@ -100,19 +106,25 @@ export class Framebuffer {
|
||||
}
|
||||
|
||||
static blit(sourceFramebuffer, destFramebuffer, glAttachment, glMask, glFilter) {
|
||||
|
||||
let gl = sourceFramebuffer.handler.gl;
|
||||
|
||||
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, sourceFramebuffer._fbo);
|
||||
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, framebuffer._fbo);
|
||||
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, destFramebuffer._fbo);
|
||||
gl.readBuffer(glAttachment);
|
||||
|
||||
gl.clearBufferfv(gl.COLOR, 0, [0.0, 0.0, 0.0, 1.0]);
|
||||
|
||||
gl.blitFramebuffer(
|
||||
0, 0, sourceFramebuffer._width, sourceFramebuffer._height,
|
||||
0, 0, destFramebuffer._width, destFramebuffer._height,
|
||||
glMask, glFilter
|
||||
0,
|
||||
0,
|
||||
sourceFramebuffer._width,
|
||||
sourceFramebuffer._height,
|
||||
0,
|
||||
0,
|
||||
destFramebuffer._width,
|
||||
destFramebuffer._height,
|
||||
glMask,
|
||||
glFilter
|
||||
);
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
@ -151,8 +163,8 @@ export class Framebuffer {
|
||||
if (!this._isBare) {
|
||||
let attachmentArr = [];
|
||||
for (var i = 0; i < this.textures.length; i++) {
|
||||
|
||||
let ti = this.textures[i] ||
|
||||
let ti =
|
||||
this.textures[i] ||
|
||||
this.handler.createEmptyTexture2DExt(
|
||||
this._width,
|
||||
this._height,
|
||||
@ -178,8 +190,18 @@ export class Framebuffer {
|
||||
if (this._useDepth) {
|
||||
this._depthRenderbuffer = gl.createRenderbuffer();
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderbuffer);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, gl[this._depthComponent], this._width, this._height);
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._depthRenderbuffer);
|
||||
gl.renderbufferStorage(
|
||||
gl.RENDERBUFFER,
|
||||
gl[this._depthComponent],
|
||||
this._width,
|
||||
this._height
|
||||
);
|
||||
gl.framebufferRenderbuffer(
|
||||
gl.FRAMEBUFFER,
|
||||
gl.DEPTH_ATTACHMENT,
|
||||
gl.RENDERBUFFER,
|
||||
this._depthRenderbuffer
|
||||
);
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
}
|
||||
|
||||
@ -197,7 +219,13 @@ export class Framebuffer {
|
||||
bindOutputTexture(texture, glAttachment) {
|
||||
var gl = this.handler.gl;
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, glAttachment || gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
||||
gl.framebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
glAttachment || gl.COLOR_ATTACHMENT0,
|
||||
gl.TEXTURE_2D,
|
||||
texture,
|
||||
0
|
||||
);
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
}
|
||||
|
||||
@ -248,7 +276,15 @@ export class Framebuffer {
|
||||
var gl = this.handler.gl;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fbo);
|
||||
gl.readBuffer && gl.readBuffer(gl.COLOR_ATTACHMENT0 + index || 0);
|
||||
gl.readPixels(nx * this._width, ny * this._height, w, h, gl.RGBA, gl[this._typeArr[index]], res);
|
||||
gl.readPixels(
|
||||
nx * this._width,
|
||||
ny * this._height,
|
||||
w,
|
||||
h,
|
||||
gl.RGBA,
|
||||
gl[this._typeArr[index]],
|
||||
res
|
||||
);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
}
|
||||
|
||||
@ -262,7 +298,15 @@ export class Framebuffer {
|
||||
var gl = this.handler.gl;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fbo);
|
||||
gl.readBuffer && gl.readBuffer(gl.COLOR_ATTACHMENT0 + attachmentIndex);
|
||||
gl.readPixels(0, 0, this._width, this._height, gl.RGBA, gl[this._typeArr[attachmentIndex]], res);
|
||||
gl.readPixels(
|
||||
0,
|
||||
0,
|
||||
this._width,
|
||||
this._height,
|
||||
gl.RGBA,
|
||||
gl[this._typeArr[attachmentIndex]],
|
||||
res
|
||||
);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
}
|
||||
|
||||
@ -323,17 +367,21 @@ export class Framebuffer {
|
||||
openImage() {
|
||||
var img = this.getImage();
|
||||
var dataUrl = img.src;
|
||||
var windowContent = '<!DOCTYPE html>';
|
||||
windowContent += '<html>';
|
||||
windowContent += '<head><title>Print</title></head>';
|
||||
windowContent += '<body>';
|
||||
var windowContent = "<!DOCTYPE html>";
|
||||
windowContent += "<html>";
|
||||
windowContent += "<head><title>Print</title></head>";
|
||||
windowContent += "<body>";
|
||||
windowContent += '<img src="' + dataUrl + '">';
|
||||
windowContent += '</body>';
|
||||
windowContent += '</html>';
|
||||
var printWin = window.open('', '', 'width=' + img.width + 'px ,height=' + img.height + 'px');
|
||||
windowContent += "</body>";
|
||||
windowContent += "</html>";
|
||||
var printWin = window.open(
|
||||
"",
|
||||
"",
|
||||
"width=" + img.width + "px ,height=" + img.height + "px"
|
||||
);
|
||||
printWin.document.open();
|
||||
printWin.document.write(windowContent);
|
||||
printWin.document.close();
|
||||
printWin.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,23 +1,21 @@
|
||||
import { Handler } from "./Handler";
|
||||
import { Program } from "./Program";
|
||||
import { Handler } from "./Handler.js";
|
||||
import { Program } from "./Program.js";
|
||||
|
||||
'use strict';
|
||||
("use strict");
|
||||
|
||||
/**
|
||||
* This is shader program controller that used by hadler object to access the shader
|
||||
* This is shader program controller that used by hadler object to access the shader
|
||||
* program capabilities, like switching program during the rendering.
|
||||
* Get access to the program from ...handler.programs.<program name> etc.
|
||||
* @class
|
||||
*/
|
||||
export class ProgramController {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Handler} handler - Handler.
|
||||
* @param {Program} program - Shader program.
|
||||
*/
|
||||
constructor(handler, program) {
|
||||
|
||||
/**
|
||||
* Shader program.
|
||||
* @private
|
||||
@ -142,4 +140,4 @@ export class ProgramController {
|
||||
this._program.drawArrays(mode, numItems);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,16 +2,16 @@
|
||||
* @module og/webgl/callbacks
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import { types } from './types.js';
|
||||
import { types } from "./types.js";
|
||||
|
||||
/*=========================
|
||||
Uniforms callbacks
|
||||
=========================*/
|
||||
export const callbacks = {
|
||||
'u': [],
|
||||
'a': []
|
||||
u: [],
|
||||
a: []
|
||||
};
|
||||
|
||||
callbacks.u[types.MAT4] = function (program, variable) {
|
||||
@ -71,7 +71,7 @@ callbacks.u[types.SAMPLER2DARRAY] = function (program, variable) {
|
||||
};
|
||||
|
||||
callbacks.u[types.INTXX] = function (program, variable) {
|
||||
pgl.uniform1iv(variable._pName, variable.value);
|
||||
program.gl.uniform1iv(variable._pName, variable.value);
|
||||
};
|
||||
|
||||
callbacks.u[types.FLOATXX] = function (program, variable) {
|
||||
@ -95,4 +95,4 @@ callbacks.a[types.VEC3] = function (program, variable) {
|
||||
|
||||
callbacks.a[types.VEC4] = function (program, variable) {
|
||||
program.gl.vertexAttrib4fv(variable._pName, variable.value);
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user