mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
#706 docs cleanup
This commit is contained in:
parent
8f0b76641e
commit
36862fee55
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ Release
|
||||
Debug
|
||||
eslint
|
||||
node_modules
|
||||
docs
|
||||
.eslintrc
|
||||
.csslintrc
|
||||
.idea
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/Clock
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as jd from "./astro/jd.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/Events
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { binaryInsert, stamp } from "./utils/shared.js";
|
||||
|
||||
708
src/og/Extent.js
708
src/og/Extent.js
@ -1,356 +1,352 @@
|
||||
/**
|
||||
* @module og/Extent
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { LonLat } from "./LonLat.js";
|
||||
import * as math from "./math.js";
|
||||
import * as mercator from "./mercator.js";
|
||||
|
||||
/**
|
||||
* Represents geographical coordinates extent.
|
||||
* @class
|
||||
* @param {LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {LonLat} [ne] - North East extent corner coordiantes.
|
||||
*/
|
||||
export class Extent {
|
||||
/**
|
||||
* @param {LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {LonLat} [ne] - North East extent corner coordiantes.
|
||||
*/
|
||||
constructor(sw = new LonLat(), ne = new LonLat()) {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
this.southWest = sw;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
this.northEast = ne;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whole mercator extent.
|
||||
* @const
|
||||
*/
|
||||
static get FULL_MERC() {
|
||||
return new Extent(LonLat.SW_MERC, LonLat.NE_MERC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Degrees extent from north mercator limit to north pole.
|
||||
* @const
|
||||
*/
|
||||
static get NORTH_POLE_DEG() {
|
||||
return new Extent(LonLat.NW_MERC_DEG, new LonLat(180.0, 90.0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Degrees extent from south pole to south mercator limit.
|
||||
* @const
|
||||
*/
|
||||
static get SOUTH_POLE_DEG() {
|
||||
return new Extent(new LonLat(-180.0, -90.0), LonLat.SE_MERC_DEG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent instance from values in array.
|
||||
* @static
|
||||
* @param {Array.<number>} arr - South west and north east longitude and latidudes packed in array. (exactly 4 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createFromArray(arr) {
|
||||
return new Extent(new LonLat(arr[0], arr[1]), new LonLat(arr[2], arr[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinates(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {Array.<Array<number>>} arr - Coordinate array. (exactly 2 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinatesArr(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi[0] < lonmin) lonmin = vi[0];
|
||||
if (vi[0] > lonmax) lonmax = vi[0];
|
||||
if (vi[1] < latmin) latmin = vi[1];
|
||||
if (vi[1] > latmax) latmax = vi[1];
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent by meractor grid tile coordinates.
|
||||
* @static
|
||||
* @param {number} x -
|
||||
* @param {number} y -
|
||||
* @param {number} z -
|
||||
* @param {number} width -
|
||||
* @param {number} height -
|
||||
* @returns {Extent} -
|
||||
*/
|
||||
static fromTile(x, y, z, width, height) {
|
||||
width = width || mercator.POLE_DOUBLE;
|
||||
height = height || mercator.POLE_DOUBLE;
|
||||
const H = Math.pow(2, z),
|
||||
W = Math.pow(2, z),
|
||||
lnSize = width / W,
|
||||
ltSize = height / H;
|
||||
|
||||
const left = -width * 0.5 + x * lnSize,
|
||||
top = height * 0.5 - y * ltSize,
|
||||
bottom = top - ltSize,
|
||||
right = left + lnSize;
|
||||
|
||||
return new Extent(new LonLat(left, bottom), new LonLat(right, top));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current bounding extent object by coordinate array.
|
||||
* @public
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Current extent.
|
||||
*/
|
||||
setByCoordinates(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
this.southWest.lon = lonmin;
|
||||
this.southWest.lat = latmin;
|
||||
this.northEast.lon = lonmax;
|
||||
this.northEast.lat = latmax;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if point inside extent.
|
||||
* @public
|
||||
* @param {LonLat} lonlat - Coordinate point.
|
||||
* @return {boolean} Returns true if point inside extent.
|
||||
*/
|
||||
isInside(lonlat) {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return (
|
||||
lonlat.lon >= sw.lon &&
|
||||
lonlat.lon <= ne.lon &&
|
||||
lonlat.lat >= sw.lat &&
|
||||
lonlat.lat <= ne.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if two extent overlap each other.
|
||||
* @public
|
||||
* @param {Extent} e - Another extent.
|
||||
* @return {boolean} -
|
||||
*/
|
||||
overlaps(e) {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return (
|
||||
sw.lon <= e.northEast.lon &&
|
||||
ne.lon >= e.southWest.lon &&
|
||||
sw.lat <= e.northEast.lat &&
|
||||
ne.lat >= e.southWest.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent width.
|
||||
* @public
|
||||
* @return {number} Extent width.
|
||||
*/
|
||||
getWidth() {
|
||||
return this.northEast.lon - this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent height.
|
||||
* @public
|
||||
* @return {number} Extent height.
|
||||
*/
|
||||
getHeight() {
|
||||
return this.northEast.lat - this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates clone instance of the current extent.
|
||||
* @public
|
||||
* @return {Extent} Extent clone.
|
||||
*/
|
||||
clone() {
|
||||
return new Extent(this.southWest.clone(), this.northEast.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the center coordinate of the extent.
|
||||
* @public
|
||||
* @return {number} Center coordinate.
|
||||
*/
|
||||
getCenter() {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return new LonLat(sw.lon + (ne.lon - sw.lon) * 0.5, sw.lat + (ne.lat - sw.lat) * 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorthWest() {
|
||||
return new LonLat(this.southWest.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorthEast() {
|
||||
return new LonLat(this.northEast.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
getSouthWest() {
|
||||
return new LonLat(this.southWest.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getSouthEast() {
|
||||
return new LonLat(this.northEast.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorth() {
|
||||
return this.northEast.lat;
|
||||
}
|
||||
|
||||
getEast() {
|
||||
return this.northEast.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getWest() {
|
||||
return this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getSouth() {
|
||||
return this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extents are equals.
|
||||
* @param {Extent} extent - Extent.
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
equals(extent) {
|
||||
return (
|
||||
this.southWest.lon === extent.southWest.lon &&
|
||||
this.southWest.lat === extent.southWest.lat &&
|
||||
this.northEast.lon === extent.northEast.lon &&
|
||||
this.northEast.lat === extent.northEast.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates to mercator projection coordinates.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
forwardMercator() {
|
||||
return new Extent(this.southWest.forwardMercator(), this.northEast.forwardMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates from mercator projection to degrees.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
inverseMercator() {
|
||||
return new Extent(this.southWest.inverseMercator(), this.northEast.inverseMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cartesian bounding bounds of the current ellipsoid.
|
||||
* @public
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @return {Array.<number>} Cartesian 3d coordinate array. (exactly 6 entries)
|
||||
*/
|
||||
getCartesianBounds(ellipsoid) {
|
||||
let xmin = math.MAX,
|
||||
xmax = math.MIN,
|
||||
ymin = math.MAX,
|
||||
ymax = math.MIN,
|
||||
zmin = math.MAX,
|
||||
zmax = math.MIN;
|
||||
|
||||
const v = [
|
||||
new LonLat(this.southWest.lon, this.southWest.lat),
|
||||
new LonLat(this.southWest.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.southWest.lat)
|
||||
];
|
||||
|
||||
for (let i = 0; i < v.length; i++) {
|
||||
const coord = ellipsoid.lonLatToCartesian(v[i]);
|
||||
const x = coord.x,
|
||||
y = coord.y,
|
||||
z = coord.z;
|
||||
if (x < xmin) xmin = x;
|
||||
if (x > xmax) xmax = x;
|
||||
if (y < ymin) ymin = y;
|
||||
if (y > ymax) ymax = y;
|
||||
if (z < zmin) zmin = z;
|
||||
if (z > zmax) zmax = z;
|
||||
}
|
||||
|
||||
return [xmin, ymin, zmin, xmax, ymax, zmax];
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (
|
||||
`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`
|
||||
);
|
||||
}
|
||||
}
|
||||
"use strict";
|
||||
|
||||
import { LonLat } from "./LonLat.js";
|
||||
import * as math from "./math.js";
|
||||
import * as mercator from "./mercator.js";
|
||||
|
||||
/**
|
||||
* Represents geographical coordinates extent.
|
||||
* @class
|
||||
* @param {LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {LonLat} [ne] - North East extent corner coordiantes.
|
||||
*/
|
||||
export class Extent {
|
||||
/**
|
||||
* @param {LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {LonLat} [ne] - North East extent corner coordiantes.
|
||||
*/
|
||||
constructor(sw = new LonLat(), ne = new LonLat()) {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
this.southWest = sw;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
this.northEast = ne;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whole mercator extent.
|
||||
* @const
|
||||
*/
|
||||
static get FULL_MERC() {
|
||||
return new Extent(LonLat.SW_MERC, LonLat.NE_MERC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Degrees extent from north mercator limit to north pole.
|
||||
* @const
|
||||
*/
|
||||
static get NORTH_POLE_DEG() {
|
||||
return new Extent(LonLat.NW_MERC_DEG, new LonLat(180.0, 90.0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Degrees extent from south pole to south mercator limit.
|
||||
* @const
|
||||
*/
|
||||
static get SOUTH_POLE_DEG() {
|
||||
return new Extent(new LonLat(-180.0, -90.0), LonLat.SE_MERC_DEG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent instance from values in array.
|
||||
* @static
|
||||
* @param {Array.<number>} arr - South west and north east longitude and latidudes packed in array. (exactly 4 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createFromArray(arr) {
|
||||
return new Extent(new LonLat(arr[0], arr[1]), new LonLat(arr[2], arr[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinates(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {Array.<Array<number>>} arr - Coordinate array. (exactly 2 entries)
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinatesArr(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi[0] < lonmin) lonmin = vi[0];
|
||||
if (vi[0] > lonmax) lonmax = vi[0];
|
||||
if (vi[1] < latmin) latmin = vi[1];
|
||||
if (vi[1] > latmax) latmax = vi[1];
|
||||
}
|
||||
return new Extent(new LonLat(lonmin, latmin), new LonLat(lonmax, latmax));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates extent by meractor grid tile coordinates.
|
||||
* @static
|
||||
* @param {number} x -
|
||||
* @param {number} y -
|
||||
* @param {number} z -
|
||||
* @param {number} width -
|
||||
* @param {number} height -
|
||||
* @returns {Extent} -
|
||||
*/
|
||||
static fromTile(x, y, z, width, height) {
|
||||
width = width || mercator.POLE_DOUBLE;
|
||||
height = height || mercator.POLE_DOUBLE;
|
||||
const H = Math.pow(2, z),
|
||||
W = Math.pow(2, z),
|
||||
lnSize = width / W,
|
||||
ltSize = height / H;
|
||||
|
||||
const left = -width * 0.5 + x * lnSize,
|
||||
top = height * 0.5 - y * ltSize,
|
||||
bottom = top - ltSize,
|
||||
right = left + lnSize;
|
||||
|
||||
return new Extent(new LonLat(left, bottom), new LonLat(right, top));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current bounding extent object by coordinate array.
|
||||
* @public
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Current extent.
|
||||
*/
|
||||
setByCoordinates(arr) {
|
||||
let lonmin = math.MAX,
|
||||
lonmax = math.MIN,
|
||||
latmin = math.MAX,
|
||||
latmax = math.MIN;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const vi = arr[i];
|
||||
if (vi.lon < lonmin) lonmin = vi.lon;
|
||||
if (vi.lon > lonmax) lonmax = vi.lon;
|
||||
if (vi.lat < latmin) latmin = vi.lat;
|
||||
if (vi.lat > latmax) latmax = vi.lat;
|
||||
}
|
||||
this.southWest.lon = lonmin;
|
||||
this.southWest.lat = latmin;
|
||||
this.northEast.lon = lonmax;
|
||||
this.northEast.lat = latmax;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if point inside extent.
|
||||
* @public
|
||||
* @param {LonLat} lonlat - Coordinate point.
|
||||
* @return {boolean} Returns true if point inside extent.
|
||||
*/
|
||||
isInside(lonlat) {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return (
|
||||
lonlat.lon >= sw.lon &&
|
||||
lonlat.lon <= ne.lon &&
|
||||
lonlat.lat >= sw.lat &&
|
||||
lonlat.lat <= ne.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if two extent overlap each other.
|
||||
* @public
|
||||
* @param {Extent} e - Another extent.
|
||||
* @return {boolean} -
|
||||
*/
|
||||
overlaps(e) {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return (
|
||||
sw.lon <= e.northEast.lon &&
|
||||
ne.lon >= e.southWest.lon &&
|
||||
sw.lat <= e.northEast.lat &&
|
||||
ne.lat >= e.southWest.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent width.
|
||||
* @public
|
||||
* @return {number} Extent width.
|
||||
*/
|
||||
getWidth() {
|
||||
return this.northEast.lon - this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extent height.
|
||||
* @public
|
||||
* @return {number} Extent height.
|
||||
*/
|
||||
getHeight() {
|
||||
return this.northEast.lat - this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates clone instance of the current extent.
|
||||
* @public
|
||||
* @return {Extent} Extent clone.
|
||||
*/
|
||||
clone() {
|
||||
return new Extent(this.southWest.clone(), this.northEast.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the center coordinate of the extent.
|
||||
* @public
|
||||
* @return {number} Center coordinate.
|
||||
*/
|
||||
getCenter() {
|
||||
const sw = this.southWest,
|
||||
ne = this.northEast;
|
||||
return new LonLat(sw.lon + (ne.lon - sw.lon) * 0.5, sw.lat + (ne.lat - sw.lat) * 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorthWest() {
|
||||
return new LonLat(this.southWest.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorthEast() {
|
||||
return new LonLat(this.northEast.lon, this.northEast.lat);
|
||||
}
|
||||
|
||||
getSouthWest() {
|
||||
return new LonLat(this.southWest.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getSouthEast() {
|
||||
return new LonLat(this.northEast.lon, this.southWest.lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getNorth() {
|
||||
return this.northEast.lat;
|
||||
}
|
||||
|
||||
getEast() {
|
||||
return this.northEast.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getWest() {
|
||||
return this.southWest.lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
getSouth() {
|
||||
return this.southWest.lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extents are equals.
|
||||
* @param {Extent} extent - Extent.
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
equals(extent) {
|
||||
return (
|
||||
this.southWest.lon === extent.southWest.lon &&
|
||||
this.southWest.lat === extent.southWest.lat &&
|
||||
this.northEast.lon === extent.northEast.lon &&
|
||||
this.northEast.lat === extent.northEast.lat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates to mercator projection coordinates.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
forwardMercator() {
|
||||
return new Extent(this.southWest.forwardMercator(), this.northEast.forwardMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts extent coordinates from mercator projection to degrees.
|
||||
* @public
|
||||
* @return {Extent} New instance of the current extent.
|
||||
*/
|
||||
inverseMercator() {
|
||||
return new Extent(this.southWest.inverseMercator(), this.northEast.inverseMercator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cartesian bounding bounds of the current ellipsoid.
|
||||
* @public
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @return {Array.<number>} Cartesian 3d coordinate array. (exactly 6 entries)
|
||||
*/
|
||||
getCartesianBounds(ellipsoid) {
|
||||
let xmin = math.MAX,
|
||||
xmax = math.MIN,
|
||||
ymin = math.MAX,
|
||||
ymax = math.MIN,
|
||||
zmin = math.MAX,
|
||||
zmax = math.MIN;
|
||||
|
||||
const v = [
|
||||
new LonLat(this.southWest.lon, this.southWest.lat),
|
||||
new LonLat(this.southWest.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.northEast.lat),
|
||||
new LonLat(this.northEast.lon, this.southWest.lat)
|
||||
];
|
||||
|
||||
for (let i = 0; i < v.length; i++) {
|
||||
const coord = ellipsoid.lonLatToCartesian(v[i]);
|
||||
const x = coord.x,
|
||||
y = coord.y,
|
||||
z = coord.z;
|
||||
if (x < xmin) xmin = x;
|
||||
if (x > xmax) xmax = x;
|
||||
if (y < ymin) ymin = y;
|
||||
if (y > ymax) ymax = y;
|
||||
if (z < zmin) zmin = z;
|
||||
if (z > zmax) zmax = z;
|
||||
}
|
||||
|
||||
return [xmin, ymin, zmin, xmax, ymax, zmax];
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (
|
||||
`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// StandWithUkraine
|
||||
// #StandWithUkraine
|
||||
|
||||
/**
|
||||
* @module og/Globe
|
||||
|
||||
@ -1,229 +1,225 @@
|
||||
/**
|
||||
* @module og/ImageCanvas
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Usefull class for working with JS canvas object.
|
||||
* @class
|
||||
*/
|
||||
class ImageCanvas {
|
||||
/**
|
||||
* @param {number} [width] - Canvas width. Default 256.
|
||||
* @param {number} [height] - Canvas height. Default 256.
|
||||
*/
|
||||
constructor(width = 256, height = 256) {
|
||||
/**
|
||||
* Canvas object.
|
||||
* @protected
|
||||
* @type {Object}
|
||||
*/
|
||||
this._canvas = document.createElement("canvas");
|
||||
this._canvas.width = width;
|
||||
this._canvas.height = height;
|
||||
|
||||
/**
|
||||
* Canvas context.
|
||||
* @protected
|
||||
* @type {Object}
|
||||
*/
|
||||
this._context = this._canvas.getContext("2d");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns canvas object.
|
||||
* @public
|
||||
* @returns {Object}
|
||||
*/
|
||||
getCanvas() {
|
||||
return this._canvas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns canvas context pointer.
|
||||
* @public
|
||||
* @returns {Object}
|
||||
*/
|
||||
getContext() {
|
||||
return this._context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills canvas RGBA with zeroes.
|
||||
* @public
|
||||
*/
|
||||
fillEmpty() {
|
||||
var imgd = this._context.getImageData(0, 0, this._canvas.width, this._canvas.height);
|
||||
var pixels = imgd.data;
|
||||
for (var i = 0, n = pixels.length; i < n; i += 4) {
|
||||
pixels[i] = pixels[i + 1] = pixels[i + 2] = pixels[i + 3] = 0;
|
||||
}
|
||||
this._context.putImageData(imgd, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets canvas pixels RGBA data.
|
||||
* @public
|
||||
* @returns {Array.<number>}
|
||||
*/
|
||||
getData() {
|
||||
var imgd = this._context.getImageData(0, 0, this._canvas.width, this._canvas.height);
|
||||
return imgd.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the canvas by color.
|
||||
* @public
|
||||
* @param {string} color - CSS string color.
|
||||
*/
|
||||
fillColor(color) {
|
||||
this._context.fillStyle = color;
|
||||
this._context.fillRect(0, 0, this._canvas.width, this._canvas.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets RGBA pixel data.
|
||||
* @public
|
||||
* @param {Array.<number>} data - Array RGBA data.
|
||||
*/
|
||||
setData(data) {
|
||||
var imageData = this._context.createImageData(this._canvas.width, this._canvas.height);
|
||||
imageData.data.set(data);
|
||||
this._context.putImageData(imageData, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize canvas.
|
||||
* @public
|
||||
* @param {number} width - Width.
|
||||
* @param {number} height - Height.
|
||||
*/
|
||||
resize(width, height) {
|
||||
this._canvas.width = width;
|
||||
this._canvas.height = height;
|
||||
this._context = this._canvas.getContext("2d");
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an image on the canvas.
|
||||
* @public
|
||||
* @param {Image} img - Draw image.
|
||||
* @param {number} [x] - Left top image corner X coordinate on the canvas.
|
||||
* @param {number} [y] - Left top image corner Y coordinate on the canvas.
|
||||
* @param {number} [width] - Image width slice. Image width is default.
|
||||
* @param {number} [height] - Image height slice. Image height is default.
|
||||
*/
|
||||
drawImage(img, x, y, width, height) {
|
||||
this._context = this._canvas.getContext("2d");
|
||||
this._context.drawImage(img, x || 0, y || 0, width || img.width, height || img.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts canvas to JS image object.
|
||||
* @public
|
||||
* @returns {Image}
|
||||
*/
|
||||
getImage() {
|
||||
var img = new Image();
|
||||
img.width = this.getWidth();
|
||||
img.height = this.getHeight();
|
||||
img.src = this._canvas.toDataURL("image/png");
|
||||
return img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get measured text width.
|
||||
* @public
|
||||
* @param {string} text - Measured text.
|
||||
* @returns {number}
|
||||
*/
|
||||
getTextWidth(text) {
|
||||
var metrics = this._context.measureText(text);
|
||||
return Math.round(metrics.width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a text on the canvas.
|
||||
* @public
|
||||
* @param {string} text - Text.
|
||||
* @param {number} [x] - Canvas X - coordinate. 0 - default.
|
||||
* @param {number} [y] - Canvas Y - coordinate. 0 - default.
|
||||
* @param {string} [font] - Font style. 'normal 14px Verdana' - is default.
|
||||
* @param {string} [color] - Css font color.
|
||||
*/
|
||||
drawText(text, x, y, font, color) {
|
||||
this._context.fillStyle = color || "black";
|
||||
this._context.font = font || "normal 14px Verdana";
|
||||
this._context.fillText(text, x || 0, y || 14);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets canvas width.
|
||||
* @public
|
||||
* @returns {number}
|
||||
*/
|
||||
getWidth() {
|
||||
return this._canvas.width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets canvas height.
|
||||
* @public
|
||||
* @returns {number}
|
||||
*/
|
||||
getHeight() {
|
||||
return this._canvas.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load image to canvas.
|
||||
* @public
|
||||
* @param {string} url - Image url.
|
||||
* @pararm {imageCallback} [callback] - Image onload callback.
|
||||
*/
|
||||
load(url, callback) {
|
||||
var img = new Image();
|
||||
var that = this;
|
||||
img.onload = function () {
|
||||
that.resize(img.width, img.height);
|
||||
that._context.drawImage(img, 0, 0, img.width, img.height);
|
||||
callback && callback(img);
|
||||
};
|
||||
img.src = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open canvas image in the new window.
|
||||
* @public
|
||||
*/
|
||||
openImage() {
|
||||
var img = this.getImage();
|
||||
var dataUrl = img.src;
|
||||
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"
|
||||
);
|
||||
printWin.document.open();
|
||||
printWin.document.write(windowContent);
|
||||
printWin.document.close();
|
||||
printWin.focus();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this._canvas.width = 1;
|
||||
this._canvas.height = 1;
|
||||
this._canvas = null;
|
||||
this._context = null;
|
||||
}
|
||||
}
|
||||
|
||||
export { ImageCanvas };
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Usefull class for working with JS canvas object.
|
||||
* @class
|
||||
*/
|
||||
class ImageCanvas {
|
||||
/**
|
||||
* @param {number} [width] - Canvas width. Default 256.
|
||||
* @param {number} [height] - Canvas height. Default 256.
|
||||
*/
|
||||
constructor(width = 256, height = 256) {
|
||||
/**
|
||||
* Canvas object.
|
||||
* @protected
|
||||
* @type {Object}
|
||||
*/
|
||||
this._canvas = document.createElement("canvas");
|
||||
this._canvas.width = width;
|
||||
this._canvas.height = height;
|
||||
|
||||
/**
|
||||
* Canvas context.
|
||||
* @protected
|
||||
* @type {Object}
|
||||
*/
|
||||
this._context = this._canvas.getContext("2d");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns canvas object.
|
||||
* @public
|
||||
* @returns {Object}
|
||||
*/
|
||||
getCanvas() {
|
||||
return this._canvas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns canvas context pointer.
|
||||
* @public
|
||||
* @returns {Object}
|
||||
*/
|
||||
getContext() {
|
||||
return this._context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills canvas RGBA with zeroes.
|
||||
* @public
|
||||
*/
|
||||
fillEmpty() {
|
||||
var imgd = this._context.getImageData(0, 0, this._canvas.width, this._canvas.height);
|
||||
var pixels = imgd.data;
|
||||
for (var i = 0, n = pixels.length; i < n; i += 4) {
|
||||
pixels[i] = pixels[i + 1] = pixels[i + 2] = pixels[i + 3] = 0;
|
||||
}
|
||||
this._context.putImageData(imgd, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets canvas pixels RGBA data.
|
||||
* @public
|
||||
* @returns {Array.<number>}
|
||||
*/
|
||||
getData() {
|
||||
var imgd = this._context.getImageData(0, 0, this._canvas.width, this._canvas.height);
|
||||
return imgd.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the canvas by color.
|
||||
* @public
|
||||
* @param {string} color - CSS string color.
|
||||
*/
|
||||
fillColor(color) {
|
||||
this._context.fillStyle = color;
|
||||
this._context.fillRect(0, 0, this._canvas.width, this._canvas.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets RGBA pixel data.
|
||||
* @public
|
||||
* @param {Array.<number>} data - Array RGBA data.
|
||||
*/
|
||||
setData(data) {
|
||||
var imageData = this._context.createImageData(this._canvas.width, this._canvas.height);
|
||||
imageData.data.set(data);
|
||||
this._context.putImageData(imageData, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize canvas.
|
||||
* @public
|
||||
* @param {number} width - Width.
|
||||
* @param {number} height - Height.
|
||||
*/
|
||||
resize(width, height) {
|
||||
this._canvas.width = width;
|
||||
this._canvas.height = height;
|
||||
this._context = this._canvas.getContext("2d");
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an image on the canvas.
|
||||
* @public
|
||||
* @param {Image} img - Draw image.
|
||||
* @param {number} [x] - Left top image corner X coordinate on the canvas.
|
||||
* @param {number} [y] - Left top image corner Y coordinate on the canvas.
|
||||
* @param {number} [width] - Image width slice. Image width is default.
|
||||
* @param {number} [height] - Image height slice. Image height is default.
|
||||
*/
|
||||
drawImage(img, x, y, width, height) {
|
||||
this._context = this._canvas.getContext("2d");
|
||||
this._context.drawImage(img, x || 0, y || 0, width || img.width, height || img.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts canvas to JS image object.
|
||||
* @public
|
||||
* @returns {Image}
|
||||
*/
|
||||
getImage() {
|
||||
var img = new Image();
|
||||
img.width = this.getWidth();
|
||||
img.height = this.getHeight();
|
||||
img.src = this._canvas.toDataURL("image/png");
|
||||
return img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get measured text width.
|
||||
* @public
|
||||
* @param {string} text - Measured text.
|
||||
* @returns {number}
|
||||
*/
|
||||
getTextWidth(text) {
|
||||
var metrics = this._context.measureText(text);
|
||||
return Math.round(metrics.width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a text on the canvas.
|
||||
* @public
|
||||
* @param {string} text - Text.
|
||||
* @param {number} [x] - Canvas X - coordinate. 0 - default.
|
||||
* @param {number} [y] - Canvas Y - coordinate. 0 - default.
|
||||
* @param {string} [font] - Font style. 'normal 14px Verdana' - is default.
|
||||
* @param {string} [color] - Css font color.
|
||||
*/
|
||||
drawText(text, x, y, font, color) {
|
||||
this._context.fillStyle = color || "black";
|
||||
this._context.font = font || "normal 14px Verdana";
|
||||
this._context.fillText(text, x || 0, y || 14);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets canvas width.
|
||||
* @public
|
||||
* @returns {number}
|
||||
*/
|
||||
getWidth() {
|
||||
return this._canvas.width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets canvas height.
|
||||
* @public
|
||||
* @returns {number}
|
||||
*/
|
||||
getHeight() {
|
||||
return this._canvas.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load image to canvas.
|
||||
* @public
|
||||
* @param {string} url - Image url.
|
||||
* @pararm {imageCallback} [callback] - Image onload callback.
|
||||
*/
|
||||
load(url, callback) {
|
||||
var img = new Image();
|
||||
var that = this;
|
||||
img.onload = function () {
|
||||
that.resize(img.width, img.height);
|
||||
that._context.drawImage(img, 0, 0, img.width, img.height);
|
||||
callback && callback(img);
|
||||
};
|
||||
img.src = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open canvas image in the new window.
|
||||
* @public
|
||||
*/
|
||||
openImage() {
|
||||
var img = this.getImage();
|
||||
var dataUrl = img.src;
|
||||
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"
|
||||
);
|
||||
printWin.document.open();
|
||||
printWin.document.write(windowContent);
|
||||
printWin.document.close();
|
||||
printWin.focus();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this._canvas.width = 1;
|
||||
this._canvas.height = 1;
|
||||
this._canvas = null;
|
||||
this._context = null;
|
||||
}
|
||||
}
|
||||
|
||||
export { ImageCanvas };
|
||||
|
||||
@ -1,48 +1,44 @@
|
||||
/**
|
||||
* @module og/Lock
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
class Lock {
|
||||
|
||||
constructor() {
|
||||
this._lock = 0;
|
||||
}
|
||||
|
||||
lock(key) {
|
||||
this._lock |= (1 << key._id);
|
||||
}
|
||||
|
||||
free(key) {
|
||||
this._lock &= ~(1 << key._id);
|
||||
}
|
||||
|
||||
isFree() {
|
||||
return this._lock === 0;
|
||||
}
|
||||
|
||||
isLocked() {
|
||||
return this._lock !== 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Key {
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this._id = Key._staticCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
export { Lock, Key };
|
||||
'use strict';
|
||||
|
||||
class Lock {
|
||||
|
||||
constructor() {
|
||||
this._lock = 0;
|
||||
}
|
||||
|
||||
lock(key) {
|
||||
this._lock |= (1 << key._id);
|
||||
}
|
||||
|
||||
free(key) {
|
||||
this._lock &= ~(1 << key._id);
|
||||
}
|
||||
|
||||
isFree() {
|
||||
return this._lock === 0;
|
||||
}
|
||||
|
||||
isLocked() {
|
||||
return this._lock !== 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Key {
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this._id = Key._staticCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
export { Lock, Key };
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/LonLat
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as mercator from "./mercator.js";
|
||||
|
||||
102
src/og/Stack.js
102
src/og/Stack.js
@ -1,53 +1,49 @@
|
||||
/**
|
||||
* @module og/Stack
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
class Node {
|
||||
constructor() {
|
||||
this.next = null;
|
||||
this.prev = null;
|
||||
this.data = null;
|
||||
}
|
||||
}
|
||||
|
||||
class Stack {
|
||||
/**
|
||||
*
|
||||
* @param {number} [size]
|
||||
*/
|
||||
constructor(size = 256) {
|
||||
this._current = new Node();
|
||||
this._head = this._current;
|
||||
|
||||
for (var i = 0; i < size; i++) {
|
||||
var n = new Node();
|
||||
n.prev = this._current;
|
||||
this._current.next = n;
|
||||
this._current = n;
|
||||
}
|
||||
this._current = this._head;
|
||||
}
|
||||
|
||||
current() {
|
||||
return this._current;
|
||||
}
|
||||
|
||||
push(data) {
|
||||
this._current = this._current.next;
|
||||
this._current.data = data;
|
||||
}
|
||||
|
||||
pop(data) {
|
||||
this._current = this._current.prev;
|
||||
return this._current.next.data;
|
||||
}
|
||||
|
||||
popPrev(data) {
|
||||
this._current = this._current.prev;
|
||||
return this._current.data;
|
||||
}
|
||||
}
|
||||
|
||||
export { Stack };
|
||||
"use strict";
|
||||
|
||||
class Node {
|
||||
constructor() {
|
||||
this.next = null;
|
||||
this.prev = null;
|
||||
this.data = null;
|
||||
}
|
||||
}
|
||||
|
||||
class Stack {
|
||||
/**
|
||||
*
|
||||
* @param {number} [size]
|
||||
*/
|
||||
constructor(size = 256) {
|
||||
this._current = new Node();
|
||||
this._head = this._current;
|
||||
|
||||
for (var i = 0; i < size; i++) {
|
||||
var n = new Node();
|
||||
n.prev = this._current;
|
||||
this._current.next = n;
|
||||
this._current = n;
|
||||
}
|
||||
this._current = this._head;
|
||||
}
|
||||
|
||||
current() {
|
||||
return this._current;
|
||||
}
|
||||
|
||||
push(data) {
|
||||
this._current = this._current.next;
|
||||
this._current.data = data;
|
||||
}
|
||||
|
||||
pop(data) {
|
||||
this._current = this._current.prev;
|
||||
return this._current.next.data;
|
||||
}
|
||||
|
||||
popPrev(data) {
|
||||
this._current = this._current.prev;
|
||||
return this._current.data;
|
||||
}
|
||||
}
|
||||
|
||||
export { Stack };
|
||||
|
||||
@ -1,116 +1,112 @@
|
||||
/**
|
||||
* @module og/astro/earth
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as math from "../math.js";
|
||||
import { Quat } from "../math/Quat.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import * as astro from "./astro.js";
|
||||
import * as jd from "./jd.js";
|
||||
|
||||
/**
|
||||
* Returns Sun position in the geocentric coordinate system by the time.
|
||||
* @param {Number} jDate - Julian date time.
|
||||
* @returns {Vec3} - Sun geocentric coordinates.
|
||||
*/
|
||||
export function getSunPosition(jDate) {
|
||||
// http://stjarnhimlen.se/comp/tutorial.html
|
||||
// a Mean distance, or semi-major axis
|
||||
// e Eccentricity
|
||||
// T Time at perihelion
|
||||
|
||||
// q Perihelion distance = a * (1 - e)
|
||||
// Q Aphelion distance = a * (1 + e)
|
||||
|
||||
// i Inclination, i.e. the "tilt" of the orbit relative to the
|
||||
// ecliptic. The inclination varies from 0 to 180 degrees. If
|
||||
// the inclination is larger than 90 degrees, the planet is in
|
||||
// a retrogade orbit, i.e. it moves "backwards". The most
|
||||
// well-known celestial body with retrogade motion is Comet Halley.
|
||||
|
||||
// N (usually written as "Capital Omega") Longitude of Ascending
|
||||
// Node. This is the angle, along the ecliptic, from the Vernal
|
||||
// Point to the Ascending Node, which is the intersection between
|
||||
// the orbit and the ecliptic, where the planet moves from south
|
||||
// of to north of the ecliptic, i.e. from negative to positive
|
||||
// latitudes.
|
||||
|
||||
// w (usually written as "small Omega") The angle from the Ascending
|
||||
// node to the Perihelion, along the orbit.
|
||||
|
||||
// P Orbital period = 365.256898326 * a**1.5/sqrt(1+m) days,
|
||||
// where m = the mass of the planet in solar masses (0 for
|
||||
// comets and asteroids). sqrt() is the square root function.
|
||||
|
||||
// n Daily motion = 360_deg / P degrees/day
|
||||
|
||||
// t Some epoch as a day count, e.g. Julian Day Number. The Time
|
||||
// at Perihelion, T, should then be expressed as the same day count.
|
||||
|
||||
// t - T Time since Perihelion, usually in days
|
||||
|
||||
// M Mean Anomaly = n * (t - T) = (t - T) * 360_deg / P
|
||||
// Mean Anomaly is 0 at perihelion and 180 degrees at aphelion
|
||||
|
||||
// L Mean Longitude = M + w + N
|
||||
|
||||
// E Eccentric anomaly, defined by Kepler's equation: M = E - e * sin(E)
|
||||
// An auxiliary angle to compute the position in an elliptic orbit
|
||||
|
||||
// v True anomaly: the angle from perihelion to the planet, as seen
|
||||
// from the Sun
|
||||
|
||||
// r Heliocentric distance: the planet's distance from the Sun.
|
||||
|
||||
// x,y,z Rectangular coordinates. Used e.g. when a heliocentric
|
||||
// position (seen from the Sun) should be converted to a
|
||||
// corresponding geocentric position (seen from the Earth).
|
||||
|
||||
var d = jDate - jd.J2000;
|
||||
|
||||
var w = 282.9404 + 4.70935e-5 * d; // longitude of perihelion
|
||||
// var a = 1.000000; // mean distance, a.u.
|
||||
var e = 0.016709 - 1.151e-9 * d; // eccentricity
|
||||
var M = math.rev(356.047 + 0.9856002585 * d); // mean anomaly
|
||||
|
||||
var oblecl = astro.J2000_OBLIQUITY - 3.563e-7 * d; // obliquity of the ecliptic
|
||||
|
||||
// var L = math.rev(w + M); // Sun's mean longitude
|
||||
|
||||
var E =
|
||||
M + math.DEGREES * e * Math.sin(M * math.RADIANS) * (1 + e * Math.cos(M * math.RADIANS)); // eccentric anomaly
|
||||
|
||||
// Sun rectangular coordiantes, where the X axis points towards the perihelion
|
||||
var x = Math.cos(E * math.RADIANS) - e;
|
||||
var y = Math.sin(E * math.RADIANS) * Math.sqrt(1 - e * e);
|
||||
|
||||
var r = Math.sqrt(x * x + y * y); // distance
|
||||
var v = Math.atan2(y, x) * math.DEGREES; // true anomaly
|
||||
|
||||
var lon = math.rev(v + w); // longitude of the Sun
|
||||
|
||||
// the Sun's ecliptic rectangular coordinates
|
||||
x = r * Math.cos(lon * math.RADIANS);
|
||||
y = r * Math.sin(lon * math.RADIANS);
|
||||
|
||||
// We use oblecl, and rotate these coordinates
|
||||
var xequat = x;
|
||||
var yequat = y * Math.cos(oblecl * math.RADIANS);
|
||||
var zequat = y * Math.sin(oblecl * math.RADIANS);
|
||||
|
||||
var theta = math.TWO_PI * ((d * 24.0) / 23.9344694 - 259.853 / 360.0); // Siderial spin time
|
||||
|
||||
return Quat.yRotation(-theta).mulVec3(
|
||||
new Vec3(
|
||||
-yequat * astro.AU_TO_METERS,
|
||||
zequat * astro.AU_TO_METERS,
|
||||
-xequat * astro.AU_TO_METERS
|
||||
)
|
||||
);
|
||||
|
||||
// Convert to RA and Decl
|
||||
// var RA = Math.atan2(yequat, xequat) * math.DEGREES;
|
||||
// var Decl = Math.atan2(zequat, Math.sqrt(xequat * xequat + yequat * yequat)) * math.DEGREES;
|
||||
}
|
||||
"use strict";
|
||||
|
||||
import * as math from "../math.js";
|
||||
import { Quat } from "../math/Quat.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import * as astro from "./astro.js";
|
||||
import * as jd from "./jd.js";
|
||||
|
||||
/**
|
||||
* Returns Sun position in the geocentric coordinate system by the time.
|
||||
* @param {Number} jDate - Julian date time.
|
||||
* @returns {Vec3} - Sun geocentric coordinates.
|
||||
*/
|
||||
export function getSunPosition(jDate) {
|
||||
// http://stjarnhimlen.se/comp/tutorial.html
|
||||
// a Mean distance, or semi-major axis
|
||||
// e Eccentricity
|
||||
// T Time at perihelion
|
||||
|
||||
// q Perihelion distance = a * (1 - e)
|
||||
// Q Aphelion distance = a * (1 + e)
|
||||
|
||||
// i Inclination, i.e. the "tilt" of the orbit relative to the
|
||||
// ecliptic. The inclination varies from 0 to 180 degrees. If
|
||||
// the inclination is larger than 90 degrees, the planet is in
|
||||
// a retrogade orbit, i.e. it moves "backwards". The most
|
||||
// well-known celestial body with retrogade motion is Comet Halley.
|
||||
|
||||
// N (usually written as "Capital Omega") Longitude of Ascending
|
||||
// Node. This is the angle, along the ecliptic, from the Vernal
|
||||
// Point to the Ascending Node, which is the intersection between
|
||||
// the orbit and the ecliptic, where the planet moves from south
|
||||
// of to north of the ecliptic, i.e. from negative to positive
|
||||
// latitudes.
|
||||
|
||||
// w (usually written as "small Omega") The angle from the Ascending
|
||||
// node to the Perihelion, along the orbit.
|
||||
|
||||
// P Orbital period = 365.256898326 * a**1.5/sqrt(1+m) days,
|
||||
// where m = the mass of the planet in solar masses (0 for
|
||||
// comets and asteroids). sqrt() is the square root function.
|
||||
|
||||
// n Daily motion = 360_deg / P degrees/day
|
||||
|
||||
// t Some epoch as a day count, e.g. Julian Day Number. The Time
|
||||
// at Perihelion, T, should then be expressed as the same day count.
|
||||
|
||||
// t - T Time since Perihelion, usually in days
|
||||
|
||||
// M Mean Anomaly = n * (t - T) = (t - T) * 360_deg / P
|
||||
// Mean Anomaly is 0 at perihelion and 180 degrees at aphelion
|
||||
|
||||
// L Mean Longitude = M + w + N
|
||||
|
||||
// E Eccentric anomaly, defined by Kepler's equation: M = E - e * sin(E)
|
||||
// An auxiliary angle to compute the position in an elliptic orbit
|
||||
|
||||
// v True anomaly: the angle from perihelion to the planet, as seen
|
||||
// from the Sun
|
||||
|
||||
// r Heliocentric distance: the planet's distance from the Sun.
|
||||
|
||||
// x,y,z Rectangular coordinates. Used e.g. when a heliocentric
|
||||
// position (seen from the Sun) should be converted to a
|
||||
// corresponding geocentric position (seen from the Earth).
|
||||
|
||||
var d = jDate - jd.J2000;
|
||||
|
||||
var w = 282.9404 + 4.70935e-5 * d; // longitude of perihelion
|
||||
// var a = 1.000000; // mean distance, a.u.
|
||||
var e = 0.016709 - 1.151e-9 * d; // eccentricity
|
||||
var M = math.rev(356.047 + 0.9856002585 * d); // mean anomaly
|
||||
|
||||
var oblecl = astro.J2000_OBLIQUITY - 3.563e-7 * d; // obliquity of the ecliptic
|
||||
|
||||
// var L = math.rev(w + M); // Sun's mean longitude
|
||||
|
||||
var E =
|
||||
M + math.DEGREES * e * Math.sin(M * math.RADIANS) * (1 + e * Math.cos(M * math.RADIANS)); // eccentric anomaly
|
||||
|
||||
// Sun rectangular coordiantes, where the X axis points towards the perihelion
|
||||
var x = Math.cos(E * math.RADIANS) - e;
|
||||
var y = Math.sin(E * math.RADIANS) * Math.sqrt(1 - e * e);
|
||||
|
||||
var r = Math.sqrt(x * x + y * y); // distance
|
||||
var v = Math.atan2(y, x) * math.DEGREES; // true anomaly
|
||||
|
||||
var lon = math.rev(v + w); // longitude of the Sun
|
||||
|
||||
// the Sun's ecliptic rectangular coordinates
|
||||
x = r * Math.cos(lon * math.RADIANS);
|
||||
y = r * Math.sin(lon * math.RADIANS);
|
||||
|
||||
// We use oblecl, and rotate these coordinates
|
||||
var xequat = x;
|
||||
var yequat = y * Math.cos(oblecl * math.RADIANS);
|
||||
var zequat = y * Math.sin(oblecl * math.RADIANS);
|
||||
|
||||
var theta = math.TWO_PI * ((d * 24.0) / 23.9344694 - 259.853 / 360.0); // Siderial spin time
|
||||
|
||||
return Quat.yRotation(-theta).mulVec3(
|
||||
new Vec3(
|
||||
-yequat * astro.AU_TO_METERS,
|
||||
zequat * astro.AU_TO_METERS,
|
||||
-xequat * astro.AU_TO_METERS
|
||||
)
|
||||
);
|
||||
|
||||
// Convert to RA and Decl
|
||||
// var RA = Math.atan2(yequat, xequat) * math.DEGREES;
|
||||
// var Decl = Math.atan2(zequat, Math.sqrt(xequat * xequat + yequat * yequat)) * math.DEGREES;
|
||||
}
|
||||
|
||||
1032
src/og/astro/jd.js
1032
src/og/astro/jd.js
File diff suppressed because it is too large
Load Diff
@ -1,123 +1,119 @@
|
||||
/**
|
||||
* @module og/astro/orbit
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as math from "../math.js";
|
||||
import { Mat3 } from "../math/Mat3.js";
|
||||
|
||||
export function getEccentricAnomaly(M, ecc) {
|
||||
if (ecc == 0.0) {
|
||||
// Circular orbit
|
||||
return M;
|
||||
} else if (ecc < 0.2) {
|
||||
// Low eccentricity, so use the standard iteration technique
|
||||
return math.solve_iteration_fixed(solveKeplerFunc1(ecc, M), M, 5);
|
||||
} else if (ecc < 0.9) {
|
||||
// Higher eccentricity elliptical orbit; use a more complex but
|
||||
// much faster converging iteration.
|
||||
return math.solve_iteration_fixed(solveKeplerFunc2(ecc, M), M, 6);
|
||||
} else if (ecc < 1.0) {
|
||||
// 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 * 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 = Math.log((2 * M) / ecc + 1.85);
|
||||
return math.solve_iteration_fixed(solveKeplerLaguerreConwayHyp(ecc, M), E, 30);
|
||||
}
|
||||
}
|
||||
|
||||
// Standard iteration for solving Kepler's Equation
|
||||
function solveKeplerFunc1(ecc, M) {
|
||||
return function (x) {
|
||||
return M + ecc * Math.sin(x);
|
||||
};
|
||||
}
|
||||
|
||||
// Faster converging iteration for Kepler's Equation; more efficient
|
||||
// than above for orbits with eccentricities greater than 0.3. This
|
||||
// is from Jean Meeus's _Astronomical Algorithms_ (2nd ed), p. 199
|
||||
function solveKeplerFunc2(ecc, M) {
|
||||
return function (x) {
|
||||
return x + (M + ecc * Math.sin(x) - x) / (1 - ecc * Math.cos(x));
|
||||
};
|
||||
}
|
||||
|
||||
function solveKeplerLaguerreConway(ecc, M) {
|
||||
return function (x) {
|
||||
var s = ecc * Math.sin(x);
|
||||
var c = ecc * Math.cos(x);
|
||||
var f = x - s - M;
|
||||
var f1 = 1 - c;
|
||||
var f2 = s;
|
||||
x += (-5 * f) / (f1 + Math.sign(f1) * Math.sqrt(Math.abs(16 * f1 * f1 - 20 * f * f2)));
|
||||
return x;
|
||||
};
|
||||
}
|
||||
|
||||
function solveKeplerLaguerreConwayHyp(ecc, M) {
|
||||
return function (x) {
|
||||
var s = ecc * Math.sinh(x);
|
||||
var c = ecc * Math.cosh(x);
|
||||
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)));
|
||||
return x;
|
||||
};
|
||||
}
|
||||
|
||||
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 err = 1;
|
||||
while (Math.abs(err) > tol && iterations > 0) {
|
||||
err = e - eccentricity * Math.sin(e) - meanAnomaly;
|
||||
var delta = err / (1 - eccentricity * Math.cos(e));
|
||||
e -= delta;
|
||||
iterations--;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
trueAnomaly = math.zeroTwoPI(trueAnomaly);
|
||||
if (eccentricAnomaly < 0) {
|
||||
trueAnomaly -= math.TWO_PI;
|
||||
}
|
||||
return trueAnomaly + revs * math.TWO_PI;
|
||||
}
|
||||
|
||||
export function getPerifocalToCartesianMatrix(argumentOfPeriapsis, inclination, rightAscension) {
|
||||
var res = new Mat3();
|
||||
var cosap = Math.cos(argumentOfPeriapsis),
|
||||
sinap = Math.sin(argumentOfPeriapsis),
|
||||
cosi = Math.cos(inclination),
|
||||
sini = Math.sin(inclination),
|
||||
cosraan = Math.cos(rightAscension),
|
||||
sinraan = Math.sin(rightAscension);
|
||||
res._m[0] = cosraan * cosap - sinraan * sinap * cosi;
|
||||
res._m[1] = sinraan * cosap + cosraan * sinap * cosi;
|
||||
res._m[2] = sinap * sini;
|
||||
res._m[3] = -cosraan * sinap - sinraan * cosap * cosi;
|
||||
res._m[4] = -sinraan * sinap + cosraan * cosap * cosi;
|
||||
res._m[5] = cosap * sini;
|
||||
res._m[6] = sinraan * sini;
|
||||
res._m[7] = -cosraan * sini;
|
||||
res._m[8] = cosi;
|
||||
return res;
|
||||
}
|
||||
"use strict";
|
||||
|
||||
import * as math from "../math.js";
|
||||
import { Mat3 } from "../math/Mat3.js";
|
||||
|
||||
export function getEccentricAnomaly(M, ecc) {
|
||||
if (ecc == 0.0) {
|
||||
// Circular orbit
|
||||
return M;
|
||||
} else if (ecc < 0.2) {
|
||||
// Low eccentricity, so use the standard iteration technique
|
||||
return math.solve_iteration_fixed(solveKeplerFunc1(ecc, M), M, 5);
|
||||
} else if (ecc < 0.9) {
|
||||
// Higher eccentricity elliptical orbit; use a more complex but
|
||||
// much faster converging iteration.
|
||||
return math.solve_iteration_fixed(solveKeplerFunc2(ecc, M), M, 6);
|
||||
} else if (ecc < 1.0) {
|
||||
// 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 * 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 = Math.log((2 * M) / ecc + 1.85);
|
||||
return math.solve_iteration_fixed(solveKeplerLaguerreConwayHyp(ecc, M), E, 30);
|
||||
}
|
||||
}
|
||||
|
||||
// Standard iteration for solving Kepler's Equation
|
||||
function solveKeplerFunc1(ecc, M) {
|
||||
return function (x) {
|
||||
return M + ecc * Math.sin(x);
|
||||
};
|
||||
}
|
||||
|
||||
// Faster converging iteration for Kepler's Equation; more efficient
|
||||
// than above for orbits with eccentricities greater than 0.3. This
|
||||
// is from Jean Meeus's _Astronomical Algorithms_ (2nd ed), p. 199
|
||||
function solveKeplerFunc2(ecc, M) {
|
||||
return function (x) {
|
||||
return x + (M + ecc * Math.sin(x) - x) / (1 - ecc * Math.cos(x));
|
||||
};
|
||||
}
|
||||
|
||||
function solveKeplerLaguerreConway(ecc, M) {
|
||||
return function (x) {
|
||||
var s = ecc * Math.sin(x);
|
||||
var c = ecc * Math.cos(x);
|
||||
var f = x - s - M;
|
||||
var f1 = 1 - c;
|
||||
var f2 = s;
|
||||
x += (-5 * f) / (f1 + Math.sign(f1) * Math.sqrt(Math.abs(16 * f1 * f1 - 20 * f * f2)));
|
||||
return x;
|
||||
};
|
||||
}
|
||||
|
||||
function solveKeplerLaguerreConwayHyp(ecc, M) {
|
||||
return function (x) {
|
||||
var s = ecc * Math.sinh(x);
|
||||
var c = ecc * Math.cosh(x);
|
||||
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)));
|
||||
return x;
|
||||
};
|
||||
}
|
||||
|
||||
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 err = 1;
|
||||
while (Math.abs(err) > tol && iterations > 0) {
|
||||
err = e - eccentricity * Math.sin(e) - meanAnomaly;
|
||||
var delta = err / (1 - eccentricity * Math.cos(e));
|
||||
e -= delta;
|
||||
iterations--;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
trueAnomaly = math.zeroTwoPI(trueAnomaly);
|
||||
if (eccentricAnomaly < 0) {
|
||||
trueAnomaly -= math.TWO_PI;
|
||||
}
|
||||
return trueAnomaly + revs * math.TWO_PI;
|
||||
}
|
||||
|
||||
export function getPerifocalToCartesianMatrix(argumentOfPeriapsis, inclination, rightAscension) {
|
||||
var res = new Mat3();
|
||||
var cosap = Math.cos(argumentOfPeriapsis),
|
||||
sinap = Math.sin(argumentOfPeriapsis),
|
||||
cosi = Math.cos(inclination),
|
||||
sini = Math.sin(inclination),
|
||||
cosraan = Math.cos(rightAscension),
|
||||
sinraan = Math.sin(rightAscension);
|
||||
res._m[0] = cosraan * cosap - sinraan * sinap * cosi;
|
||||
res._m[1] = sinraan * cosap + cosraan * sinap * cosi;
|
||||
res._m[2] = sinap * sini;
|
||||
res._m[3] = -cosraan * sinap - sinraan * cosap * cosi;
|
||||
res._m[4] = -sinraan * sinap + cosraan * cosap * cosi;
|
||||
res._m[5] = cosap * sini;
|
||||
res._m[6] = sinraan * sini;
|
||||
res._m[7] = -cosraan * sini;
|
||||
res._m[8] = cosi;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1,40 +1,36 @@
|
||||
/**
|
||||
* @module og/astro/rotation
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { PI_TWO } from "../math.js";
|
||||
import { Mat3 } from "../math/Mat3.js";
|
||||
import { Vec3 } from "../math/Vec3.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;
|
||||
|
||||
let cosDec = Math.cos(declination);
|
||||
|
||||
zAxis.x = cosDec * Math.cos(rightAscension);
|
||||
zAxis.y = cosDec * Math.sin(rightAscension);
|
||||
zAxis.z = Math.sin(declination);
|
||||
|
||||
let yAxis = zAxis.cross(xAxis);
|
||||
|
||||
res._m[0] = xAxis.x;
|
||||
res._m[1] = yAxis.x;
|
||||
res._m[2] = zAxis.x;
|
||||
res._m[3] = xAxis.y;
|
||||
res._m[4] = yAxis.y;
|
||||
res._m[5] = zAxis.y;
|
||||
res._m[6] = xAxis.z;
|
||||
res._m[7] = yAxis.z;
|
||||
res._m[8] = zAxis.z;
|
||||
|
||||
return res;
|
||||
}
|
||||
"use strict";
|
||||
|
||||
import { PI_TWO } from "../math.js";
|
||||
import { Mat3 } from "../math/Mat3.js";
|
||||
import { Vec3 } from "../math/Vec3.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;
|
||||
|
||||
let cosDec = Math.cos(declination);
|
||||
|
||||
zAxis.x = cosDec * Math.cos(rightAscension);
|
||||
zAxis.y = cosDec * Math.sin(rightAscension);
|
||||
zAxis.z = Math.sin(declination);
|
||||
|
||||
let yAxis = zAxis.cross(xAxis);
|
||||
|
||||
res._m[0] = xAxis.x;
|
||||
res._m[1] = yAxis.x;
|
||||
res._m[2] = zAxis.x;
|
||||
res._m[3] = xAxis.y;
|
||||
res._m[4] = yAxis.y;
|
||||
res._m[5] = zAxis.y;
|
||||
res._m[6] = xAxis.z;
|
||||
res._m[7] = yAxis.z;
|
||||
res._m[8] = zAxis.z;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
158
src/og/bv/Box.js
158
src/og/bv/Box.js
@ -1,81 +1,77 @@
|
||||
/**
|
||||
* @module og/bv/Box
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
/**
|
||||
* Bounding box class.
|
||||
* @class
|
||||
*/
|
||||
class Box {
|
||||
/**
|
||||
*
|
||||
* @param {*} boundsArr
|
||||
*/
|
||||
constructor(boundsArr = [0, 0, 0, 0, 0, 0]) {
|
||||
/**
|
||||
* Vertices array.
|
||||
* @public
|
||||
* @type{Array.<Vec3>}
|
||||
*/
|
||||
this.vertices = [
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3()
|
||||
];
|
||||
|
||||
if (boundsArr) {
|
||||
this.setFromBoundsArr(boundsArr);
|
||||
}
|
||||
}
|
||||
|
||||
copy(bbox) {
|
||||
for (let i = 0, len = this.vertices.length; i < len; i++) {
|
||||
this.vertices[i].copy(bbox.vertices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding box coordinates by the bounds array.
|
||||
* @param {Array.<number>} bounds - Bounds is an array where [minX, minY, minZ, maxX, maxY, maxZ]
|
||||
*/
|
||||
setFromBoundsArr(bounds) {
|
||||
var xmin = bounds[0],
|
||||
xmax = bounds[3],
|
||||
ymin = bounds[1],
|
||||
ymax = bounds[4],
|
||||
zmin = bounds[2],
|
||||
zmax = bounds[5];
|
||||
|
||||
var v = this.vertices;
|
||||
|
||||
v[0].set(xmin, ymin, zmin);
|
||||
v[1].set(xmax, ymin, zmin);
|
||||
v[2].set(xmax, ymin, zmax);
|
||||
v[3].set(xmin, ymin, zmax);
|
||||
v[4].set(xmin, ymax, zmin);
|
||||
v[5].set(xmax, ymax, zmin);
|
||||
v[6].set(xmax, ymax, zmax);
|
||||
v[7].set(xmin, ymax, zmax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding box coordiantes by ellipsoid geodetic extend.
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @param {Extent} extent - Geodetic extent.
|
||||
*/
|
||||
setFromExtent(ellipsoid, extent) {
|
||||
this.setFromBoundsArr(extent.getCartesianBounds(ellipsoid));
|
||||
}
|
||||
}
|
||||
|
||||
export { Box };
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
/**
|
||||
* Bounding box class.
|
||||
* @class
|
||||
*/
|
||||
class Box {
|
||||
/**
|
||||
*
|
||||
* @param {*} boundsArr
|
||||
*/
|
||||
constructor(boundsArr = [0, 0, 0, 0, 0, 0]) {
|
||||
/**
|
||||
* Vertices array.
|
||||
* @public
|
||||
* @type{Array.<Vec3>}
|
||||
*/
|
||||
this.vertices = [
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3(),
|
||||
new Vec3()
|
||||
];
|
||||
|
||||
if (boundsArr) {
|
||||
this.setFromBoundsArr(boundsArr);
|
||||
}
|
||||
}
|
||||
|
||||
copy(bbox) {
|
||||
for (let i = 0, len = this.vertices.length; i < len; i++) {
|
||||
this.vertices[i].copy(bbox.vertices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding box coordinates by the bounds array.
|
||||
* @param {Array.<number>} bounds - Bounds is an array where [minX, minY, minZ, maxX, maxY, maxZ]
|
||||
*/
|
||||
setFromBoundsArr(bounds) {
|
||||
var xmin = bounds[0],
|
||||
xmax = bounds[3],
|
||||
ymin = bounds[1],
|
||||
ymax = bounds[4],
|
||||
zmin = bounds[2],
|
||||
zmax = bounds[5];
|
||||
|
||||
var v = this.vertices;
|
||||
|
||||
v[0].set(xmin, ymin, zmin);
|
||||
v[1].set(xmax, ymin, zmin);
|
||||
v[2].set(xmax, ymin, zmax);
|
||||
v[3].set(xmin, ymin, zmax);
|
||||
v[4].set(xmin, ymax, zmin);
|
||||
v[5].set(xmax, ymax, zmin);
|
||||
v[6].set(xmax, ymax, zmax);
|
||||
v[7].set(xmin, ymax, zmax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding box coordiantes by ellipsoid geodetic extend.
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @param {Extent} extent - Geodetic extent.
|
||||
*/
|
||||
setFromExtent(ellipsoid, extent) {
|
||||
this.setFromBoundsArr(extent.getCartesianBounds(ellipsoid));
|
||||
}
|
||||
}
|
||||
|
||||
export { Box };
|
||||
|
||||
|
||||
@ -1,61 +1,57 @@
|
||||
/**
|
||||
* @module og/bv/Sphere
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
/**
|
||||
* Bounding sphere class.
|
||||
* @class
|
||||
* @param {Number} [radius] - Bounding sphere radius.
|
||||
* @param {Vec3} [center] - Bounding sphere coordiantes.
|
||||
*/
|
||||
class Sphere {
|
||||
/**
|
||||
*
|
||||
* @param {number} radius
|
||||
* @param {Vec3} center
|
||||
*/
|
||||
constructor(radius = 0, center = Vec3.ZERO) {
|
||||
/**
|
||||
* Sphere radius.
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.radius = radius;
|
||||
|
||||
/**
|
||||
* Sphere coordiantes.
|
||||
* @public
|
||||
* @type {Vec3}
|
||||
*/
|
||||
this.center = center ? center.clone() : new Vec3();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding sphere coordinates by the bounds array.
|
||||
* @param {Array.<number>} bounds - Bounds is an array where [minX, minY, minZ, maxX, maxY, maxZ]
|
||||
*/
|
||||
setFromBounds(bounds) {
|
||||
let m = new Vec3(bounds[0], bounds[1], bounds[2]);
|
||||
this.center.set(
|
||||
m.x + (bounds[3] - m.x) * 0.5,
|
||||
m.y + (bounds[3] - m.y) * 0.5,
|
||||
m.z + (bounds[5] - m.z) * 0.5
|
||||
);
|
||||
this.radius = this.center.distance(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding sphere coordiantes by ellipsoid geodetic extend.
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @param {Extent} extent - Geodetic extent.
|
||||
*/
|
||||
setFromExtent(ellipsoid, extent) {
|
||||
this.setFromBounds(extent.getCartesianBounds(ellipsoid));
|
||||
}
|
||||
}
|
||||
|
||||
export { Sphere };
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
/**
|
||||
* Bounding sphere class.
|
||||
* @class
|
||||
* @param {Number} [radius] - Bounding sphere radius.
|
||||
* @param {Vec3} [center] - Bounding sphere coordiantes.
|
||||
*/
|
||||
class Sphere {
|
||||
/**
|
||||
*
|
||||
* @param {number} radius
|
||||
* @param {Vec3} center
|
||||
*/
|
||||
constructor(radius = 0, center = Vec3.ZERO) {
|
||||
/**
|
||||
* Sphere radius.
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.radius = radius;
|
||||
|
||||
/**
|
||||
* Sphere coordiantes.
|
||||
* @public
|
||||
* @type {Vec3}
|
||||
*/
|
||||
this.center = center ? center.clone() : new Vec3();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding sphere coordinates by the bounds array.
|
||||
* @param {Array.<number>} bounds - Bounds is an array where [minX, minY, minZ, maxX, maxY, maxZ]
|
||||
*/
|
||||
setFromBounds(bounds) {
|
||||
let m = new Vec3(bounds[0], bounds[1], bounds[2]);
|
||||
this.center.set(
|
||||
m.x + (bounds[3] - m.x) * 0.5,
|
||||
m.y + (bounds[3] - m.y) * 0.5,
|
||||
m.z + (bounds[5] - m.z) * 0.5
|
||||
);
|
||||
this.radius = this.center.distance(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bounding sphere coordiantes by ellipsoid geodetic extend.
|
||||
* @param {Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @param {Extent} extent - Geodetic extent.
|
||||
*/
|
||||
setFromExtent(ellipsoid, extent) {
|
||||
this.setFromBounds(extent.getCartesianBounds(ellipsoid));
|
||||
}
|
||||
}
|
||||
|
||||
export { Sphere };
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/camera/PlanetCamera
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Key } from "../Lock.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Atmosphere
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as atmos from "../shaders/atmos.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Control
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/DebugInfo
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/GeoImageDragControl
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { BaseGeoImage } from '../layer/BaseGeoImage.js';
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/KeyboardNavigation
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { input } from "../input/input.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/LayerAnimation
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Events } from '../Events.js';
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/LayerSwitcher
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Dialog } from "../ui/Dialog.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Lighting
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Dialog } from '../ui/Dialog.js';
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/MouseNavigation
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Sphere } from "../bv/Sphere.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/MouseWheelZoomControl
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Sphere } from "../bv/Sphere.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Ruler
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { ToggleButton } from "../ui/ToggleButton.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/ZoomControl
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { RADIANS } from "../math.js";
|
||||
|
||||
@ -1,44 +1,40 @@
|
||||
/**
|
||||
* @module og/control/ShowFps
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { print2d } from "../utils/shared.js";
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
/**
|
||||
* Frame per second(FPS) display control.
|
||||
* @class
|
||||
* @extends {Control}
|
||||
* @param {Object} [options] - Control options.
|
||||
*/
|
||||
class ShowFps extends Control {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
oninit() {
|
||||
var d = document.createElement("div");
|
||||
d.className = "defaultText ";
|
||||
d.id = "ogShowFpsControl";
|
||||
document.body.appendChild(d);
|
||||
this.renderer.events.on("draw", this._draw, this);
|
||||
}
|
||||
|
||||
_draw() {
|
||||
print2d(
|
||||
"ogShowFpsControl",
|
||||
(1000.0 / this.renderer.handler.deltaTime).toFixed(1),
|
||||
this.renderer.handler.canvas.clientWidth - 60,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function showFps(options) {
|
||||
return new ShowFps(options);
|
||||
}
|
||||
|
||||
export { ShowFps };
|
||||
|
||||
"use strict";
|
||||
|
||||
import { print2d } from "../utils/shared.js";
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
/**
|
||||
* Frame per second(FPS) display control.
|
||||
* @class
|
||||
* @extends {Control}
|
||||
* @param {Object} [options] - Control options.
|
||||
*/
|
||||
class ShowFps extends Control {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
oninit() {
|
||||
var d = document.createElement("div");
|
||||
d.className = "defaultText ";
|
||||
d.id = "ogShowFpsControl";
|
||||
document.body.appendChild(d);
|
||||
this.renderer.events.on("draw", this._draw, this);
|
||||
}
|
||||
|
||||
_draw() {
|
||||
print2d(
|
||||
"ogShowFpsControl",
|
||||
(1000.0 / this.renderer.handler.deltaTime).toFixed(1),
|
||||
this.renderer.handler.canvas.clientWidth - 60,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function showFps(options) {
|
||||
return new ShowFps(options);
|
||||
}
|
||||
|
||||
export { ShowFps };
|
||||
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/SimpleSkyBackground
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { htmlColorToRgb } from "../utils/shared.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Sun
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { getSunPosition } from "../astro/earth.js";
|
||||
|
||||
@ -1,39 +1,35 @@
|
||||
/**
|
||||
* @module og/control/ToggleWireframe
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { input } from "../input/input.js";
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
/**
|
||||
* Planet GL draw mode(TRIANGLE_STRIP/LINE_STRING) changer.
|
||||
* @class
|
||||
* @extends {Control}
|
||||
* @param {Object} [options] - Control options.
|
||||
*/
|
||||
class ToggleWireframe extends Control {
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this._isActive = options.isActive || false;
|
||||
}
|
||||
|
||||
oninit() {
|
||||
this.renderer.events.on("charkeypress", input.KEY_X, this.toogleWireframe, this);
|
||||
if (this._isActive) {
|
||||
this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP);
|
||||
}
|
||||
}
|
||||
|
||||
toogleWireframe(e) {
|
||||
if (this.planet.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.planet.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP);
|
||||
} else {
|
||||
this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { ToggleWireframe };
|
||||
|
||||
"use strict";
|
||||
|
||||
import { input } from "../input/input.js";
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
/**
|
||||
* Planet GL draw mode(TRIANGLE_STRIP/LINE_STRING) changer.
|
||||
* @class
|
||||
* @extends {Control}
|
||||
* @param {Object} [options] - Control options.
|
||||
*/
|
||||
class ToggleWireframe extends Control {
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this._isActive = options.isActive || false;
|
||||
}
|
||||
|
||||
oninit() {
|
||||
this.renderer.events.on("charkeypress", input.KEY_X, this.toogleWireframe, this);
|
||||
if (this._isActive) {
|
||||
this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP);
|
||||
}
|
||||
}
|
||||
|
||||
toogleWireframe(e) {
|
||||
if (this.planet.drawMode === this.renderer.handler.gl.LINE_STRIP) {
|
||||
this.planet.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP);
|
||||
} else {
|
||||
this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { ToggleWireframe };
|
||||
|
||||
|
||||
@ -1,341 +1,337 @@
|
||||
/**
|
||||
* @module og/control/TouchNavigation
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Sphere } from "../bv/Sphere.js";
|
||||
import { Key } from "../Lock.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import * as math from "../math.js";
|
||||
import { Quat } from "../math/Quat.js";
|
||||
import { Ray } from "../math/Ray.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
class Touch {
|
||||
constructor() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.prev_x = 0;
|
||||
this.prev_y = 0;
|
||||
this.grabbedPoint = new Vec3();
|
||||
this.grabbedSpheroid = new Sphere();
|
||||
this.dX = function () {
|
||||
return this.x - this.prev_x;
|
||||
};
|
||||
this.dY = function () {
|
||||
return this.y - this.prev_y;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Touch pad planet camera dragging control.
|
||||
* @class
|
||||
* @extends {Control}
|
||||
* @param {Object} [options] - Control options.
|
||||
*/
|
||||
class TouchNavigation extends Control {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
this._name = "touchNavigation";
|
||||
|
||||
this.grabbedPoint = new Vec3();
|
||||
this.inertia = 0.007;
|
||||
this.grabbedSpheroid = new Sphere();
|
||||
this.planet = null;
|
||||
this.qRot = new Quat();
|
||||
this.scaleRot = 0;
|
||||
this.rot = 1;
|
||||
this._eye0 = new Vec3();
|
||||
|
||||
this.stepsCount = 5;
|
||||
this.stepsForward = null;
|
||||
this.stepIndex = 0;
|
||||
|
||||
this.pointOnEarth = null;
|
||||
this.earthUp = null;
|
||||
|
||||
this.touches = [new Touch(), new Touch()];
|
||||
|
||||
this._keyLock = new Key();
|
||||
}
|
||||
|
||||
oninit() {
|
||||
this.renderer.events.on("touchstart", this.onTouchStart, this);
|
||||
this.renderer.events.on("touchend", this.onTouchEnd, this);
|
||||
this.renderer.events.on("doubletouch", this.onDoubleTouch, this);
|
||||
this.renderer.events.on("touchcancel", this.onTouchCancel, this);
|
||||
this.renderer.events.on("touchmove", this.onTouchMove, this);
|
||||
this.renderer.events.on("draw", this.onDraw, this);
|
||||
}
|
||||
|
||||
onTouchStart(e) {
|
||||
this._touching = true;
|
||||
|
||||
if (e.sys.touches.length === 2) {
|
||||
var t0 = this.touches[0],
|
||||
t1 = this.touches[1];
|
||||
|
||||
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
t0.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t0.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
t0.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
|
||||
|
||||
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
||||
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
||||
t1.prev_x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
||||
t1.prev_y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
||||
t1.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
|
||||
|
||||
// this.planet._viewChanged = true;
|
||||
this.pointOnEarth = this.planet.getCartesianFromPixelTerrain(
|
||||
this.renderer.handler.getCenter(),
|
||||
true
|
||||
);
|
||||
|
||||
if (this.pointOnEarth) {
|
||||
this.earthUp = this.pointOnEarth.normal();
|
||||
}
|
||||
|
||||
if (t0.grabbedPoint && t1.grabbedPoint) {
|
||||
t0.grabbedSpheroid.radius = t0.grabbedPoint.length();
|
||||
t1.grabbedSpheroid.radius = t1.grabbedPoint.length();
|
||||
this.stopRotation();
|
||||
}
|
||||
} else if (e.sys.touches.length === 1) {
|
||||
this._startTouchOne(e);
|
||||
}
|
||||
}
|
||||
|
||||
_startTouchOne(e) {
|
||||
var t = this.touches[0];
|
||||
|
||||
t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
t.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
|
||||
t.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
|
||||
this._eye0.copy(this.renderer.activeCamera.eye);
|
||||
|
||||
if (t.grabbedPoint) {
|
||||
t.grabbedSpheroid.radius = t.grabbedPoint.length();
|
||||
this.stopRotation();
|
||||
}
|
||||
}
|
||||
|
||||
stopRotation() {
|
||||
this.qRot.clear();
|
||||
this.planet.layerLock.free(this._keyLock);
|
||||
this.planet.terrainLock.free(this._keyLock);
|
||||
this.planet._normalMapCreator.free(this._keyLock);
|
||||
}
|
||||
|
||||
onDoubleTouch(e) {
|
||||
if (this.stepIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.planet.stopFlying();
|
||||
this.stopRotation();
|
||||
|
||||
var p = this.planet.getCartesianFromPixelTerrain(e);
|
||||
if (p) {
|
||||
var g = this.planet.ellipsoid.cartesianToLonLat(p);
|
||||
this.planet.flyLonLat(
|
||||
new LonLat(g.lon, g.lat, this.renderer.activeCamera.eye.distance(p) * 0.57)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onTouchEnd(e) {
|
||||
if (e.sys.touches.length === 0) {
|
||||
this._touching = false;
|
||||
}
|
||||
|
||||
if (e.sys.touches.length === 1) {
|
||||
this._startTouchOne(e);
|
||||
}
|
||||
|
||||
if (
|
||||
Math.abs(this.touches[0].x - this.touches[0].prev_x) < 3 &&
|
||||
Math.abs(this.touches[0].y - this.touches[0].prev_y) < 3
|
||||
) {
|
||||
this.scaleRot = 0;
|
||||
}
|
||||
}
|
||||
|
||||
onTouchCancel(e) {}
|
||||
|
||||
onTouchMove(e) {
|
||||
var cam = this.renderer.activeCamera;
|
||||
|
||||
if (e.sys.touches.length === 2) {
|
||||
this.renderer.controlsBag.scaleRot = 1;
|
||||
|
||||
var t0 = this.touches[0],
|
||||
t1 = this.touches[1];
|
||||
|
||||
if (!t0.grabbedPoint || !t1.grabbedPoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.planet.stopFlying();
|
||||
|
||||
t0.prev_x = t0.x;
|
||||
t0.prev_y = t0.y;
|
||||
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
|
||||
t1.prev_x = t1.x;
|
||||
t1.prev_y = t1.y;
|
||||
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
||||
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
||||
|
||||
// distance = Math.sqrt((t0.prev_x-t1.prev_x)**2+(t0.prev_y-t1.prev_y)**2) - Math.sqrt((t0.x-t1.x)**2 + (t0.y-t1.y)**2))
|
||||
// distance < 0 --> zoomIn; distance > 0 --> zoomOut
|
||||
var t0t1Distance = Math.abs(t0.prev_x - t1.prev_x) + Math.abs(t0.prev_y - t1.prev_y) - (Math.abs(t0.x - t1.x) + Math.abs(t0.y - t1.y))
|
||||
var _move = 0
|
||||
if (t0t1Distance < 0) {
|
||||
_move = 1
|
||||
}
|
||||
if (t0t1Distance > 0) {
|
||||
_move = -1
|
||||
}
|
||||
if (_move !== 0) {
|
||||
let pos = this.planet.getCartesianFromPixelTerrain(e);
|
||||
if (pos) {
|
||||
let d = cam.eye.distance(pos) * 0.075;
|
||||
cam.eye.addA(cam.getForward().scale(_move * d));
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
(t0.dY() > 0 && t1.dY() > 0) ||
|
||||
(t0.dY() < 0 && t1.dY() < 0) ||
|
||||
(t0.dX() > 0 && t1.dX() > 0) ||
|
||||
(t0.dX() < 0 && t1.dX() < 0)
|
||||
) {
|
||||
var l =
|
||||
(0.5 / cam.eye.distance(this.pointOnEarth)) * cam._lonLat.height * math.RADIANS;
|
||||
if (l > 0.007) l = 0.007;
|
||||
cam.rotateHorizontal(l * t0.dX(), false, this.pointOnEarth, this.earthUp);
|
||||
cam.rotateVertical(l * t0.dY(), this.pointOnEarth, true);
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
|
||||
this.scaleRot = 0;
|
||||
} else if (e.sys.touches.length === 1) {
|
||||
var t = this.touches[0];
|
||||
|
||||
t.prev_x = t.x;
|
||||
t.prev_y = t.y;
|
||||
t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
|
||||
if (!t.grabbedPoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.planet.stopFlying();
|
||||
|
||||
var direction = e.direction
|
||||
var targetPoint = new Ray(cam.eye, direction).hitSphere(t.grabbedSpheroid);
|
||||
|
||||
if (targetPoint) {
|
||||
if (cam.slope > 0.2) {
|
||||
this.qRot = Quat.getRotationBetweenVectors(
|
||||
targetPoint.normal(),
|
||||
t.grabbedPoint.normal()
|
||||
);
|
||||
var rot = this.qRot;
|
||||
cam.eye = rot.mulVec3(cam.eye);
|
||||
cam._r = rot.mulVec3(cam._r);
|
||||
cam._u = rot.mulVec3(cam._u);
|
||||
cam._b = rot.mulVec3(cam._b);
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
this.scaleRot = 1;
|
||||
} else {
|
||||
var p0 = t.grabbedPoint,
|
||||
p1 = Vec3.add(p0, cam._u),
|
||||
p2 = Vec3.add(p0, p0.normal());
|
||||
var dir = cam.unproject(t.x, t.y);
|
||||
var px = new Vec3();
|
||||
if (new Ray(cam.eye, dir).hitPlane(p0, p1, p2, px) === Ray.INSIDE) {
|
||||
cam.eye = this._eye0.addA(px.subA(p0).negate());
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
this.scaleRot = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onDraw(e) {
|
||||
this.renderer.controlsBag.scaleRot = this.scaleRot;
|
||||
|
||||
if (this._touching) {
|
||||
return;
|
||||
}
|
||||
|
||||
var r = this.renderer;
|
||||
var cam = r.activeCamera;
|
||||
var prevEye = cam.eye.clone();
|
||||
|
||||
if (this.stepIndex) {
|
||||
r.controlsBag.scaleRot = 1;
|
||||
var sf = this.stepsForward[this.stepsCount - this.stepIndex--];
|
||||
cam.eye = sf.eye;
|
||||
cam._r = sf.v;
|
||||
cam._u = sf.u;
|
||||
cam._b = sf.n;
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
|
||||
if (r.events.mouseState.leftButtonDown || !this.scaleRot) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.scaleRot -= this.inertia;
|
||||
if (this.scaleRot <= 0) {
|
||||
this.scaleRot = 0;
|
||||
} else {
|
||||
r.controlsBag.scaleRot = this.scaleRot;
|
||||
var rot = this.qRot
|
||||
.slerp(Quat.IDENTITY, 1 - this.scaleRot * this.scaleRot * this.scaleRot)
|
||||
.normalize();
|
||||
if (!(rot.x || rot.y || rot.z)) {
|
||||
this.scaleRot = 0;
|
||||
}
|
||||
cam.eye = rot.mulVec3(cam.eye);
|
||||
cam._r = rot.mulVec3(cam._r);
|
||||
cam._u = rot.mulVec3(cam._u);
|
||||
cam._b = rot.mulVec3(cam._b);
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
|
||||
if (cam.eye.distance(prevEye) / cam._terrainAltitude > 0.01) {
|
||||
this.planet.layerLock.lock(this._keyLock);
|
||||
this.planet.terrainLock.lock(this._keyLock);
|
||||
this.planet._normalMapCreator.lock(this._keyLock);
|
||||
} else {
|
||||
this.planet.layerLock.free(this._keyLock);
|
||||
this.planet.terrainLock.free(this._keyLock);
|
||||
this.planet._normalMapCreator.free(this._keyLock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { TouchNavigation };
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Sphere } from "../bv/Sphere.js";
|
||||
import { Key } from "../Lock.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import * as math from "../math.js";
|
||||
import { Quat } from "../math/Quat.js";
|
||||
import { Ray } from "../math/Ray.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
class Touch {
|
||||
constructor() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.prev_x = 0;
|
||||
this.prev_y = 0;
|
||||
this.grabbedPoint = new Vec3();
|
||||
this.grabbedSpheroid = new Sphere();
|
||||
this.dX = function () {
|
||||
return this.x - this.prev_x;
|
||||
};
|
||||
this.dY = function () {
|
||||
return this.y - this.prev_y;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Touch pad planet camera dragging control.
|
||||
* @class
|
||||
* @extends {Control}
|
||||
* @param {Object} [options] - Control options.
|
||||
*/
|
||||
class TouchNavigation extends Control {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
this._name = "touchNavigation";
|
||||
|
||||
this.grabbedPoint = new Vec3();
|
||||
this.inertia = 0.007;
|
||||
this.grabbedSpheroid = new Sphere();
|
||||
this.planet = null;
|
||||
this.qRot = new Quat();
|
||||
this.scaleRot = 0;
|
||||
this.rot = 1;
|
||||
this._eye0 = new Vec3();
|
||||
|
||||
this.stepsCount = 5;
|
||||
this.stepsForward = null;
|
||||
this.stepIndex = 0;
|
||||
|
||||
this.pointOnEarth = null;
|
||||
this.earthUp = null;
|
||||
|
||||
this.touches = [new Touch(), new Touch()];
|
||||
|
||||
this._keyLock = new Key();
|
||||
}
|
||||
|
||||
oninit() {
|
||||
this.renderer.events.on("touchstart", this.onTouchStart, this);
|
||||
this.renderer.events.on("touchend", this.onTouchEnd, this);
|
||||
this.renderer.events.on("doubletouch", this.onDoubleTouch, this);
|
||||
this.renderer.events.on("touchcancel", this.onTouchCancel, this);
|
||||
this.renderer.events.on("touchmove", this.onTouchMove, this);
|
||||
this.renderer.events.on("draw", this.onDraw, this);
|
||||
}
|
||||
|
||||
onTouchStart(e) {
|
||||
this._touching = true;
|
||||
|
||||
if (e.sys.touches.length === 2) {
|
||||
var t0 = this.touches[0],
|
||||
t1 = this.touches[1];
|
||||
|
||||
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
t0.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t0.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
t0.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
|
||||
|
||||
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
||||
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
||||
t1.prev_x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
||||
t1.prev_y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
||||
t1.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
|
||||
|
||||
// this.planet._viewChanged = true;
|
||||
this.pointOnEarth = this.planet.getCartesianFromPixelTerrain(
|
||||
this.renderer.handler.getCenter(),
|
||||
true
|
||||
);
|
||||
|
||||
if (this.pointOnEarth) {
|
||||
this.earthUp = this.pointOnEarth.normal();
|
||||
}
|
||||
|
||||
if (t0.grabbedPoint && t1.grabbedPoint) {
|
||||
t0.grabbedSpheroid.radius = t0.grabbedPoint.length();
|
||||
t1.grabbedSpheroid.radius = t1.grabbedPoint.length();
|
||||
this.stopRotation();
|
||||
}
|
||||
} else if (e.sys.touches.length === 1) {
|
||||
this._startTouchOne(e);
|
||||
}
|
||||
}
|
||||
|
||||
_startTouchOne(e) {
|
||||
var t = this.touches[0];
|
||||
|
||||
t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
t.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
|
||||
t.grabbedPoint = this.planet.getCartesianFromPixelTerrain(e, true);
|
||||
this._eye0.copy(this.renderer.activeCamera.eye);
|
||||
|
||||
if (t.grabbedPoint) {
|
||||
t.grabbedSpheroid.radius = t.grabbedPoint.length();
|
||||
this.stopRotation();
|
||||
}
|
||||
}
|
||||
|
||||
stopRotation() {
|
||||
this.qRot.clear();
|
||||
this.planet.layerLock.free(this._keyLock);
|
||||
this.planet.terrainLock.free(this._keyLock);
|
||||
this.planet._normalMapCreator.free(this._keyLock);
|
||||
}
|
||||
|
||||
onDoubleTouch(e) {
|
||||
if (this.stepIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.planet.stopFlying();
|
||||
this.stopRotation();
|
||||
|
||||
var p = this.planet.getCartesianFromPixelTerrain(e);
|
||||
if (p) {
|
||||
var g = this.planet.ellipsoid.cartesianToLonLat(p);
|
||||
this.planet.flyLonLat(
|
||||
new LonLat(g.lon, g.lat, this.renderer.activeCamera.eye.distance(p) * 0.57)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onTouchEnd(e) {
|
||||
if (e.sys.touches.length === 0) {
|
||||
this._touching = false;
|
||||
}
|
||||
|
||||
if (e.sys.touches.length === 1) {
|
||||
this._startTouchOne(e);
|
||||
}
|
||||
|
||||
if (
|
||||
Math.abs(this.touches[0].x - this.touches[0].prev_x) < 3 &&
|
||||
Math.abs(this.touches[0].y - this.touches[0].prev_y) < 3
|
||||
) {
|
||||
this.scaleRot = 0;
|
||||
}
|
||||
}
|
||||
|
||||
onTouchCancel(e) {}
|
||||
|
||||
onTouchMove(e) {
|
||||
var cam = this.renderer.activeCamera;
|
||||
|
||||
if (e.sys.touches.length === 2) {
|
||||
this.renderer.controlsBag.scaleRot = 1;
|
||||
|
||||
var t0 = this.touches[0],
|
||||
t1 = this.touches[1];
|
||||
|
||||
if (!t0.grabbedPoint || !t1.grabbedPoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.planet.stopFlying();
|
||||
|
||||
t0.prev_x = t0.x;
|
||||
t0.prev_y = t0.y;
|
||||
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
|
||||
t1.prev_x = t1.x;
|
||||
t1.prev_y = t1.y;
|
||||
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
||||
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
||||
|
||||
// distance = Math.sqrt((t0.prev_x-t1.prev_x)**2+(t0.prev_y-t1.prev_y)**2) - Math.sqrt((t0.x-t1.x)**2 + (t0.y-t1.y)**2))
|
||||
// distance < 0 --> zoomIn; distance > 0 --> zoomOut
|
||||
var t0t1Distance = Math.abs(t0.prev_x - t1.prev_x) + Math.abs(t0.prev_y - t1.prev_y) - (Math.abs(t0.x - t1.x) + Math.abs(t0.y - t1.y))
|
||||
var _move = 0
|
||||
if (t0t1Distance < 0) {
|
||||
_move = 1
|
||||
}
|
||||
if (t0t1Distance > 0) {
|
||||
_move = -1
|
||||
}
|
||||
if (_move !== 0) {
|
||||
let pos = this.planet.getCartesianFromPixelTerrain(e);
|
||||
if (pos) {
|
||||
let d = cam.eye.distance(pos) * 0.075;
|
||||
cam.eye.addA(cam.getForward().scale(_move * d));
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
(t0.dY() > 0 && t1.dY() > 0) ||
|
||||
(t0.dY() < 0 && t1.dY() < 0) ||
|
||||
(t0.dX() > 0 && t1.dX() > 0) ||
|
||||
(t0.dX() < 0 && t1.dX() < 0)
|
||||
) {
|
||||
var l =
|
||||
(0.5 / cam.eye.distance(this.pointOnEarth)) * cam._lonLat.height * math.RADIANS;
|
||||
if (l > 0.007) l = 0.007;
|
||||
cam.rotateHorizontal(l * t0.dX(), false, this.pointOnEarth, this.earthUp);
|
||||
cam.rotateVertical(l * t0.dY(), this.pointOnEarth, true);
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
|
||||
this.scaleRot = 0;
|
||||
} else if (e.sys.touches.length === 1) {
|
||||
var t = this.touches[0];
|
||||
|
||||
t.prev_x = t.x;
|
||||
t.prev_y = t.y;
|
||||
t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
||||
t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
||||
|
||||
if (!t.grabbedPoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.planet.stopFlying();
|
||||
|
||||
var direction = e.direction
|
||||
var targetPoint = new Ray(cam.eye, direction).hitSphere(t.grabbedSpheroid);
|
||||
|
||||
if (targetPoint) {
|
||||
if (cam.slope > 0.2) {
|
||||
this.qRot = Quat.getRotationBetweenVectors(
|
||||
targetPoint.normal(),
|
||||
t.grabbedPoint.normal()
|
||||
);
|
||||
var rot = this.qRot;
|
||||
cam.eye = rot.mulVec3(cam.eye);
|
||||
cam._r = rot.mulVec3(cam._r);
|
||||
cam._u = rot.mulVec3(cam._u);
|
||||
cam._b = rot.mulVec3(cam._b);
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
this.scaleRot = 1;
|
||||
} else {
|
||||
var p0 = t.grabbedPoint,
|
||||
p1 = Vec3.add(p0, cam._u),
|
||||
p2 = Vec3.add(p0, p0.normal());
|
||||
var dir = cam.unproject(t.x, t.y);
|
||||
var px = new Vec3();
|
||||
if (new Ray(cam.eye, dir).hitPlane(p0, p1, p2, px) === Ray.INSIDE) {
|
||||
cam.eye = this._eye0.addA(px.subA(p0).negate());
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
this.scaleRot = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onDraw(e) {
|
||||
this.renderer.controlsBag.scaleRot = this.scaleRot;
|
||||
|
||||
if (this._touching) {
|
||||
return;
|
||||
}
|
||||
|
||||
var r = this.renderer;
|
||||
var cam = r.activeCamera;
|
||||
var prevEye = cam.eye.clone();
|
||||
|
||||
if (this.stepIndex) {
|
||||
r.controlsBag.scaleRot = 1;
|
||||
var sf = this.stepsForward[this.stepsCount - this.stepIndex--];
|
||||
cam.eye = sf.eye;
|
||||
cam._r = sf.v;
|
||||
cam._u = sf.u;
|
||||
cam._b = sf.n;
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
|
||||
if (r.events.mouseState.leftButtonDown || !this.scaleRot) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.scaleRot -= this.inertia;
|
||||
if (this.scaleRot <= 0) {
|
||||
this.scaleRot = 0;
|
||||
} else {
|
||||
r.controlsBag.scaleRot = this.scaleRot;
|
||||
var rot = this.qRot
|
||||
.slerp(Quat.IDENTITY, 1 - this.scaleRot * this.scaleRot * this.scaleRot)
|
||||
.normalize();
|
||||
if (!(rot.x || rot.y || rot.z)) {
|
||||
this.scaleRot = 0;
|
||||
}
|
||||
cam.eye = rot.mulVec3(cam.eye);
|
||||
cam._r = rot.mulVec3(cam._r);
|
||||
cam._u = rot.mulVec3(cam._u);
|
||||
cam._b = rot.mulVec3(cam._b);
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
}
|
||||
|
||||
if (cam.eye.distance(prevEye) / cam._terrainAltitude > 0.01) {
|
||||
this.planet.layerLock.lock(this._keyLock);
|
||||
this.planet.terrainLock.lock(this._keyLock);
|
||||
this.planet._normalMapCreator.lock(this._keyLock);
|
||||
} else {
|
||||
this.planet.layerLock.free(this._keyLock);
|
||||
this.planet.terrainLock.free(this._keyLock);
|
||||
this.planet._normalMapCreator.free(this._keyLock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { TouchNavigation };
|
||||
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/ZoomControl
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Key } from "../Lock.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Ruler
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Control } from "../Control.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Ruler
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Control } from "../Control.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/control/Selector
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { ToggleButton } from "../../ui/ToggleButton.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/shaders/drawnode
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Program } from "../../webgl/Program.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/ellipsoid/Ellipsoid
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { LonLat } from "../LonLat.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/ellipsoid/wgs84
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Ellipsoid } from "./Ellipsoid.js";
|
||||
|
||||
@ -1,379 +1,375 @@
|
||||
/**
|
||||
* @module og/entity/BaseBillboard
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import * as utils from "../utils/shared.js";
|
||||
import { LOCK_FREE, LOCK_UPDATE } from "./LabelWorker.js";
|
||||
|
||||
/**
|
||||
* Base prototype for billboard and label classes.
|
||||
* @class
|
||||
* @param {Object} [options] - Options:
|
||||
* @param {Vec3|Array.<number>} [options.position] - Billboard spatial position.
|
||||
* @param {number} [options.rotation] - Screen angle rotaion.
|
||||
* @param {Vec4|string|Array.<number>} [options.color] - Billboard color.
|
||||
* @param {Vec3|Array.<number>} [options.alignedAxis] - Billboard aligned vector.
|
||||
* @param {Vec3|Array.<number>} [options.offset] - Billboard center screen offset.
|
||||
* @param {boolean} [options.visibility] - Visibility.
|
||||
*/
|
||||
class BaseBillboard {
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* Object unic identifier.
|
||||
* @public
|
||||
* @readonly
|
||||
* @type {number}
|
||||
*/
|
||||
this.id = BaseBillboard._staticCounter++;
|
||||
|
||||
/**
|
||||
* Billboard center cartesian position.
|
||||
* @protected
|
||||
* @type {Vec3}
|
||||
*/
|
||||
this._position = utils.createVector3(options.position);
|
||||
|
||||
this._positionHigh = new Vec3();
|
||||
|
||||
this._positionLow = new Vec3();
|
||||
|
||||
Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
|
||||
|
||||
/**
|
||||
* Screen space rotation angle.
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this._rotation = options.rotation || 0;
|
||||
|
||||
/**
|
||||
* RGBA color.
|
||||
* @protected
|
||||
* @type {Vec4}
|
||||
*/
|
||||
this._color = utils.createColorRGBA(options.color);
|
||||
|
||||
/**
|
||||
* Cartesian aligned axis vector.
|
||||
* @protected
|
||||
* @type {Vec3}
|
||||
*/
|
||||
this._alignedAxis = utils.createVector3(options.alignedAxis);
|
||||
|
||||
/**
|
||||
* Billboard center screen space offset. Where x,y - screen space offset and z - depth offset.
|
||||
* @protected
|
||||
* @type {math.Vecto3}
|
||||
*/
|
||||
this._offset = utils.createVector3(options.offset);
|
||||
|
||||
/**
|
||||
* Billboard visibility.
|
||||
* @protected
|
||||
* @type {boolean}
|
||||
*/
|
||||
this._visibility = options.visibility != undefined ? options.visibility : true;
|
||||
|
||||
/**
|
||||
* Entity instance that holds this billboard.
|
||||
* @protected
|
||||
* @type {Entity}
|
||||
*/
|
||||
this._entity = null;
|
||||
|
||||
/**
|
||||
* Handler that stores and renders this billboard object.
|
||||
* @protected
|
||||
* @type {BillboardHandler}
|
||||
*/
|
||||
this._handler = null;
|
||||
|
||||
/**
|
||||
* Billboard handler array index.
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this._handlerIndex = -1;
|
||||
|
||||
/**
|
||||
* An indication that the object is ready to draw
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this._isReady = false;
|
||||
|
||||
this._lockId = LOCK_FREE;
|
||||
}
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard position.
|
||||
* @public
|
||||
* @param {number} x - X coordinate.
|
||||
* @param {number} y - Y coordinate.
|
||||
* @param {number} z - Z coordinate.
|
||||
*/
|
||||
setPosition(x, y, z) {
|
||||
this._position.x = x;
|
||||
this._position.y = y;
|
||||
this._position.z = z;
|
||||
Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard position.
|
||||
* @public
|
||||
* @param {Vec3} position - Cartesian coordinates.
|
||||
*/
|
||||
setPosition3v(position) {
|
||||
this._position.x = position.x;
|
||||
this._position.y = position.y;
|
||||
this._position.z = position.z;
|
||||
Vec3.doubleToTwoFloats(position, this._positionHigh, this._positionLow);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns billboard position.
|
||||
* @public
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
getPosition() {
|
||||
return this._position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets screen space offset.
|
||||
* @public
|
||||
* @param {number} x - X offset.
|
||||
* @param {number} y - Y offset.
|
||||
* @param {number} [z] - Z offset.
|
||||
*/
|
||||
setOffset(x, y, z) {
|
||||
this._offset.x = x;
|
||||
this._offset.y = y;
|
||||
z != undefined && (this._offset.z = z);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setOffsetArr(this._handlerIndex, this._offset);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets screen space offset.
|
||||
* @public
|
||||
* @param {Vec2} offset - Offset size.
|
||||
*/
|
||||
setOffset3v(offset) {
|
||||
this.setOffset(offset.x, offset.y, offset.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns billboard screen space offset size.
|
||||
* @public
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
getOffset() {
|
||||
return this._offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard screen space rotation in radians.
|
||||
* @public
|
||||
* @param {number} rotation - Screen space rotation in radians.
|
||||
*/
|
||||
setRotation(rotation) {
|
||||
if (rotation !== this._rotation) {
|
||||
this._rotation = rotation;
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setRotationArr(this._handlerIndex, rotation);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets screen space rotation.
|
||||
* @public
|
||||
* @returns {number}
|
||||
*/
|
||||
getRotation() {
|
||||
return this._rotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard opacity.
|
||||
* @public
|
||||
* @param {number} a - Billboard opacity.
|
||||
*/
|
||||
setOpacity(a) {
|
||||
if (a !== this._color.w) {
|
||||
a != undefined && (this._color.w = a);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setRgbaArr(this._handlerIndex, this._color);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets RGBA color. Each channel from 0.0 to 1.0.
|
||||
* @public
|
||||
* @param {number} r - Red.
|
||||
* @param {number} g - Green.
|
||||
* @param {number} b - Blue.
|
||||
* @param {number} a - Alpha.
|
||||
*/
|
||||
setColor(r, g, b, a) {
|
||||
if (a !== this._color.w || r !== this._color.x || g !== this._color.y || this._color.z !== b) {
|
||||
this._color.x = r;
|
||||
this._color.y = g;
|
||||
this._color.z = b;
|
||||
a != undefined && (this._color.w = a);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setRgbaArr(this._handlerIndex, this._color);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets RGBA color. Each channel from 0.0 to 1.0.
|
||||
* @public
|
||||
* @param {Vec4} color - RGBA vector.
|
||||
*/
|
||||
setColor4v(color) {
|
||||
this.setColor(color.x, color.y, color.z, color.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard color.
|
||||
* @public
|
||||
* @param {string} color - HTML style color.
|
||||
*/
|
||||
setColorHTML(color) {
|
||||
this.setColor4v(utils.htmlColorToRgba(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns RGBA color.
|
||||
* @public
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
getColor() {
|
||||
return this._color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard visibility.
|
||||
* @public
|
||||
* @param {boolean} visibility - Visibility flag.
|
||||
*/
|
||||
setVisibility(visibility) {
|
||||
if (visibility !== this._visibility) {
|
||||
this._visibility = visibility;
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setVisibility(this._handlerIndex, visibility);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns billboard visibility.
|
||||
* @public
|
||||
* @returns {boolean}
|
||||
*/
|
||||
getVisibility() {
|
||||
return this._visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard cartesian aligned vector.
|
||||
* @public
|
||||
* @param {number} x - Aligned vector X coordinate.
|
||||
* @param {number} y - Aligned vector Y coordinate.
|
||||
* @param {number} z - Aligned vector Z coordinate.
|
||||
*/
|
||||
setAlignedAxis(x, y, z) {
|
||||
this._alignedAxis.x = x;
|
||||
this._alignedAxis.y = y;
|
||||
this._alignedAxis.z = z;
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setAlignedAxisArr(this._handlerIndex, this._alignedAxis);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard aligned vector.
|
||||
* @public
|
||||
* @param {math.Vecto3} alignedAxis - Vector to align.
|
||||
*/
|
||||
setAlignedAxis3v(alignedAxis) {
|
||||
this.setAlignedAxis(alignedAxis.x, alignedAxis.y, alignedAxis.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns aligned vector.
|
||||
* @public
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
getAlignedAxis() {
|
||||
return this._alignedAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes billboard from hander.
|
||||
* @public
|
||||
*/
|
||||
remove() {
|
||||
this._entity = null;
|
||||
this._handler && this._handler.remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard picking color.
|
||||
* @public
|
||||
* @param {Vec3} color - Picking color.
|
||||
*/
|
||||
setPickingColor3v(color) {
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setPickingColorArr(this._handlerIndex, color);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { BaseBillboard };
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import * as utils from "../utils/shared.js";
|
||||
import { LOCK_FREE, LOCK_UPDATE } from "./LabelWorker.js";
|
||||
|
||||
/**
|
||||
* Base prototype for billboard and label classes.
|
||||
* @class
|
||||
* @param {Object} [options] - Options:
|
||||
* @param {Vec3|Array.<number>} [options.position] - Billboard spatial position.
|
||||
* @param {number} [options.rotation] - Screen angle rotaion.
|
||||
* @param {Vec4|string|Array.<number>} [options.color] - Billboard color.
|
||||
* @param {Vec3|Array.<number>} [options.alignedAxis] - Billboard aligned vector.
|
||||
* @param {Vec3|Array.<number>} [options.offset] - Billboard center screen offset.
|
||||
* @param {boolean} [options.visibility] - Visibility.
|
||||
*/
|
||||
class BaseBillboard {
|
||||
constructor(options) {
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* Object unic identifier.
|
||||
* @public
|
||||
* @readonly
|
||||
* @type {number}
|
||||
*/
|
||||
this.id = BaseBillboard._staticCounter++;
|
||||
|
||||
/**
|
||||
* Billboard center cartesian position.
|
||||
* @protected
|
||||
* @type {Vec3}
|
||||
*/
|
||||
this._position = utils.createVector3(options.position);
|
||||
|
||||
this._positionHigh = new Vec3();
|
||||
|
||||
this._positionLow = new Vec3();
|
||||
|
||||
Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
|
||||
|
||||
/**
|
||||
* Screen space rotation angle.
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this._rotation = options.rotation || 0;
|
||||
|
||||
/**
|
||||
* RGBA color.
|
||||
* @protected
|
||||
* @type {Vec4}
|
||||
*/
|
||||
this._color = utils.createColorRGBA(options.color);
|
||||
|
||||
/**
|
||||
* Cartesian aligned axis vector.
|
||||
* @protected
|
||||
* @type {Vec3}
|
||||
*/
|
||||
this._alignedAxis = utils.createVector3(options.alignedAxis);
|
||||
|
||||
/**
|
||||
* Billboard center screen space offset. Where x,y - screen space offset and z - depth offset.
|
||||
* @protected
|
||||
* @type {math.Vecto3}
|
||||
*/
|
||||
this._offset = utils.createVector3(options.offset);
|
||||
|
||||
/**
|
||||
* Billboard visibility.
|
||||
* @protected
|
||||
* @type {boolean}
|
||||
*/
|
||||
this._visibility = options.visibility != undefined ? options.visibility : true;
|
||||
|
||||
/**
|
||||
* Entity instance that holds this billboard.
|
||||
* @protected
|
||||
* @type {Entity}
|
||||
*/
|
||||
this._entity = null;
|
||||
|
||||
/**
|
||||
* Handler that stores and renders this billboard object.
|
||||
* @protected
|
||||
* @type {BillboardHandler}
|
||||
*/
|
||||
this._handler = null;
|
||||
|
||||
/**
|
||||
* Billboard handler array index.
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this._handlerIndex = -1;
|
||||
|
||||
/**
|
||||
* An indication that the object is ready to draw
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this._isReady = false;
|
||||
|
||||
this._lockId = LOCK_FREE;
|
||||
}
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard position.
|
||||
* @public
|
||||
* @param {number} x - X coordinate.
|
||||
* @param {number} y - Y coordinate.
|
||||
* @param {number} z - Z coordinate.
|
||||
*/
|
||||
setPosition(x, y, z) {
|
||||
this._position.x = x;
|
||||
this._position.y = y;
|
||||
this._position.z = z;
|
||||
Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard position.
|
||||
* @public
|
||||
* @param {Vec3} position - Cartesian coordinates.
|
||||
*/
|
||||
setPosition3v(position) {
|
||||
this._position.x = position.x;
|
||||
this._position.y = position.y;
|
||||
this._position.z = position.z;
|
||||
Vec3.doubleToTwoFloats(position, this._positionHigh, this._positionLow);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns billboard position.
|
||||
* @public
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
getPosition() {
|
||||
return this._position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets screen space offset.
|
||||
* @public
|
||||
* @param {number} x - X offset.
|
||||
* @param {number} y - Y offset.
|
||||
* @param {number} [z] - Z offset.
|
||||
*/
|
||||
setOffset(x, y, z) {
|
||||
this._offset.x = x;
|
||||
this._offset.y = y;
|
||||
z != undefined && (this._offset.z = z);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setOffsetArr(this._handlerIndex, this._offset);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets screen space offset.
|
||||
* @public
|
||||
* @param {Vec2} offset - Offset size.
|
||||
*/
|
||||
setOffset3v(offset) {
|
||||
this.setOffset(offset.x, offset.y, offset.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns billboard screen space offset size.
|
||||
* @public
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
getOffset() {
|
||||
return this._offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard screen space rotation in radians.
|
||||
* @public
|
||||
* @param {number} rotation - Screen space rotation in radians.
|
||||
*/
|
||||
setRotation(rotation) {
|
||||
if (rotation !== this._rotation) {
|
||||
this._rotation = rotation;
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setRotationArr(this._handlerIndex, rotation);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets screen space rotation.
|
||||
* @public
|
||||
* @returns {number}
|
||||
*/
|
||||
getRotation() {
|
||||
return this._rotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard opacity.
|
||||
* @public
|
||||
* @param {number} a - Billboard opacity.
|
||||
*/
|
||||
setOpacity(a) {
|
||||
if (a !== this._color.w) {
|
||||
a != undefined && (this._color.w = a);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setRgbaArr(this._handlerIndex, this._color);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets RGBA color. Each channel from 0.0 to 1.0.
|
||||
* @public
|
||||
* @param {number} r - Red.
|
||||
* @param {number} g - Green.
|
||||
* @param {number} b - Blue.
|
||||
* @param {number} a - Alpha.
|
||||
*/
|
||||
setColor(r, g, b, a) {
|
||||
if (a !== this._color.w || r !== this._color.x || g !== this._color.y || this._color.z !== b) {
|
||||
this._color.x = r;
|
||||
this._color.y = g;
|
||||
this._color.z = b;
|
||||
a != undefined && (this._color.w = a);
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setRgbaArr(this._handlerIndex, this._color);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets RGBA color. Each channel from 0.0 to 1.0.
|
||||
* @public
|
||||
* @param {Vec4} color - RGBA vector.
|
||||
*/
|
||||
setColor4v(color) {
|
||||
this.setColor(color.x, color.y, color.z, color.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard color.
|
||||
* @public
|
||||
* @param {string} color - HTML style color.
|
||||
*/
|
||||
setColorHTML(color) {
|
||||
this.setColor4v(utils.htmlColorToRgba(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns RGBA color.
|
||||
* @public
|
||||
* @returns {Vec4}
|
||||
*/
|
||||
getColor() {
|
||||
return this._color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard visibility.
|
||||
* @public
|
||||
* @param {boolean} visibility - Visibility flag.
|
||||
*/
|
||||
setVisibility(visibility) {
|
||||
if (visibility !== this._visibility) {
|
||||
this._visibility = visibility;
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setVisibility(this._handlerIndex, visibility);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns billboard visibility.
|
||||
* @public
|
||||
* @returns {boolean}
|
||||
*/
|
||||
getVisibility() {
|
||||
return this._visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard cartesian aligned vector.
|
||||
* @public
|
||||
* @param {number} x - Aligned vector X coordinate.
|
||||
* @param {number} y - Aligned vector Y coordinate.
|
||||
* @param {number} z - Aligned vector Z coordinate.
|
||||
*/
|
||||
setAlignedAxis(x, y, z) {
|
||||
this._alignedAxis.x = x;
|
||||
this._alignedAxis.y = y;
|
||||
this._alignedAxis.z = z;
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setAlignedAxisArr(this._handlerIndex, this._alignedAxis);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard aligned vector.
|
||||
* @public
|
||||
* @param {math.Vecto3} alignedAxis - Vector to align.
|
||||
*/
|
||||
setAlignedAxis3v(alignedAxis) {
|
||||
this.setAlignedAxis(alignedAxis.x, alignedAxis.y, alignedAxis.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns aligned vector.
|
||||
* @public
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
getAlignedAxis() {
|
||||
return this._alignedAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes billboard from hander.
|
||||
* @public
|
||||
*/
|
||||
remove() {
|
||||
this._entity = null;
|
||||
this._handler && this._handler.remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets billboard picking color.
|
||||
* @public
|
||||
* @param {Vec3} color - Picking color.
|
||||
*/
|
||||
setPickingColor3v(color) {
|
||||
if (this._isReady && this._handler) {
|
||||
this._handler.setPickingColorArr(this._handlerIndex, color);
|
||||
} else if (this._lockId !== LOCK_FREE) {
|
||||
this._lockId = LOCK_UPDATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { BaseBillboard };
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/Billboard
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { BaseBillboard } from "./BaseBillboard.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/BillboardHandler
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as shaders from "../shaders/billboard.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/Entity
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/EntityCollection
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Events } from "../Events.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/GeoObject
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Quat, Vec3 } from "../math/index.js";
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @module og/entity/GeoObjectHandler
|
||||
*/
|
||||
|
||||
import * as shaders from "../shaders/geoObject.js";
|
||||
import { concatArrays, loadImage, makeArrayTyped, spliceArray } from "../utils/shared.js";
|
||||
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/Geometry
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
@ -193,7 +189,7 @@ class Geometry {
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
* @todo ASAP need test for this method
|
||||
* @param geoJson
|
||||
* @returns {Geometry}
|
||||
*/
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/GeometryHandler
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { doubleToTwoFloatsV2 } from "../math/coder.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/Label
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec4 } from "../math/Vec4.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/LabelHandler
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as shaders from "../shaders/label.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/PointCloud
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
@ -1,126 +1,122 @@
|
||||
/**
|
||||
* @module og/entity/PointCloudHandler
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as shaders from "../shaders/pointCloud.js";
|
||||
|
||||
class PointCloudHandler {
|
||||
constructor(entityCollection) {
|
||||
/**
|
||||
* Picking rendering option.
|
||||
* @public
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.pickingEnabled = true;
|
||||
|
||||
/**
|
||||
* Parent collection
|
||||
* @private
|
||||
* @type {EntityCollection}
|
||||
*/
|
||||
this._entityCollection = entityCollection;
|
||||
|
||||
/**
|
||||
* Renderer
|
||||
* @private
|
||||
* @type {Renderer}
|
||||
*/
|
||||
this._renderer = null;
|
||||
|
||||
/**
|
||||
* Point cloud array
|
||||
* @private
|
||||
* @type {Array.<PointCloud>}
|
||||
*/
|
||||
this._pointClouds = [];
|
||||
|
||||
this.__staticId = PointCloudHandler._staticCounter++;
|
||||
}
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
_initProgram() {
|
||||
if (this._renderer.handler) {
|
||||
if (!this._renderer.handler.programs.pointCloud) {
|
||||
this._renderer.handler.addProgram(shaders.pointCloud());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRenderNode(renderNode) {
|
||||
this._renderer = renderNode.renderer;
|
||||
this._initProgram();
|
||||
for (var i = 0; i < this._pointClouds.length; i++) {
|
||||
this._pointClouds[i].setRenderNode(renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
add(pointCloud) {
|
||||
if (pointCloud._handlerIndex === -1) {
|
||||
pointCloud._handler = this;
|
||||
pointCloud._handlerIndex = this._pointClouds.length;
|
||||
this._pointClouds.push(pointCloud);
|
||||
this._entityCollection &&
|
||||
this._entityCollection.renderNode &&
|
||||
pointCloud.setRenderNode(this._entityCollection.renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
remove(pointCloud) {
|
||||
var index = pointCloud._handlerIndex;
|
||||
if (index !== -1) {
|
||||
pointCloud._deleteBuffers();
|
||||
pointCloud._handlerIndex = -1;
|
||||
pointCloud._handler = null;
|
||||
this._pointClouds.splice(index, 1);
|
||||
this.reindexPointCloudArray(index);
|
||||
}
|
||||
}
|
||||
|
||||
reindexPointCloudArray(startIndex) {
|
||||
var pc = this._pointClouds;
|
||||
for (var i = startIndex; i < pc.length; i++) {
|
||||
pc[i]._handlerIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
var i = this._pointClouds.length;
|
||||
while (i--) {
|
||||
this._pointClouds[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
drawPicking() {
|
||||
if (this.pickingEnabled) {
|
||||
var i = this._pointClouds.length;
|
||||
while (i--) {
|
||||
this._pointClouds[i].drawPicking();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear() {
|
||||
var i = this._pointClouds.length;
|
||||
while (i--) {
|
||||
this._pointClouds[i]._deleteBuffers();
|
||||
this._pointClouds[i]._handler = null;
|
||||
this._pointClouds[i]._handlerIndex = -1;
|
||||
}
|
||||
this._pointClouds.length = 0;
|
||||
this._pointClouds = [];
|
||||
}
|
||||
}
|
||||
|
||||
export { PointCloudHandler };
|
||||
"use strict";
|
||||
|
||||
import * as shaders from "../shaders/pointCloud.js";
|
||||
|
||||
class PointCloudHandler {
|
||||
constructor(entityCollection) {
|
||||
/**
|
||||
* Picking rendering option.
|
||||
* @public
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.pickingEnabled = true;
|
||||
|
||||
/**
|
||||
* Parent collection
|
||||
* @private
|
||||
* @type {EntityCollection}
|
||||
*/
|
||||
this._entityCollection = entityCollection;
|
||||
|
||||
/**
|
||||
* Renderer
|
||||
* @private
|
||||
* @type {Renderer}
|
||||
*/
|
||||
this._renderer = null;
|
||||
|
||||
/**
|
||||
* Point cloud array
|
||||
* @private
|
||||
* @type {Array.<PointCloud>}
|
||||
*/
|
||||
this._pointClouds = [];
|
||||
|
||||
this.__staticId = PointCloudHandler._staticCounter++;
|
||||
}
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
_initProgram() {
|
||||
if (this._renderer.handler) {
|
||||
if (!this._renderer.handler.programs.pointCloud) {
|
||||
this._renderer.handler.addProgram(shaders.pointCloud());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRenderNode(renderNode) {
|
||||
this._renderer = renderNode.renderer;
|
||||
this._initProgram();
|
||||
for (var i = 0; i < this._pointClouds.length; i++) {
|
||||
this._pointClouds[i].setRenderNode(renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
add(pointCloud) {
|
||||
if (pointCloud._handlerIndex === -1) {
|
||||
pointCloud._handler = this;
|
||||
pointCloud._handlerIndex = this._pointClouds.length;
|
||||
this._pointClouds.push(pointCloud);
|
||||
this._entityCollection &&
|
||||
this._entityCollection.renderNode &&
|
||||
pointCloud.setRenderNode(this._entityCollection.renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
remove(pointCloud) {
|
||||
var index = pointCloud._handlerIndex;
|
||||
if (index !== -1) {
|
||||
pointCloud._deleteBuffers();
|
||||
pointCloud._handlerIndex = -1;
|
||||
pointCloud._handler = null;
|
||||
this._pointClouds.splice(index, 1);
|
||||
this.reindexPointCloudArray(index);
|
||||
}
|
||||
}
|
||||
|
||||
reindexPointCloudArray(startIndex) {
|
||||
var pc = this._pointClouds;
|
||||
for (var i = startIndex; i < pc.length; i++) {
|
||||
pc[i]._handlerIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
var i = this._pointClouds.length;
|
||||
while (i--) {
|
||||
this._pointClouds[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
drawPicking() {
|
||||
if (this.pickingEnabled) {
|
||||
var i = this._pointClouds.length;
|
||||
while (i--) {
|
||||
this._pointClouds[i].drawPicking();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear() {
|
||||
var i = this._pointClouds.length;
|
||||
while (i--) {
|
||||
this._pointClouds[i]._deleteBuffers();
|
||||
this._pointClouds[i]._handler = null;
|
||||
this._pointClouds[i]._handlerIndex = -1;
|
||||
}
|
||||
this._pointClouds.length = 0;
|
||||
this._pointClouds = [];
|
||||
}
|
||||
}
|
||||
|
||||
export { PointCloudHandler };
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/Polyline
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
|
||||
@ -1,109 +1,105 @@
|
||||
/**
|
||||
* @module og/entity/PolylineHandler
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as shaders from '../shaders/polyline.js';
|
||||
|
||||
class PolylineHandler {
|
||||
constructor(entityCollection) {
|
||||
|
||||
this._entityCollection = entityCollection;
|
||||
|
||||
this._renderer = null;
|
||||
|
||||
this._polylines = [];
|
||||
|
||||
this.__staticId = PolylineHandler._staticCounter++;
|
||||
|
||||
this.pickingEnabled = true;
|
||||
}
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
_initProgram() {
|
||||
if (this._renderer.handler) {
|
||||
if (!this._renderer.handler.programs.polyline_screen) {
|
||||
this._renderer.handler.addProgram(shaders.polyline_screen());
|
||||
}
|
||||
if (!this._renderer.handler.programs.polyline_picking) {
|
||||
this._renderer.handler.addProgram(shaders.polyline_picking());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRenderNode(renderNode) {
|
||||
this._renderer = renderNode.renderer;
|
||||
this._initProgram();
|
||||
for (var i = 0; i < this._polylines.length; i++) {
|
||||
this._polylines[i].setRenderNode(renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
add(polyline) {
|
||||
if (polyline._handlerIndex === -1) {
|
||||
polyline._handler = this;
|
||||
polyline._handlerIndex = this._polylines.length;
|
||||
this._polylines.push(polyline);
|
||||
this._entityCollection && this._entityCollection.renderNode &&
|
||||
polyline.setRenderNode(this._entityCollection.renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
remove(polyline) {
|
||||
var index = polyline._handlerIndex;
|
||||
if (index !== -1) {
|
||||
polyline._deleteBuffers();
|
||||
polyline._handlerIndex = -1;
|
||||
polyline._handler = null;
|
||||
this._polylines.splice(index, 1);
|
||||
this.reindexPolylineArray(index);
|
||||
}
|
||||
}
|
||||
|
||||
reindexPolylineArray(startIndex) {
|
||||
var ls = this._polylines;
|
||||
for (var i = startIndex; i < ls.length; i++) {
|
||||
ls[i]._handlerIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
let i = this._polylines.length;
|
||||
while (i--) {
|
||||
this._polylines[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
drawPicking() {
|
||||
if (this.pickingEnabled) {
|
||||
let i = this._polylines.length;
|
||||
while (i--) {
|
||||
this._polylines[i].drawPicking();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear() {
|
||||
var i = this._polylines.length;
|
||||
while (i--) {
|
||||
this._polylines[i]._deleteBuffers();
|
||||
this._polylines[i]._handler = null;
|
||||
this._polylines[i]._handlerIndex = -1;
|
||||
}
|
||||
this._polylines.length = 0;
|
||||
this._polylines = [];
|
||||
}
|
||||
}
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as shaders from '../shaders/polyline.js';
|
||||
|
||||
class PolylineHandler {
|
||||
constructor(entityCollection) {
|
||||
|
||||
this._entityCollection = entityCollection;
|
||||
|
||||
this._renderer = null;
|
||||
|
||||
this._polylines = [];
|
||||
|
||||
this.__staticId = PolylineHandler._staticCounter++;
|
||||
|
||||
this.pickingEnabled = true;
|
||||
}
|
||||
|
||||
static get _staticCounter() {
|
||||
if (!this._counter && this._counter !== 0) {
|
||||
this._counter = 0;
|
||||
}
|
||||
return this._counter;
|
||||
}
|
||||
|
||||
static set _staticCounter(n) {
|
||||
this._counter = n;
|
||||
}
|
||||
|
||||
_initProgram() {
|
||||
if (this._renderer.handler) {
|
||||
if (!this._renderer.handler.programs.polyline_screen) {
|
||||
this._renderer.handler.addProgram(shaders.polyline_screen());
|
||||
}
|
||||
if (!this._renderer.handler.programs.polyline_picking) {
|
||||
this._renderer.handler.addProgram(shaders.polyline_picking());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRenderNode(renderNode) {
|
||||
this._renderer = renderNode.renderer;
|
||||
this._initProgram();
|
||||
for (var i = 0; i < this._polylines.length; i++) {
|
||||
this._polylines[i].setRenderNode(renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
add(polyline) {
|
||||
if (polyline._handlerIndex === -1) {
|
||||
polyline._handler = this;
|
||||
polyline._handlerIndex = this._polylines.length;
|
||||
this._polylines.push(polyline);
|
||||
this._entityCollection && this._entityCollection.renderNode &&
|
||||
polyline.setRenderNode(this._entityCollection.renderNode);
|
||||
}
|
||||
}
|
||||
|
||||
remove(polyline) {
|
||||
var index = polyline._handlerIndex;
|
||||
if (index !== -1) {
|
||||
polyline._deleteBuffers();
|
||||
polyline._handlerIndex = -1;
|
||||
polyline._handler = null;
|
||||
this._polylines.splice(index, 1);
|
||||
this.reindexPolylineArray(index);
|
||||
}
|
||||
}
|
||||
|
||||
reindexPolylineArray(startIndex) {
|
||||
var ls = this._polylines;
|
||||
for (var i = startIndex; i < ls.length; i++) {
|
||||
ls[i]._handlerIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
let i = this._polylines.length;
|
||||
while (i--) {
|
||||
this._polylines[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
drawPicking() {
|
||||
if (this.pickingEnabled) {
|
||||
let i = this._polylines.length;
|
||||
while (i--) {
|
||||
this._polylines[i].drawPicking();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear() {
|
||||
var i = this._polylines.length;
|
||||
while (i--) {
|
||||
this._polylines[i]._deleteBuffers();
|
||||
this._polylines[i]._handler = null;
|
||||
this._polylines[i]._handlerIndex = -1;
|
||||
}
|
||||
this._polylines.length = 0;
|
||||
this._polylines = [];
|
||||
}
|
||||
}
|
||||
|
||||
export { PolylineHandler };
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/entity/BaseBillboard
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
@ -1,132 +1,128 @@
|
||||
/**
|
||||
* @module og/input/KeyboardHandler
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { input } from './input.js';
|
||||
|
||||
class KeyboardHandler {
|
||||
|
||||
constructor() {
|
||||
var _currentlyPressedKeys = {};
|
||||
var _pressedKeysCallbacks = {};
|
||||
var _unpressedKeysCallbacks = {};
|
||||
var _charkeysCallbacks = {};
|
||||
var _that = this;
|
||||
var _anykeyCallback = null;
|
||||
var _event = null;
|
||||
|
||||
var _active = true;
|
||||
|
||||
if (KeyboardHandler.prototype._instance) {
|
||||
return KeyboardHandler.prototype._instance;
|
||||
} else {
|
||||
KeyboardHandler.prototype._instance = this;
|
||||
|
||||
document.onkeydown = function (event) { _event = event; _active && _that.handleKeyDown(); };
|
||||
document.onkeyup = function (event) { _event = event; _active && _that.handleKeyUp(); };
|
||||
}
|
||||
|
||||
var _sortByPriority = function (a, b) {
|
||||
return a.priority < b.priority;
|
||||
};
|
||||
|
||||
this.removeEvent = function (events, callback) {
|
||||
//
|
||||
// TODO:...
|
||||
//
|
||||
};
|
||||
|
||||
this.setActivity = function (activity) {
|
||||
_active = activity;
|
||||
};
|
||||
|
||||
this.releaseKeys = function () {
|
||||
_currentlyPressedKeys = {};
|
||||
}
|
||||
|
||||
this.addEvent = function (event, sender, callback, keyCode, priority) {
|
||||
if (priority === undefined) {
|
||||
priority = 1600;
|
||||
}
|
||||
switch (event) {
|
||||
case "keyfree":
|
||||
if (!_unpressedKeysCallbacks[keyCode]) {
|
||||
_unpressedKeysCallbacks[keyCode] = [];
|
||||
}
|
||||
_unpressedKeysCallbacks[keyCode].push({ callback: callback, sender: sender, priority: priority });
|
||||
_unpressedKeysCallbacks[keyCode].sort(_sortByPriority);
|
||||
break;
|
||||
|
||||
case "keypress":
|
||||
if (keyCode == null) {
|
||||
_anykeyCallback = { callback: callback, sender: sender || _that };
|
||||
} else {
|
||||
if (!_pressedKeysCallbacks[keyCode]) {
|
||||
_pressedKeysCallbacks[keyCode] = [];
|
||||
}
|
||||
_pressedKeysCallbacks[keyCode].push({ callback: callback, sender: sender, priority: priority });
|
||||
_pressedKeysCallbacks[keyCode].sort(_sortByPriority);
|
||||
}
|
||||
break;
|
||||
|
||||
case "charkeypress":
|
||||
if (!_charkeysCallbacks[keyCode]) {
|
||||
_charkeysCallbacks[keyCode] = [];
|
||||
}
|
||||
_charkeysCallbacks[keyCode].push({ callback: callback, sender: sender, priority: priority });
|
||||
_charkeysCallbacks[keyCode].sort(_sortByPriority);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
this.isKeyPressed = function (keyCode) {
|
||||
return _currentlyPressedKeys[keyCode];
|
||||
};
|
||||
|
||||
this.handleKeyDown = function () {
|
||||
_anykeyCallback && _anykeyCallback.callback.call(_anykeyCallback.sender, _event);
|
||||
_currentlyPressedKeys[_event.keyCode] = true;
|
||||
for (var ch in _charkeysCallbacks) {
|
||||
if (String.fromCharCode(_event.keyCode) == String.fromCharCode(ch)) {
|
||||
var ccl = _charkeysCallbacks[ch];
|
||||
for (var i = 0; i < ccl.length; i++) {
|
||||
ccl[i].callback.call(ccl[i].sender, _event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_event.keyCode == input.KEY_ALT || _event.keyCode == input.KEY_SHIFT) {
|
||||
_event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
this.handleKeyUp = function () {
|
||||
if (_currentlyPressedKeys[_event.keyCode] || _event.keyCode === input.KEY_PRINTSCREEN) {
|
||||
for (var pk in _unpressedKeysCallbacks) {
|
||||
if (_currentlyPressedKeys[pk] || _event.keyCode === input.KEY_PRINTSCREEN && pk == input.KEY_PRINTSCREEN) {
|
||||
var cpk = _unpressedKeysCallbacks[pk];
|
||||
for (var i = 0; i < cpk.length; i++) {
|
||||
cpk[i].callback.call(cpk[i].sender, _event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentlyPressedKeys[_event.keyCode] = false;
|
||||
};
|
||||
|
||||
this.handleEvents = function () {
|
||||
for (var pk in _pressedKeysCallbacks) {
|
||||
if (_currentlyPressedKeys[pk]) {
|
||||
var cpk = _pressedKeysCallbacks[pk];
|
||||
for (var i = 0; i < cpk.length; i++) {
|
||||
cpk[i].callback.call(cpk[i].sender, _event);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { KeyboardHandler };
|
||||
'use strict';
|
||||
|
||||
import { input } from './input.js';
|
||||
|
||||
class KeyboardHandler {
|
||||
|
||||
constructor() {
|
||||
var _currentlyPressedKeys = {};
|
||||
var _pressedKeysCallbacks = {};
|
||||
var _unpressedKeysCallbacks = {};
|
||||
var _charkeysCallbacks = {};
|
||||
var _that = this;
|
||||
var _anykeyCallback = null;
|
||||
var _event = null;
|
||||
|
||||
var _active = true;
|
||||
|
||||
if (KeyboardHandler.prototype._instance) {
|
||||
return KeyboardHandler.prototype._instance;
|
||||
} else {
|
||||
KeyboardHandler.prototype._instance = this;
|
||||
|
||||
document.onkeydown = function (event) { _event = event; _active && _that.handleKeyDown(); };
|
||||
document.onkeyup = function (event) { _event = event; _active && _that.handleKeyUp(); };
|
||||
}
|
||||
|
||||
var _sortByPriority = function (a, b) {
|
||||
return a.priority < b.priority;
|
||||
};
|
||||
|
||||
this.removeEvent = function (events, callback) {
|
||||
//
|
||||
// TODO:...
|
||||
//
|
||||
};
|
||||
|
||||
this.setActivity = function (activity) {
|
||||
_active = activity;
|
||||
};
|
||||
|
||||
this.releaseKeys = function () {
|
||||
_currentlyPressedKeys = {};
|
||||
}
|
||||
|
||||
this.addEvent = function (event, sender, callback, keyCode, priority) {
|
||||
if (priority === undefined) {
|
||||
priority = 1600;
|
||||
}
|
||||
switch (event) {
|
||||
case "keyfree":
|
||||
if (!_unpressedKeysCallbacks[keyCode]) {
|
||||
_unpressedKeysCallbacks[keyCode] = [];
|
||||
}
|
||||
_unpressedKeysCallbacks[keyCode].push({ callback: callback, sender: sender, priority: priority });
|
||||
_unpressedKeysCallbacks[keyCode].sort(_sortByPriority);
|
||||
break;
|
||||
|
||||
case "keypress":
|
||||
if (keyCode == null) {
|
||||
_anykeyCallback = { callback: callback, sender: sender || _that };
|
||||
} else {
|
||||
if (!_pressedKeysCallbacks[keyCode]) {
|
||||
_pressedKeysCallbacks[keyCode] = [];
|
||||
}
|
||||
_pressedKeysCallbacks[keyCode].push({ callback: callback, sender: sender, priority: priority });
|
||||
_pressedKeysCallbacks[keyCode].sort(_sortByPriority);
|
||||
}
|
||||
break;
|
||||
|
||||
case "charkeypress":
|
||||
if (!_charkeysCallbacks[keyCode]) {
|
||||
_charkeysCallbacks[keyCode] = [];
|
||||
}
|
||||
_charkeysCallbacks[keyCode].push({ callback: callback, sender: sender, priority: priority });
|
||||
_charkeysCallbacks[keyCode].sort(_sortByPriority);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
this.isKeyPressed = function (keyCode) {
|
||||
return _currentlyPressedKeys[keyCode];
|
||||
};
|
||||
|
||||
this.handleKeyDown = function () {
|
||||
_anykeyCallback && _anykeyCallback.callback.call(_anykeyCallback.sender, _event);
|
||||
_currentlyPressedKeys[_event.keyCode] = true;
|
||||
for (var ch in _charkeysCallbacks) {
|
||||
if (String.fromCharCode(_event.keyCode) == String.fromCharCode(ch)) {
|
||||
var ccl = _charkeysCallbacks[ch];
|
||||
for (var i = 0; i < ccl.length; i++) {
|
||||
ccl[i].callback.call(ccl[i].sender, _event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_event.keyCode == input.KEY_ALT || _event.keyCode == input.KEY_SHIFT) {
|
||||
_event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
this.handleKeyUp = function () {
|
||||
if (_currentlyPressedKeys[_event.keyCode] || _event.keyCode === input.KEY_PRINTSCREEN) {
|
||||
for (var pk in _unpressedKeysCallbacks) {
|
||||
if (_currentlyPressedKeys[pk] || _event.keyCode === input.KEY_PRINTSCREEN && pk == input.KEY_PRINTSCREEN) {
|
||||
var cpk = _unpressedKeysCallbacks[pk];
|
||||
for (var i = 0; i < cpk.length; i++) {
|
||||
cpk[i].callback.call(cpk[i].sender, _event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentlyPressedKeys[_event.keyCode] = false;
|
||||
};
|
||||
|
||||
this.handleEvents = function () {
|
||||
for (var pk in _pressedKeysCallbacks) {
|
||||
if (_currentlyPressedKeys[pk]) {
|
||||
var cpk = _pressedKeysCallbacks[pk];
|
||||
for (var i = 0; i < cpk.length; i++) {
|
||||
cpk[i].callback.call(cpk[i].sender, _event);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { KeyboardHandler };
|
||||
|
||||
@ -1,98 +1,94 @@
|
||||
/**
|
||||
* @module og/input/MouseHandler
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
class MouseHandler {
|
||||
|
||||
constructor(htmlObject) {
|
||||
this._htmlObject = htmlObject;
|
||||
}
|
||||
|
||||
setEvent(event, sender, callback) {
|
||||
switch (event) {
|
||||
case "mousewheel":
|
||||
this._htmlObject.addEventListener('mousewheel', function (evt) {
|
||||
var delta = evt.deltaY || evt.detail || evt.wheelDelta;
|
||||
if (evt.wheelDelta == undefined) {
|
||||
evt.wheelDelta = delta * (-120);
|
||||
}
|
||||
callback.call(sender, evt);
|
||||
evt.preventDefault();
|
||||
}, false);
|
||||
|
||||
this._htmlObject.addEventListener('wheel', function (evt) {
|
||||
var delta = evt.deltaY || evt.detail || evt.wheelDelta;
|
||||
if (evt.wheelDelta == undefined) {
|
||||
evt.wheelDelta = delta * (-120);
|
||||
}
|
||||
callback.call(sender, evt);
|
||||
evt.preventDefault();
|
||||
}, false);
|
||||
break;
|
||||
|
||||
case "mousedown":
|
||||
this._htmlObject.addEventListener('mousedown', function (event) {
|
||||
var rect = this.getBoundingClientRect();
|
||||
callback.call(sender, {
|
||||
button: event.button,
|
||||
clientX: event.clientX - rect.left,
|
||||
clientY: event.clientY - rect.top
|
||||
}, event);
|
||||
});
|
||||
this._htmlObject.addEventListener('contextmenu', function (event) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseup":
|
||||
this._htmlObject.addEventListener('mouseup', function (event) {
|
||||
var rect = this.getBoundingClientRect();
|
||||
callback.call(sender, {
|
||||
button: event.button,
|
||||
clientX: event.clientX - rect.left,
|
||||
clientY: event.clientY - rect.top
|
||||
}, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mousemove":
|
||||
this._htmlObject.addEventListener('mousemove', function (event) {
|
||||
var rect = this.getBoundingClientRect();
|
||||
callback.call(sender, {
|
||||
clientX: event.clientX - rect.left,
|
||||
clientY: event.clientY - rect.top
|
||||
}, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseleave":
|
||||
this._htmlObject.addEventListener('mouseleave', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseout":
|
||||
this._htmlObject.addEventListener('mouseout', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseover":
|
||||
this._htmlObject.addEventListener('mouseover', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseenter":
|
||||
this._htmlObject.addEventListener('mouseenter', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { MouseHandler };
|
||||
'use strict';
|
||||
|
||||
class MouseHandler {
|
||||
|
||||
constructor(htmlObject) {
|
||||
this._htmlObject = htmlObject;
|
||||
}
|
||||
|
||||
setEvent(event, sender, callback) {
|
||||
switch (event) {
|
||||
case "mousewheel":
|
||||
this._htmlObject.addEventListener('mousewheel', function (evt) {
|
||||
var delta = evt.deltaY || evt.detail || evt.wheelDelta;
|
||||
if (evt.wheelDelta == undefined) {
|
||||
evt.wheelDelta = delta * (-120);
|
||||
}
|
||||
callback.call(sender, evt);
|
||||
evt.preventDefault();
|
||||
}, false);
|
||||
|
||||
this._htmlObject.addEventListener('wheel', function (evt) {
|
||||
var delta = evt.deltaY || evt.detail || evt.wheelDelta;
|
||||
if (evt.wheelDelta == undefined) {
|
||||
evt.wheelDelta = delta * (-120);
|
||||
}
|
||||
callback.call(sender, evt);
|
||||
evt.preventDefault();
|
||||
}, false);
|
||||
break;
|
||||
|
||||
case "mousedown":
|
||||
this._htmlObject.addEventListener('mousedown', function (event) {
|
||||
var rect = this.getBoundingClientRect();
|
||||
callback.call(sender, {
|
||||
button: event.button,
|
||||
clientX: event.clientX - rect.left,
|
||||
clientY: event.clientY - rect.top
|
||||
}, event);
|
||||
});
|
||||
this._htmlObject.addEventListener('contextmenu', function (event) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseup":
|
||||
this._htmlObject.addEventListener('mouseup', function (event) {
|
||||
var rect = this.getBoundingClientRect();
|
||||
callback.call(sender, {
|
||||
button: event.button,
|
||||
clientX: event.clientX - rect.left,
|
||||
clientY: event.clientY - rect.top
|
||||
}, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mousemove":
|
||||
this._htmlObject.addEventListener('mousemove', function (event) {
|
||||
var rect = this.getBoundingClientRect();
|
||||
callback.call(sender, {
|
||||
clientX: event.clientX - rect.left,
|
||||
clientY: event.clientY - rect.top
|
||||
}, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseleave":
|
||||
this._htmlObject.addEventListener('mouseleave', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseout":
|
||||
this._htmlObject.addEventListener('mouseout', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseover":
|
||||
this._htmlObject.addEventListener('mouseover', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
|
||||
case "mouseenter":
|
||||
this._htmlObject.addEventListener('mouseenter', function (event) {
|
||||
callback.call(sender, event);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { MouseHandler };
|
||||
|
||||
@ -1,63 +1,59 @@
|
||||
/**
|
||||
* @module og/input/TouchHandler
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
class TouchHandler {
|
||||
|
||||
constructor(htmlObject) {
|
||||
this._htmlObject = htmlObject;
|
||||
}
|
||||
|
||||
setEvent(event, sender, callback) {
|
||||
switch (event) {
|
||||
case "touchcancel":
|
||||
this._htmlObject.addEventListener('touchcancel', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
|
||||
case "touchstart":
|
||||
this._htmlObject.addEventListener('touchstart', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
|
||||
case "touchend":
|
||||
this._htmlObject.addEventListener('touchend', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
|
||||
case "touchmove":
|
||||
this._htmlObject.addEventListener('touchmove', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { TouchHandler };
|
||||
|
||||
'use strict';
|
||||
|
||||
class TouchHandler {
|
||||
|
||||
constructor(htmlObject) {
|
||||
this._htmlObject = htmlObject;
|
||||
}
|
||||
|
||||
setEvent(event, sender, callback) {
|
||||
switch (event) {
|
||||
case "touchcancel":
|
||||
this._htmlObject.addEventListener('touchcancel', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
|
||||
case "touchstart":
|
||||
this._htmlObject.addEventListener('touchstart', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
|
||||
case "touchend":
|
||||
this._htmlObject.addEventListener('touchend', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
|
||||
case "touchmove":
|
||||
this._htmlObject.addEventListener('touchmove', function (event) {
|
||||
event.preventDefault();
|
||||
var rect = this.getBoundingClientRect();
|
||||
event.offsetLeft = rect.left;
|
||||
event.offsetTop = rect.top;
|
||||
callback.call(sender, event);
|
||||
event.preventDefault();
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { TouchHandler };
|
||||
|
||||
|
||||
@ -1,48 +1,44 @@
|
||||
/**
|
||||
* @module og/input/input
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
export const input = {
|
||||
KEY_CTRL: 17,
|
||||
KEY_ALT: 18,
|
||||
KEY_SHIFT: 16,
|
||||
KEY_SPACE: 32,
|
||||
KEY_PGUP: 33,
|
||||
KEY_PGDN: 34,
|
||||
KEY_LEFT: 37,
|
||||
KEY_UP: 38,
|
||||
KEY_RIGHT: 39,
|
||||
KEY_DOWN: 40,
|
||||
KEY_PRINTSCREEN: 44,
|
||||
KEY_EQUALS: 61,
|
||||
KEY_A: 65,
|
||||
KEY_C: 67,
|
||||
KEY_D: 68,
|
||||
KEY_E: 69,
|
||||
KEY_F: 70,
|
||||
KEY_H: 72,
|
||||
KEY_I: 73,
|
||||
KEY_K: 75,
|
||||
KEY_L: 76,
|
||||
KEY_N: 78,
|
||||
KEY_O: 79,
|
||||
KEY_P: 80,
|
||||
KEY_Q: 81,
|
||||
KEY_R: 82,
|
||||
KEY_S: 83,
|
||||
KEY_V: 86,
|
||||
KEY_W: 87,
|
||||
KEY_X: 88,
|
||||
KEY_Z: 90,
|
||||
KEY_PLUS: 107,
|
||||
KEY_F1: 112,
|
||||
KEY_MINUS: 173,
|
||||
KEY_APOSTROPHE: 192,
|
||||
MB_LEFT: 0,
|
||||
MB_RIGHT: 2,
|
||||
MB_MIDDLE: 1,
|
||||
KEY_BACK_SLASH: 220,
|
||||
KEY_SINGLE_QUOTE: 222
|
||||
};
|
||||
'use strict';
|
||||
|
||||
export const input = {
|
||||
KEY_CTRL: 17,
|
||||
KEY_ALT: 18,
|
||||
KEY_SHIFT: 16,
|
||||
KEY_SPACE: 32,
|
||||
KEY_PGUP: 33,
|
||||
KEY_PGDN: 34,
|
||||
KEY_LEFT: 37,
|
||||
KEY_UP: 38,
|
||||
KEY_RIGHT: 39,
|
||||
KEY_DOWN: 40,
|
||||
KEY_PRINTSCREEN: 44,
|
||||
KEY_EQUALS: 61,
|
||||
KEY_A: 65,
|
||||
KEY_C: 67,
|
||||
KEY_D: 68,
|
||||
KEY_E: 69,
|
||||
KEY_F: 70,
|
||||
KEY_H: 72,
|
||||
KEY_I: 73,
|
||||
KEY_K: 75,
|
||||
KEY_L: 76,
|
||||
KEY_N: 78,
|
||||
KEY_O: 79,
|
||||
KEY_P: 80,
|
||||
KEY_Q: 81,
|
||||
KEY_R: 82,
|
||||
KEY_S: 83,
|
||||
KEY_V: 86,
|
||||
KEY_W: 87,
|
||||
KEY_X: 88,
|
||||
KEY_Z: 90,
|
||||
KEY_PLUS: 107,
|
||||
KEY_F1: 112,
|
||||
KEY_MINUS: 173,
|
||||
KEY_APOSTROPHE: 192,
|
||||
MB_LEFT: 0,
|
||||
MB_RIGHT: 2,
|
||||
MB_MIDDLE: 1,
|
||||
KEY_BACK_SLASH: 220,
|
||||
KEY_SINGLE_QUOTE: 222
|
||||
};
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/BaseGeoImage
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/CanvasTiles
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as quadTree from "../quadTree/quadTree.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/GeoImage
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { nextHighestPowerOfTwo } from "../math.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/GeoTexture2d
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as math from '../math.js';
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/GeoVideo
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { BaseGeoImage } from "./BaseGeoImage.js";
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
/**
|
||||
* @module og/layer/KML
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Billboard } from "../entity/Billboard.js";
|
||||
import { Entity } from "../entity/Entity.js";
|
||||
import { Extent } from "../Extent.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/Layer
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Events } from "../Events.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/Material
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
class Material {
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/Vector
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Entity } from "../entity/Entity.js";
|
||||
|
||||
@ -1,186 +1,182 @@
|
||||
/**
|
||||
* @module og/layer/WMS
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import * as mercator from "../mercator.js";
|
||||
import { XYZ } from "./XYZ.js";
|
||||
|
||||
/**
|
||||
* Used to display WMS services as tile layers on the globe.
|
||||
* @class
|
||||
* @extends {XYZ}
|
||||
* //TODO: WMS version, format, and custom srs cpecification.
|
||||
* @param {string} name - Layer name.
|
||||
* @param {Object} options - Options:
|
||||
* @param {number} [options.opacity=1.0] - Layer opacity.
|
||||
* @param {number} [options.minZoom=0] - Minimal visibility zoom level.
|
||||
* @param {number} [options.maxZoom=0] - Maximal visibility zoom level.
|
||||
* @param {string} [options.attribution] - Layer attribution that displayed in the attribution area on the screen.
|
||||
* @param {boolean} [options.isBaseLayer=false] - Base layer flag.
|
||||
* @param {boolean} [options.visibility=true] - Layer visibility.
|
||||
* @param {string} options.url - WMS url source.
|
||||
* @param {number} [options.width=256] - Tile width.
|
||||
* @param {number} [options.height=256] - Tile height.
|
||||
* @param {string} options.layers - WMS layers string.
|
||||
* @param {string} [options.version="1.1.1"] - WMS version.
|
||||
* @param {Object} extra - Extra parameters (by WMS rreference or by WMS service vendors) to pass to WMS service.
|
||||
* @example:
|
||||
* new og.layer.WMS("USA States", {
|
||||
* isBaseLayer: false,
|
||||
* url: "http://openglobus.org/geoserver/",
|
||||
* layers: "topp:states",
|
||||
* opacity: 0.5,
|
||||
* zIndex: 50,
|
||||
* attribution: 'USA states - geoserver WMS example',
|
||||
* version: "1.1.1",
|
||||
* visibility: false }, {
|
||||
* transparent: true,
|
||||
* sld: "style.sld"}
|
||||
* );
|
||||
*
|
||||
* @fires og.layer.XYZ#load
|
||||
* @fires og.layer.XYZ#loadend
|
||||
*/
|
||||
class WMS extends XYZ {
|
||||
|
||||
|
||||
constructor(name, options, extra) {
|
||||
super(name, options);
|
||||
|
||||
this._extra = new URLSearchParams(extra).toString();
|
||||
|
||||
|
||||
if (!options.extent) {
|
||||
this.setExtent(new Extent(new LonLat(-180.0, -90), new LonLat(180.0, 90)));
|
||||
}
|
||||
|
||||
/**
|
||||
* WMS layers string.
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.layers = options.layers;
|
||||
|
||||
/**
|
||||
* WMS tile width.
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.imageWidth = options.imageWidth || 256;
|
||||
|
||||
/**
|
||||
* WMS tile height.
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.imageHeight = options.imageHeight || 256;
|
||||
|
||||
this._getBbox = WMS.get_bbox_v1_1_1;
|
||||
|
||||
this.setVersion(options.version);
|
||||
}
|
||||
|
||||
static createRequestUrl(
|
||||
url,
|
||||
layers,
|
||||
format = "image/png",
|
||||
version = "1.1.1",
|
||||
request = "GetMap",
|
||||
srs,
|
||||
bbox,
|
||||
width = 256,
|
||||
height = 256,
|
||||
extra
|
||||
|
||||
) {
|
||||
return `${url}/?LAYERS=${layers}&FORMAT=${format}&SERVICE=WMS&VERSION=${version}&REQUEST=${request}&SRS=${srs}&BBOX=${bbox}&WIDTH=${width}&HEIGHT=${height}` +
|
||||
(extra ? `&${extra}` : "");
|
||||
}
|
||||
|
||||
static get_bbox_v1_1_1(extent) {
|
||||
return (
|
||||
extent.getWest() +
|
||||
"," +
|
||||
extent.getSouth() +
|
||||
"," +
|
||||
extent.getEast() +
|
||||
"," +
|
||||
extent.getNorth()
|
||||
);
|
||||
}
|
||||
|
||||
static get_bbox_v1_3_0(extent) {
|
||||
return (
|
||||
extent.getSouth() +
|
||||
"," +
|
||||
extent.getWest() +
|
||||
"," +
|
||||
extent.getNorth() +
|
||||
"," +
|
||||
extent.getEast()
|
||||
);
|
||||
}
|
||||
|
||||
_checkSegment(segment) {
|
||||
return true;
|
||||
}
|
||||
|
||||
get instanceName() {
|
||||
return "WMS";
|
||||
}
|
||||
|
||||
_createUrl(segment) {
|
||||
return WMS.createRequestUrl(
|
||||
this.url,
|
||||
this.layers,
|
||||
"image/png",
|
||||
this._version,
|
||||
"GetMap",
|
||||
segment._projection.code,
|
||||
this._getBbox(segment.getExtent()),
|
||||
this.imageWidth,
|
||||
this.imageHeight,
|
||||
this._extra
|
||||
);
|
||||
}
|
||||
|
||||
setVersion(version) {
|
||||
if (version) {
|
||||
this._version = version;
|
||||
} else {
|
||||
this._version = "1.1.1";
|
||||
}
|
||||
|
||||
if (this._version === "1.1.1") {
|
||||
this._getBbox = WMS.get_bbox_v1_1_1;
|
||||
} else if (version === "1.3.0") {
|
||||
this._getBbox = WMS.get_bbox_v1_3_0;
|
||||
}
|
||||
}
|
||||
|
||||
_correctFullExtent() {
|
||||
var e = this._extent,
|
||||
em = this._extentMerc;
|
||||
var ENLARGE_MERCATOR_LON = mercator.POLE + 50000;
|
||||
var ENLARGE_MERCATOR_LAT = mercator.POLE + 50000;
|
||||
if (e.northEast.lat === 90.0) {
|
||||
em.northEast.lat = ENLARGE_MERCATOR_LAT;
|
||||
}
|
||||
if (e.northEast.lon === 180.0) {
|
||||
em.northEast.lon = ENLARGE_MERCATOR_LON;
|
||||
}
|
||||
if (e.southWest.lat === -90.0) {
|
||||
em.southWest.lat = -ENLARGE_MERCATOR_LAT;
|
||||
}
|
||||
if (e.southWest.lon === -180.0) {
|
||||
em.southWest.lon = -ENLARGE_MERCATOR_LON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { WMS };
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import * as mercator from "../mercator.js";
|
||||
import { XYZ } from "./XYZ.js";
|
||||
|
||||
/**
|
||||
* Used to display WMS services as tile layers on the globe.
|
||||
* @class
|
||||
* @extends {XYZ}
|
||||
* //TODO: WMS version, format, and custom srs cpecification.
|
||||
* @param {string} name - Layer name.
|
||||
* @param {Object} options - Options:
|
||||
* @param {number} [options.opacity=1.0] - Layer opacity.
|
||||
* @param {number} [options.minZoom=0] - Minimal visibility zoom level.
|
||||
* @param {number} [options.maxZoom=0] - Maximal visibility zoom level.
|
||||
* @param {string} [options.attribution] - Layer attribution that displayed in the attribution area on the screen.
|
||||
* @param {boolean} [options.isBaseLayer=false] - Base layer flag.
|
||||
* @param {boolean} [options.visibility=true] - Layer visibility.
|
||||
* @param {string} options.url - WMS url source.
|
||||
* @param {number} [options.width=256] - Tile width.
|
||||
* @param {number} [options.height=256] - Tile height.
|
||||
* @param {string} options.layers - WMS layers string.
|
||||
* @param {string} [options.version="1.1.1"] - WMS version.
|
||||
* @param {Object} extra - Extra parameters (by WMS rreference or by WMS service vendors) to pass to WMS service.
|
||||
* @example:
|
||||
* new og.layer.WMS("USA States", {
|
||||
* isBaseLayer: false,
|
||||
* url: "http://openglobus.org/geoserver/",
|
||||
* layers: "topp:states",
|
||||
* opacity: 0.5,
|
||||
* zIndex: 50,
|
||||
* attribution: 'USA states - geoserver WMS example',
|
||||
* version: "1.1.1",
|
||||
* visibility: false }, {
|
||||
* transparent: true,
|
||||
* sld: "style.sld"}
|
||||
* );
|
||||
*
|
||||
* @fires og.layer.XYZ#load
|
||||
* @fires og.layer.XYZ#loadend
|
||||
*/
|
||||
class WMS extends XYZ {
|
||||
|
||||
|
||||
constructor(name, options, extra) {
|
||||
super(name, options);
|
||||
|
||||
this._extra = new URLSearchParams(extra).toString();
|
||||
|
||||
|
||||
if (!options.extent) {
|
||||
this.setExtent(new Extent(new LonLat(-180.0, -90), new LonLat(180.0, 90)));
|
||||
}
|
||||
|
||||
/**
|
||||
* WMS layers string.
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.layers = options.layers;
|
||||
|
||||
/**
|
||||
* WMS tile width.
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.imageWidth = options.imageWidth || 256;
|
||||
|
||||
/**
|
||||
* WMS tile height.
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.imageHeight = options.imageHeight || 256;
|
||||
|
||||
this._getBbox = WMS.get_bbox_v1_1_1;
|
||||
|
||||
this.setVersion(options.version);
|
||||
}
|
||||
|
||||
static createRequestUrl(
|
||||
url,
|
||||
layers,
|
||||
format = "image/png",
|
||||
version = "1.1.1",
|
||||
request = "GetMap",
|
||||
srs,
|
||||
bbox,
|
||||
width = 256,
|
||||
height = 256,
|
||||
extra
|
||||
|
||||
) {
|
||||
return `${url}/?LAYERS=${layers}&FORMAT=${format}&SERVICE=WMS&VERSION=${version}&REQUEST=${request}&SRS=${srs}&BBOX=${bbox}&WIDTH=${width}&HEIGHT=${height}` +
|
||||
(extra ? `&${extra}` : "");
|
||||
}
|
||||
|
||||
static get_bbox_v1_1_1(extent) {
|
||||
return (
|
||||
extent.getWest() +
|
||||
"," +
|
||||
extent.getSouth() +
|
||||
"," +
|
||||
extent.getEast() +
|
||||
"," +
|
||||
extent.getNorth()
|
||||
);
|
||||
}
|
||||
|
||||
static get_bbox_v1_3_0(extent) {
|
||||
return (
|
||||
extent.getSouth() +
|
||||
"," +
|
||||
extent.getWest() +
|
||||
"," +
|
||||
extent.getNorth() +
|
||||
"," +
|
||||
extent.getEast()
|
||||
);
|
||||
}
|
||||
|
||||
_checkSegment(segment) {
|
||||
return true;
|
||||
}
|
||||
|
||||
get instanceName() {
|
||||
return "WMS";
|
||||
}
|
||||
|
||||
_createUrl(segment) {
|
||||
return WMS.createRequestUrl(
|
||||
this.url,
|
||||
this.layers,
|
||||
"image/png",
|
||||
this._version,
|
||||
"GetMap",
|
||||
segment._projection.code,
|
||||
this._getBbox(segment.getExtent()),
|
||||
this.imageWidth,
|
||||
this.imageHeight,
|
||||
this._extra
|
||||
);
|
||||
}
|
||||
|
||||
setVersion(version) {
|
||||
if (version) {
|
||||
this._version = version;
|
||||
} else {
|
||||
this._version = "1.1.1";
|
||||
}
|
||||
|
||||
if (this._version === "1.1.1") {
|
||||
this._getBbox = WMS.get_bbox_v1_1_1;
|
||||
} else if (version === "1.3.0") {
|
||||
this._getBbox = WMS.get_bbox_v1_3_0;
|
||||
}
|
||||
}
|
||||
|
||||
_correctFullExtent() {
|
||||
var e = this._extent,
|
||||
em = this._extentMerc;
|
||||
var ENLARGE_MERCATOR_LON = mercator.POLE + 50000;
|
||||
var ENLARGE_MERCATOR_LAT = mercator.POLE + 50000;
|
||||
if (e.northEast.lat === 90.0) {
|
||||
em.northEast.lat = ENLARGE_MERCATOR_LAT;
|
||||
}
|
||||
if (e.northEast.lon === 180.0) {
|
||||
em.northEast.lon = ENLARGE_MERCATOR_LON;
|
||||
}
|
||||
if (e.southWest.lat === -90.0) {
|
||||
em.southWest.lat = -ENLARGE_MERCATOR_LAT;
|
||||
}
|
||||
if (e.southWest.lon === -180.0) {
|
||||
em.southWest.lon = -ENLARGE_MERCATOR_LON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { WMS };
|
||||
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/layer/XYZ
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as mercator from "../mercator.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/light/LightSource
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @module og/math
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @const */
|
||||
|
||||
@ -1,32 +1,28 @@
|
||||
/**
|
||||
* @module og/math/Line2
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Vec2 } from './Vec2.js';
|
||||
|
||||
export class Line2 {
|
||||
constructor(a = 0, b = 0, c = 0) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
static get(p0, p1) {
|
||||
return new Line2(p1.y - p0.y, p0.x - p1.x, p1.x * p0.y - p0.x * p1.y);
|
||||
}
|
||||
|
||||
static getParallel(l, p) {
|
||||
return new Line2(l.a, l.b, -l.a * p.x - l.b * p.y);
|
||||
}
|
||||
|
||||
static getIntersection(L0, L1) {
|
||||
var x = (L1.b * L0.c - L0.b * L1.c) / (L0.b * L1.a - L1.b * L0.a);
|
||||
return new Vec2(x, -(L0.c + L0.a * x) / L0.b);
|
||||
}
|
||||
|
||||
intersects(l) {
|
||||
return Line2.getIntersection(this, l);
|
||||
}
|
||||
}
|
||||
'use strict';
|
||||
|
||||
import { Vec2 } from './Vec2.js';
|
||||
|
||||
export class Line2 {
|
||||
constructor(a = 0, b = 0, c = 0) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
static get(p0, p1) {
|
||||
return new Line2(p1.y - p0.y, p0.x - p1.x, p1.x * p0.y - p0.x * p1.y);
|
||||
}
|
||||
|
||||
static getParallel(l, p) {
|
||||
return new Line2(l.a, l.b, -l.a * p.x - l.b * p.y);
|
||||
}
|
||||
|
||||
static getIntersection(L0, L1) {
|
||||
var x = (L1.b * L0.c - L0.b * L1.c) / (L0.b * L1.a - L1.b * L0.a);
|
||||
return new Vec2(x, -(L0.c + L0.a * x) / L0.b);
|
||||
}
|
||||
|
||||
intersects(l) {
|
||||
return Line2.getIntersection(this, l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,156 +1,152 @@
|
||||
/**
|
||||
* @module og/math/Mat3
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Mat4 } from "./Mat4.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
|
||||
/**
|
||||
* Class represents a 3x3 matrix.
|
||||
* @class
|
||||
*/
|
||||
export class Mat3 {
|
||||
constructor() {
|
||||
/**
|
||||
* A 3x3 matrix, indexable as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this._m = new Array(9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets column-major order array matrix.
|
||||
* @public
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
set(m) {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
this._m[3] = m[3];
|
||||
this._m[4] = m[4];
|
||||
this._m[5] = m[5];
|
||||
this._m[6] = m[6];
|
||||
this._m[7] = m[7];
|
||||
this._m[8] = m[8];
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicates a Mat3 instance.
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
clone() {
|
||||
var res = new Mat3();
|
||||
res.set(this);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy matrix.
|
||||
* @public
|
||||
* @param {Mat3} a - Matrix to copy.
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
copy(a) {
|
||||
return this.set(a._m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates trasposed matrix from the current.
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
transposeTo() {
|
||||
var res = new Mat3();
|
||||
var m = this._m;
|
||||
res._m[0] = m[0];
|
||||
res._m[1] = m[3];
|
||||
res._m[2] = m[6];
|
||||
res._m[3] = m[1];
|
||||
res._m[4] = m[4];
|
||||
res._m[5] = m[7];
|
||||
res._m[6] = m[2];
|
||||
res._m[7] = m[5];
|
||||
res._m[8] = m[8];
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets matrix to identity.
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
setIdentity() {
|
||||
this._m[0] = 1;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
this._m[3] = 0;
|
||||
this._m[4] = 1;
|
||||
this._m[5] = 0;
|
||||
this._m[6] = 0;
|
||||
this._m[7] = 0;
|
||||
this._m[8] = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply to 3d vector.
|
||||
* @public
|
||||
* @params {Vec3} p - 3d vector.
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
mulVec(p) {
|
||||
var d = p.x,
|
||||
e = p.y,
|
||||
g = p.z;
|
||||
var m = this._m;
|
||||
return new Vec3(
|
||||
m[0] * d + m[3] * e + m[6] * g,
|
||||
m[1] * d + m[4] * e + m[7] * g,
|
||||
m[2] * d + m[5] * e + m[8] * g
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to 4x4 matrix.
|
||||
* @public
|
||||
* @returns {Mat4}
|
||||
*/
|
||||
toMatrix4() {
|
||||
var res = new Mat4();
|
||||
var b = res._m;
|
||||
var a = this._m;
|
||||
b[0] = a[0];
|
||||
b[1] = a[1];
|
||||
b[2] = a[2];
|
||||
b[3] = 0;
|
||||
b[4] = a[3];
|
||||
b[5] = a[4];
|
||||
b[6] = a[5];
|
||||
b[7] = 0;
|
||||
b[8] = a[6];
|
||||
b[9] = a[7];
|
||||
b[10] = a[8];
|
||||
b[11] = 0;
|
||||
b[12] = 0;
|
||||
b[13] = 0;
|
||||
b[14] = 0;
|
||||
b[15] = 1;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mat3 factory.
|
||||
* @static
|
||||
* @return {Mat3}
|
||||
*/
|
||||
export function mat3() {
|
||||
return new Mat3();
|
||||
}
|
||||
"use strict";
|
||||
|
||||
import { Mat4 } from "./Mat4.js";
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
|
||||
/**
|
||||
* Class represents a 3x3 matrix.
|
||||
* @class
|
||||
*/
|
||||
export class Mat3 {
|
||||
constructor() {
|
||||
/**
|
||||
* A 3x3 matrix, indexable as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this._m = new Array(9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets column-major order array matrix.
|
||||
* @public
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
set(m) {
|
||||
this._m[0] = m[0];
|
||||
this._m[1] = m[1];
|
||||
this._m[2] = m[2];
|
||||
this._m[3] = m[3];
|
||||
this._m[4] = m[4];
|
||||
this._m[5] = m[5];
|
||||
this._m[6] = m[6];
|
||||
this._m[7] = m[7];
|
||||
this._m[8] = m[8];
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicates a Mat3 instance.
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
clone() {
|
||||
var res = new Mat3();
|
||||
res.set(this);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy matrix.
|
||||
* @public
|
||||
* @param {Mat3} a - Matrix to copy.
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
copy(a) {
|
||||
return this.set(a._m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates trasposed matrix from the current.
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
transposeTo() {
|
||||
var res = new Mat3();
|
||||
var m = this._m;
|
||||
res._m[0] = m[0];
|
||||
res._m[1] = m[3];
|
||||
res._m[2] = m[6];
|
||||
res._m[3] = m[1];
|
||||
res._m[4] = m[4];
|
||||
res._m[5] = m[7];
|
||||
res._m[6] = m[2];
|
||||
res._m[7] = m[5];
|
||||
res._m[8] = m[8];
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets matrix to identity.
|
||||
* @public
|
||||
* @returns {Mat3}
|
||||
*/
|
||||
setIdentity() {
|
||||
this._m[0] = 1;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
this._m[3] = 0;
|
||||
this._m[4] = 1;
|
||||
this._m[5] = 0;
|
||||
this._m[6] = 0;
|
||||
this._m[7] = 0;
|
||||
this._m[8] = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply to 3d vector.
|
||||
* @public
|
||||
* @params {Vec3} p - 3d vector.
|
||||
* @returns {Vec3}
|
||||
*/
|
||||
mulVec(p) {
|
||||
var d = p.x,
|
||||
e = p.y,
|
||||
g = p.z;
|
||||
var m = this._m;
|
||||
return new Vec3(
|
||||
m[0] * d + m[3] * e + m[6] * g,
|
||||
m[1] * d + m[4] * e + m[7] * g,
|
||||
m[2] * d + m[5] * e + m[8] * g
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to 4x4 matrix.
|
||||
* @public
|
||||
* @returns {Mat4}
|
||||
*/
|
||||
toMatrix4() {
|
||||
var res = new Mat4();
|
||||
var b = res._m;
|
||||
var a = this._m;
|
||||
b[0] = a[0];
|
||||
b[1] = a[1];
|
||||
b[2] = a[2];
|
||||
b[3] = 0;
|
||||
b[4] = a[3];
|
||||
b[5] = a[4];
|
||||
b[6] = a[5];
|
||||
b[7] = 0;
|
||||
b[8] = a[6];
|
||||
b[9] = a[7];
|
||||
b[10] = a[8];
|
||||
b[11] = 0;
|
||||
b[12] = 0;
|
||||
b[13] = 0;
|
||||
b[14] = 0;
|
||||
b[15] = 1;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mat3 factory.
|
||||
* @static
|
||||
* @return {Mat3}
|
||||
*/
|
||||
export function mat3() {
|
||||
return new Mat3();
|
||||
}
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/math/Ray
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { EPS10 } from "../math.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/math/Vec2
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Vec3 } from "./Vec3.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/math/Vec3
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Quat } from "./Quat.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/math/Vec4
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { frac } from "../math.js";
|
||||
|
||||
@ -1,104 +1,104 @@
|
||||
/**
|
||||
* @module og/math/coder
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as math from "../math.js";
|
||||
import { Vec4 } from "./Vec4.js";
|
||||
|
||||
/**
|
||||
* Encode 32 bit float value to the RGBA vector.
|
||||
* @function
|
||||
* @param {number} v - 32 bit float value.
|
||||
* @returns {math.Vec4} - RGBA vector value.
|
||||
*/
|
||||
export function encodeFloatToRGBA(v) {
|
||||
var enc = new Vec4((1.0 * v) % 1, (255.0 * v) % 1, (65025.0 * v) % 1, (160581375.0 * v) % 1);
|
||||
var yzww = new Vec4(enc.y / 255, enc.z / 255, enc.w / 255, 0);
|
||||
return enc.subA(yzww);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode RGBA vector to 32 bit float value.
|
||||
* @function
|
||||
* @param {Vec4} rgba - RGBA encoded 32 bit float value.
|
||||
* @returns {number} - Float value.
|
||||
*/
|
||||
export function decodeFloatFromRGBA(rgba) {
|
||||
var s = 1.0 - math.step(128.0, rgba.x) * 2.0;
|
||||
var e = 2.0 * math.mod(rgba.x, 128.0) + math.step(128.0, rgba.y) - 127.0;
|
||||
var m = math.mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;
|
||||
return s * math.exp2(e) * (m * 1.1920928955078125e-7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode RGBA vector to 32 bit float value.
|
||||
* @function
|
||||
* @param {Vec4} rgba - RGBA encoded 32 bit float value.
|
||||
* @returns {number} - Float value.
|
||||
*/
|
||||
export function decodeFloatFromRGBAArr(arr, use32) {
|
||||
var s = 1.0 - math.step(128.0, arr[0]) * 2.0;
|
||||
var e = 2.0 * math.mod(arr[0], 128.0) + math.step(128.0, arr[1]) - 127.0;
|
||||
var m = math.mod(arr[1], 128.0) * 65536.0 + arr[2] * 256.0 + (use32 ? arr[3] : 0.0) + 8388608.0;
|
||||
return s * math.exp2(e) * (m * 1.1920928955078125e-7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloats(value) {
|
||||
var high, low;
|
||||
if (value >= 0.0) {
|
||||
let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
high = Math.fround(doubleHigh);
|
||||
low = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
high = Math.fround(-doubleHigh);
|
||||
low = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return new Float32Array([high, low]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloats2(value, highLowArr) {
|
||||
if (value >= 0.0) {
|
||||
let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
highLowArr[0] = Math.fround(doubleHigh);
|
||||
highLowArr[1] = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
highLowArr[0] = Math.fround(-doubleHigh);
|
||||
highLowArr[1] = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return highLowArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloatsV2(value, highLowVec) {
|
||||
if (value >= 0.0) {
|
||||
let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
highLowVec.x = Math.fround(doubleHigh);
|
||||
highLowVec.y = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
highLowVec.x = Math.fround(-doubleHigh);
|
||||
highLowVec.y = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return highLowVec;
|
||||
}
|
||||
/**
|
||||
* @module og/math/coder
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import * as math from "../math.js";
|
||||
import { Vec4 } from "./Vec4.js";
|
||||
|
||||
/**
|
||||
* Encode 32 bit float value to the RGBA vector.
|
||||
* @function
|
||||
* @param {number} v - 32 bit float value.
|
||||
* @returns {math.Vec4} - RGBA vector value.
|
||||
*/
|
||||
export function encodeFloatToRGBA(v) {
|
||||
var enc = new Vec4((1.0 * v) % 1, (255.0 * v) % 1, (65025.0 * v) % 1, (160581375.0 * v) % 1);
|
||||
var yzww = new Vec4(enc.y / 255, enc.z / 255, enc.w / 255, 0);
|
||||
return enc.subA(yzww);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode RGBA vector to 32 bit float value.
|
||||
* @function
|
||||
* @param {Vec4} rgba - RGBA encoded 32 bit float value.
|
||||
* @returns {number} - Float value.
|
||||
*/
|
||||
export function decodeFloatFromRGBA(rgba) {
|
||||
var s = 1.0 - math.step(128.0, rgba.x) * 2.0;
|
||||
var e = 2.0 * math.mod(rgba.x, 128.0) + math.step(128.0, rgba.y) - 127.0;
|
||||
var m = math.mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;
|
||||
return s * math.exp2(e) * (m * 1.1920928955078125e-7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode RGBA vector to 32 bit float value.
|
||||
* @function
|
||||
* @param {Vec4} rgba - RGBA encoded 32 bit float value.
|
||||
* @returns {number} - Float value.
|
||||
*/
|
||||
export function decodeFloatFromRGBAArr(arr, use32) {
|
||||
var s = 1.0 - math.step(128.0, arr[0]) * 2.0;
|
||||
var e = 2.0 * math.mod(arr[0], 128.0) + math.step(128.0, arr[1]) - 127.0;
|
||||
var m = math.mod(arr[1], 128.0) * 65536.0 + arr[2] * 256.0 + (use32 ? arr[3] : 0.0) + 8388608.0;
|
||||
return s * math.exp2(e) * (m * 1.1920928955078125e-7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloats(value) {
|
||||
var high, low;
|
||||
if (value >= 0.0) {
|
||||
let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
high = Math.fround(doubleHigh);
|
||||
low = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
high = Math.fround(-doubleHigh);
|
||||
low = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return new Float32Array([high, low]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloats2(value, highLowArr) {
|
||||
if (value >= 0.0) {
|
||||
let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
highLowArr[0] = Math.fround(doubleHigh);
|
||||
highLowArr[1] = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
highLowArr[0] = Math.fround(-doubleHigh);
|
||||
highLowArr[1] = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return highLowArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloatsV2(value, highLowVec) {
|
||||
if (value >= 0.0) {
|
||||
let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
|
||||
highLowVec.x = Math.fround(doubleHigh);
|
||||
highLowVec.y = Math.fround(value - doubleHigh);
|
||||
} else {
|
||||
let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
|
||||
highLowVec.x = Math.fround(-doubleHigh);
|
||||
highLowVec.y = Math.fround(value + doubleHigh);
|
||||
}
|
||||
return highLowVec;
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
/**
|
||||
* @module og/proj/EPSG3857
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Proj, Units } from "./Proj.js";
|
||||
|
||||
/**
|
||||
* EPSG:3857 projection object.
|
||||
* @type {Proj}
|
||||
*/
|
||||
export const EPSG3857 = new Proj({ code: "epsg:3857", units: Units.METERS });
|
||||
/**
|
||||
* @module og/proj/EPSG3857
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Proj, Units } from "./Proj.js";
|
||||
|
||||
/**
|
||||
* EPSG:3857 projection object.
|
||||
* @type {Proj}
|
||||
*/
|
||||
export const EPSG3857 = new Proj({ code: "epsg:3857", units: Units.METERS });
|
||||
|
||||
@ -1,63 +1,59 @@
|
||||
/**
|
||||
* @module og/proj/Proj
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Projection units: 'degrees', 'ft', 'm' or 'km'.
|
||||
* @enum {string}
|
||||
* @api
|
||||
*/
|
||||
export const Units = {
|
||||
DEGREES: "degrees",
|
||||
FEET: "ft",
|
||||
METERS: "m",
|
||||
KILOMETERS: "km"
|
||||
};
|
||||
|
||||
/**
|
||||
* Meters per unit lookup table.
|
||||
* @const
|
||||
* @type {Object.<og.proj.Units, number>}
|
||||
*/
|
||||
export const METERS_PER_UNIT = {};
|
||||
METERS_PER_UNIT[Units.FEET] = 0.3048;
|
||||
METERS_PER_UNIT[Units.METERS] = 1;
|
||||
METERS_PER_UNIT[Units.KILOMETERS] = 1000;
|
||||
|
||||
let _counter = 0;
|
||||
class Proj {
|
||||
constructor(options) {
|
||||
/**
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.code = options.code;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {proj.Units}
|
||||
*/
|
||||
this.units = /** @type {Units} */ (options.units);
|
||||
|
||||
/**
|
||||
* Projection identifier, especially usefull for comparison.
|
||||
* @const
|
||||
* @type {integer}
|
||||
*/
|
||||
this.id = _counter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare projections.
|
||||
* @public
|
||||
* @param {Proj} proj - Projetion object.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equal(proj) {
|
||||
return proj.id === this.id;
|
||||
}
|
||||
}
|
||||
|
||||
export { Proj };
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Projection units: 'degrees', 'ft', 'm' or 'km'.
|
||||
* @enum {string}
|
||||
* @api
|
||||
*/
|
||||
export const Units = {
|
||||
DEGREES: "degrees",
|
||||
FEET: "ft",
|
||||
METERS: "m",
|
||||
KILOMETERS: "km"
|
||||
};
|
||||
|
||||
/**
|
||||
* Meters per unit lookup table.
|
||||
* @const
|
||||
* @type {Object.<og.proj.Units, number>}
|
||||
*/
|
||||
export const METERS_PER_UNIT = {};
|
||||
METERS_PER_UNIT[Units.FEET] = 0.3048;
|
||||
METERS_PER_UNIT[Units.METERS] = 1;
|
||||
METERS_PER_UNIT[Units.KILOMETERS] = 1000;
|
||||
|
||||
let _counter = 0;
|
||||
class Proj {
|
||||
constructor(options) {
|
||||
/**
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.code = options.code;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {proj.Units}
|
||||
*/
|
||||
this.units = /** @type {Units} */ (options.units);
|
||||
|
||||
/**
|
||||
* Projection identifier, especially usefull for comparison.
|
||||
* @const
|
||||
* @type {integer}
|
||||
*/
|
||||
this.id = _counter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare projections.
|
||||
* @public
|
||||
* @param {Proj} proj - Projetion object.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
equal(proj) {
|
||||
return proj.id === this.id;
|
||||
}
|
||||
}
|
||||
|
||||
export { Proj };
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
import { EPSG4326 } from "../proj/EPSG4326.js";
|
||||
import { Node } from "../quadTree/Node.js";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
import * as mercator from "../mercator.js";
|
||||
import { Node } from "../quadTree/Node.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/quadTree/EntityCollectionNode
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Sphere } from '../bv/Sphere.js';
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
import { EPSG4326 } from "../proj/EPSG4326.js";
|
||||
import { Node } from "../quadTree/Node.js";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
import { EPSG3857 } from "../proj/EPSG3857.js";
|
||||
|
||||
export class QuadTreeStrategy {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
import { Extent } from "../Extent.js";
|
||||
import { EPSG4326 } from "../proj/EPSG4326.js";
|
||||
import { Node } from "../quadTree/Node.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/renderer/RendererEvents
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Events } from "../Events.js";
|
||||
|
||||
@ -1,78 +1,74 @@
|
||||
/**
|
||||
* @module og/scene/Axes
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Program } from '../webgl/Program.js';
|
||||
import { RenderNode } from './RenderNode.js';
|
||||
|
||||
class Axes extends RenderNode {
|
||||
constructor(size) {
|
||||
super("Axes");
|
||||
|
||||
this.size = size || 100;
|
||||
this.axesBuffer = null;
|
||||
this.axesColorBuffer = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.createAxisBuffer(this.size);
|
||||
this.drawMode = this.renderer.handler.gl.LINES;
|
||||
this.renderer.handler.addProgram(new Program("axesShader", {
|
||||
uniforms: {
|
||||
projectionViewMatrix: 'mat4'
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: 'vec3',
|
||||
aVertexColor: 'vec4'
|
||||
},
|
||||
vertexShader:
|
||||
`attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColor;
|
||||
uniform mat4 projectionViewMatrix;
|
||||
varying vec4 vColor;
|
||||
void main(void) {
|
||||
gl_Position = projectionViewMatrix * vec4(aVertexPosition, 1.0);
|
||||
vColor = aVertexColor;
|
||||
}`,
|
||||
fragmentShader:
|
||||
`precision highp float;
|
||||
varying vec4 vColor;
|
||||
void main(void) {
|
||||
gl_FragColor = vColor;
|
||||
}`
|
||||
}));
|
||||
}
|
||||
|
||||
frame() {
|
||||
|
||||
this.renderer.handler.programs.axesShader.activate().set({
|
||||
projectionViewMatrix: this.renderer.activeCamera.getProjectionViewMatrix(),
|
||||
aVertexPosition: this.axisBuffer,
|
||||
aVertexColor: this.axisColorBuffer
|
||||
});
|
||||
|
||||
this.renderer.handler.programs.axesShader.drawArrays(this.drawMode, this.axisBuffer.numItems);
|
||||
}
|
||||
|
||||
createAxisBuffer(gridSize) {
|
||||
|
||||
var vertices = [
|
||||
0.0, 0.0, 0.0, gridSize - 1, 0.0, 0.0, // x - R
|
||||
0.0, 0.0, 0.0, 0.0, gridSize - 1, 0.0, // y - B
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, gridSize - 1 // z - G
|
||||
];
|
||||
|
||||
var colors = [
|
||||
1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // x - R
|
||||
0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, // y - B
|
||||
0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 // z - G
|
||||
];
|
||||
|
||||
this.axisBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 6);
|
||||
this.axisColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 6);
|
||||
}
|
||||
}
|
||||
|
||||
export { Axes };
|
||||
'use strict';
|
||||
|
||||
import { Program } from '../webgl/Program.js';
|
||||
import { RenderNode } from './RenderNode.js';
|
||||
|
||||
class Axes extends RenderNode {
|
||||
constructor(size) {
|
||||
super("Axes");
|
||||
|
||||
this.size = size || 100;
|
||||
this.axesBuffer = null;
|
||||
this.axesColorBuffer = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.createAxisBuffer(this.size);
|
||||
this.drawMode = this.renderer.handler.gl.LINES;
|
||||
this.renderer.handler.addProgram(new Program("axesShader", {
|
||||
uniforms: {
|
||||
projectionViewMatrix: 'mat4'
|
||||
},
|
||||
attributes: {
|
||||
aVertexPosition: 'vec3',
|
||||
aVertexColor: 'vec4'
|
||||
},
|
||||
vertexShader:
|
||||
`attribute vec3 aVertexPosition;
|
||||
attribute vec4 aVertexColor;
|
||||
uniform mat4 projectionViewMatrix;
|
||||
varying vec4 vColor;
|
||||
void main(void) {
|
||||
gl_Position = projectionViewMatrix * vec4(aVertexPosition, 1.0);
|
||||
vColor = aVertexColor;
|
||||
}`,
|
||||
fragmentShader:
|
||||
`precision highp float;
|
||||
varying vec4 vColor;
|
||||
void main(void) {
|
||||
gl_FragColor = vColor;
|
||||
}`
|
||||
}));
|
||||
}
|
||||
|
||||
frame() {
|
||||
|
||||
this.renderer.handler.programs.axesShader.activate().set({
|
||||
projectionViewMatrix: this.renderer.activeCamera.getProjectionViewMatrix(),
|
||||
aVertexPosition: this.axisBuffer,
|
||||
aVertexColor: this.axisColorBuffer
|
||||
});
|
||||
|
||||
this.renderer.handler.programs.axesShader.drawArrays(this.drawMode, this.axisBuffer.numItems);
|
||||
}
|
||||
|
||||
createAxisBuffer(gridSize) {
|
||||
|
||||
var vertices = [
|
||||
0.0, 0.0, 0.0, gridSize - 1, 0.0, 0.0, // x - R
|
||||
0.0, 0.0, 0.0, 0.0, gridSize - 1, 0.0, // y - B
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, gridSize - 1 // z - G
|
||||
];
|
||||
|
||||
var colors = [
|
||||
1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // x - R
|
||||
0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, // y - B
|
||||
0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 // z - G
|
||||
];
|
||||
|
||||
this.axisBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(vertices), 3, 6);
|
||||
this.axisColorBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(colors), 4, 6);
|
||||
}
|
||||
}
|
||||
|
||||
export { Axes };
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/scene/BaseNode
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/scene/Planet
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { PlanetCamera } from "../camera/PlanetCamera.js";
|
||||
|
||||
@ -1,108 +1,104 @@
|
||||
/**
|
||||
* @module og/scene/SkyBox
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as shaders from '../shaders/skybox.js';
|
||||
import { RenderNode } from './RenderNode.js';
|
||||
|
||||
class SkyBox extends RenderNode {
|
||||
constructor(params) {
|
||||
super("skybox");
|
||||
this.params = params;
|
||||
this.vertexPositionBuffer = null;
|
||||
this.texture = null;
|
||||
}
|
||||
|
||||
static createDefault(RESOURCES_URL) {
|
||||
return new SkyBox({
|
||||
nx: RESOURCES_URL + "skybox/gal/_nx.jpg",
|
||||
px: RESOURCES_URL + "skybox/gal/_px.jpg",
|
||||
py: RESOURCES_URL + "skybox/gal/_py.jpg",
|
||||
ny: RESOURCES_URL + "skybox/gal/_ny.jpg",
|
||||
pz: RESOURCES_URL + "skybox/gal/_pz.jpg",
|
||||
nz: RESOURCES_URL + "skybox/gal/_nz.jpg"
|
||||
});
|
||||
}
|
||||
|
||||
init() {
|
||||
this.renderer.handler.addProgram(shaders.skybox(), true);
|
||||
this.texture = this.renderer.handler.loadCubeMapTexture(this.params);
|
||||
this._createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLES;
|
||||
}
|
||||
|
||||
frame() {
|
||||
var h = this.renderer.handler;
|
||||
var gl = h.gl;
|
||||
var cam = this.renderer.activeCamera;
|
||||
gl.disable(h.gl.DEPTH_TEST);
|
||||
|
||||
h.programs.skybox.activate();
|
||||
var sh = h.programs.skybox._program;
|
||||
var shu = sh.uniforms;
|
||||
gl.uniformMatrix4fv(shu.projectionViewMatrix, false, cam.getProjectionViewMatrix());
|
||||
gl.uniform3fv(shu.pos, cam.eye.toVec());
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.texture);
|
||||
gl.uniform1i(shu.uSampler, 0);
|
||||
var buf = this.vertexPositionBuffer;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
||||
gl.vertexAttribPointer(sh.attributes.aVertexPosition, buf.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.drawArrays(this.drawMode, 0, buf.numItems);
|
||||
h.gl.enable(h.gl.DEPTH_TEST);
|
||||
}
|
||||
|
||||
_createBuffers() {
|
||||
|
||||
var vertices = new Float32Array([
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
-100000000.0, -100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, 100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
-100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, -100000000.0, 100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
100000000.0, 100000000.0, -100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
-100000000.0, 100000000.0, 100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
|
||||
-100000000.0, -100000000.0, -100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
100000000.0, -100000000.0, 100000000.0
|
||||
]);
|
||||
|
||||
this.vertexPositionBuffer = this.renderer.handler.createArrayBuffer(vertices, 3, vertices.length / 3);
|
||||
}
|
||||
}
|
||||
|
||||
export { SkyBox };
|
||||
'use strict';
|
||||
|
||||
import * as shaders from '../shaders/skybox.js';
|
||||
import { RenderNode } from './RenderNode.js';
|
||||
|
||||
class SkyBox extends RenderNode {
|
||||
constructor(params) {
|
||||
super("skybox");
|
||||
this.params = params;
|
||||
this.vertexPositionBuffer = null;
|
||||
this.texture = null;
|
||||
}
|
||||
|
||||
static createDefault(RESOURCES_URL) {
|
||||
return new SkyBox({
|
||||
nx: RESOURCES_URL + "skybox/gal/_nx.jpg",
|
||||
px: RESOURCES_URL + "skybox/gal/_px.jpg",
|
||||
py: RESOURCES_URL + "skybox/gal/_py.jpg",
|
||||
ny: RESOURCES_URL + "skybox/gal/_ny.jpg",
|
||||
pz: RESOURCES_URL + "skybox/gal/_pz.jpg",
|
||||
nz: RESOURCES_URL + "skybox/gal/_nz.jpg"
|
||||
});
|
||||
}
|
||||
|
||||
init() {
|
||||
this.renderer.handler.addProgram(shaders.skybox(), true);
|
||||
this.texture = this.renderer.handler.loadCubeMapTexture(this.params);
|
||||
this._createBuffers();
|
||||
this.drawMode = this.renderer.handler.gl.TRIANGLES;
|
||||
}
|
||||
|
||||
frame() {
|
||||
var h = this.renderer.handler;
|
||||
var gl = h.gl;
|
||||
var cam = this.renderer.activeCamera;
|
||||
gl.disable(h.gl.DEPTH_TEST);
|
||||
|
||||
h.programs.skybox.activate();
|
||||
var sh = h.programs.skybox._program;
|
||||
var shu = sh.uniforms;
|
||||
gl.uniformMatrix4fv(shu.projectionViewMatrix, false, cam.getProjectionViewMatrix());
|
||||
gl.uniform3fv(shu.pos, cam.eye.toVec());
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.texture);
|
||||
gl.uniform1i(shu.uSampler, 0);
|
||||
var buf = this.vertexPositionBuffer;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
||||
gl.vertexAttribPointer(sh.attributes.aVertexPosition, buf.itemSize, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.drawArrays(this.drawMode, 0, buf.numItems);
|
||||
h.gl.enable(h.gl.DEPTH_TEST);
|
||||
}
|
||||
|
||||
_createBuffers() {
|
||||
|
||||
var vertices = new Float32Array([
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
-100000000.0, -100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
-100000000.0, 100000000.0, 100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
-100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, -100000000.0, 100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
100000000.0, 100000000.0, -100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
100000000.0, 100000000.0, 100000000.0,
|
||||
-100000000.0, 100000000.0, 100000000.0,
|
||||
-100000000.0, 100000000.0, -100000000.0,
|
||||
|
||||
-100000000.0, -100000000.0, -100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
100000000.0, -100000000.0, -100000000.0,
|
||||
-100000000.0, -100000000.0, 100000000.0,
|
||||
100000000.0, -100000000.0, 100000000.0
|
||||
]);
|
||||
|
||||
this.vertexPositionBuffer = this.renderer.handler.createArrayBuffer(vertices, 3, vertices.length / 3);
|
||||
}
|
||||
}
|
||||
|
||||
export { SkyBox };
|
||||
|
||||
@ -1,226 +1,230 @@
|
||||
'use strict';
|
||||
|
||||
import { N, W, S, E } from '../quadTree/quadTree.js';
|
||||
|
||||
function NewIndexesTypedArray(arr) {
|
||||
return new Uint32Array(arr);
|
||||
}
|
||||
|
||||
function createCenterBodyIndexes(size) {
|
||||
|
||||
let indexes = [];
|
||||
|
||||
var i0 = 1,
|
||||
j0 = 1;
|
||||
|
||||
var i1 = 1,
|
||||
j1 = 1;
|
||||
|
||||
var ind1, ind2, nr;
|
||||
for (var i = i0; i < size - 1 - i1; i++) {
|
||||
for (var j = j0; j < size - j1; j++) {
|
||||
ind1 = i * size + j;
|
||||
nr = (i + 1) * size;
|
||||
ind2 = nr + j;
|
||||
indexes.push(ind1, ind2);
|
||||
}
|
||||
indexes.push(ind2, nr + j0);
|
||||
}
|
||||
indexes.push(indexes[indexes.length - 1], size * size - size);
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createWestNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var b = size * size - size;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = b - size * i - size + 1,
|
||||
lind = b - size * k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size);
|
||||
indexes.push(0);
|
||||
}
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createNorthNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size + i + 1,
|
||||
lind = k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size - 2);
|
||||
indexes.push(size - 1);
|
||||
}
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createEastNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size * (i + 1) + size - 2,
|
||||
lind = size + size * k - 1;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * (size - 1) - 1);
|
||||
indexes.push(size * size - 1);
|
||||
}
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createSouthNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
var rb = size * (size - 1) - 2;
|
||||
var lb = size * size - 1;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = rb - i,
|
||||
lind = lb - k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * size - size + 1);
|
||||
}
|
||||
indexes.push(size * size - size);
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function initIndexesBodySkirts(pow) {
|
||||
var table = [];
|
||||
|
||||
table[N] = [];
|
||||
table[W] = [];
|
||||
table[S] = [];
|
||||
table[E] = [];
|
||||
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i),
|
||||
d1 = d + 1;
|
||||
|
||||
table[N][i] = [];
|
||||
table[W][i] = [];
|
||||
table[S][i] = [];
|
||||
table[E][i] = [];
|
||||
|
||||
for (var j = 0; j <= pow; j++) {
|
||||
var dd = Math.pow(2, j);
|
||||
table[W][i][j] = createWestNeighborSkirt(d1, dd);
|
||||
table[N][i][j] = createNorthNeighborSkirt(d1, dd);
|
||||
table[E][i][j] = createEastNeighborSkirt(d1, dd);
|
||||
table[S][i][j] = createSouthNeighborSkirt(d1, dd);
|
||||
|
||||
}
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
function initIndexBodiesTable(pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[i] = createCenterBodyIndexes(d + 1);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
function createTextureCoords(size) {
|
||||
var texCoords = new Uint16Array((size + 1) * (size + 1) * 2);
|
||||
let k = 0;
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
texCoords[k++] = j / size * 0xFFFF;
|
||||
texCoords[k++] = i / size * 0xFFFF;
|
||||
}
|
||||
}
|
||||
return texCoords;
|
||||
}
|
||||
|
||||
class SegmentHelper {
|
||||
constructor(maxGridSize = 0) {
|
||||
this._maxGridSize = maxGridSize;
|
||||
}
|
||||
|
||||
get maxGridSize() {
|
||||
return this._maxGridSize;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.centerIndexesTable = initIndexBodiesTable(this._maxGridSize);
|
||||
this.skirtsIndexesTable = initIndexesBodySkirts(this._maxGridSize);
|
||||
}
|
||||
|
||||
setMaxGridSize(gridSize) {
|
||||
this._maxGridSize = gridSize;
|
||||
this.init();
|
||||
}
|
||||
|
||||
createSegmentIndexes(size, sidesSizes) {
|
||||
if (size) {
|
||||
let c = this.centerIndexesTable[size],
|
||||
w = this.skirtsIndexesTable[W][size][sidesSizes[W]],
|
||||
n = this.skirtsIndexesTable[N][size][sidesSizes[N]],
|
||||
e = this.skirtsIndexesTable[E][size][sidesSizes[E]],
|
||||
s = this.skirtsIndexesTable[S][size][sidesSizes[S]];
|
||||
|
||||
let indexes = NewIndexesTypedArray(c.length + w.length + n.length + e.length + s.length);
|
||||
|
||||
indexes.set(c, 0);
|
||||
indexes.set(w, c.length);
|
||||
indexes.set(n, c.length + w.length);
|
||||
indexes.set(e, c.length + w.length + n.length);
|
||||
indexes.set(s, c.length + w.length + n.length + e.length);
|
||||
|
||||
return indexes;
|
||||
} else {
|
||||
return NewIndexesTypedArray([0, 2, 1, 3]);
|
||||
}
|
||||
}
|
||||
|
||||
initTextureCoordsTable(pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[i] = createTextureCoords(d);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
let instance = new SegmentHelper();
|
||||
|
||||
export function getInstance() {
|
||||
return instance;
|
||||
/**
|
||||
* @module og/segment/SegmentHelper
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { N, W, S, E } from '../quadTree/quadTree.js';
|
||||
|
||||
function NewIndexesTypedArray(arr) {
|
||||
return new Uint32Array(arr);
|
||||
}
|
||||
|
||||
function createCenterBodyIndexes(size) {
|
||||
|
||||
let indexes = [];
|
||||
|
||||
var i0 = 1,
|
||||
j0 = 1;
|
||||
|
||||
var i1 = 1,
|
||||
j1 = 1;
|
||||
|
||||
var ind1, ind2, nr;
|
||||
for (var i = i0; i < size - 1 - i1; i++) {
|
||||
for (var j = j0; j < size - j1; j++) {
|
||||
ind1 = i * size + j;
|
||||
nr = (i + 1) * size;
|
||||
ind2 = nr + j;
|
||||
indexes.push(ind1, ind2);
|
||||
}
|
||||
indexes.push(ind2, nr + j0);
|
||||
}
|
||||
indexes.push(indexes[indexes.length - 1], size * size - size);
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createWestNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var b = size * size - size;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = b - size * i - size + 1,
|
||||
lind = b - size * k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size);
|
||||
indexes.push(0);
|
||||
}
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createNorthNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size + i + 1,
|
||||
lind = k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size - 2);
|
||||
indexes.push(size - 1);
|
||||
}
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createEastNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = size * (i + 1) + size - 2,
|
||||
lind = size + size * k - 1;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * (size - 1) - 1);
|
||||
indexes.push(size * size - 1);
|
||||
}
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function createSouthNeighborSkirt(size, deltaGr) {
|
||||
let indexes = [];
|
||||
var grCount = (size - 1) / deltaGr;
|
||||
var k = 0;
|
||||
var rb = size * (size - 1) - 2;
|
||||
var lb = size * size - 1;
|
||||
for (var i = 0; i < size - 2; i++) {
|
||||
if (i % grCount === 0) {
|
||||
k = i;
|
||||
}
|
||||
var rind = rb - i,
|
||||
lind = lb - k;
|
||||
indexes.push(lind, rind);
|
||||
}
|
||||
|
||||
if (deltaGr === (size - 1)) {
|
||||
indexes.push(size * size - size + 1);
|
||||
}
|
||||
indexes.push(size * size - size);
|
||||
|
||||
return NewIndexesTypedArray(indexes);
|
||||
}
|
||||
|
||||
function initIndexesBodySkirts(pow) {
|
||||
var table = [];
|
||||
|
||||
table[N] = [];
|
||||
table[W] = [];
|
||||
table[S] = [];
|
||||
table[E] = [];
|
||||
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i),
|
||||
d1 = d + 1;
|
||||
|
||||
table[N][i] = [];
|
||||
table[W][i] = [];
|
||||
table[S][i] = [];
|
||||
table[E][i] = [];
|
||||
|
||||
for (var j = 0; j <= pow; j++) {
|
||||
var dd = Math.pow(2, j);
|
||||
table[W][i][j] = createWestNeighborSkirt(d1, dd);
|
||||
table[N][i][j] = createNorthNeighborSkirt(d1, dd);
|
||||
table[E][i][j] = createEastNeighborSkirt(d1, dd);
|
||||
table[S][i][j] = createSouthNeighborSkirt(d1, dd);
|
||||
|
||||
}
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
function initIndexBodiesTable(pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[i] = createCenterBodyIndexes(d + 1);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
function createTextureCoords(size) {
|
||||
var texCoords = new Uint16Array((size + 1) * (size + 1) * 2);
|
||||
let k = 0;
|
||||
for (var i = 0; i <= size; i++) {
|
||||
for (var j = 0; j <= size; j++) {
|
||||
texCoords[k++] = j / size * 0xFFFF;
|
||||
texCoords[k++] = i / size * 0xFFFF;
|
||||
}
|
||||
}
|
||||
return texCoords;
|
||||
}
|
||||
|
||||
class SegmentHelper {
|
||||
constructor(maxGridSize = 0) {
|
||||
this._maxGridSize = maxGridSize;
|
||||
}
|
||||
|
||||
get maxGridSize() {
|
||||
return this._maxGridSize;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.centerIndexesTable = initIndexBodiesTable(this._maxGridSize);
|
||||
this.skirtsIndexesTable = initIndexesBodySkirts(this._maxGridSize);
|
||||
}
|
||||
|
||||
setMaxGridSize(gridSize) {
|
||||
this._maxGridSize = gridSize;
|
||||
this.init();
|
||||
}
|
||||
|
||||
createSegmentIndexes(size, sidesSizes) {
|
||||
if (size) {
|
||||
let c = this.centerIndexesTable[size],
|
||||
w = this.skirtsIndexesTable[W][size][sidesSizes[W]],
|
||||
n = this.skirtsIndexesTable[N][size][sidesSizes[N]],
|
||||
e = this.skirtsIndexesTable[E][size][sidesSizes[E]],
|
||||
s = this.skirtsIndexesTable[S][size][sidesSizes[S]];
|
||||
|
||||
let indexes = NewIndexesTypedArray(c.length + w.length + n.length + e.length + s.length);
|
||||
|
||||
indexes.set(c, 0);
|
||||
indexes.set(w, c.length);
|
||||
indexes.set(n, c.length + w.length);
|
||||
indexes.set(e, c.length + w.length + n.length);
|
||||
indexes.set(s, c.length + w.length + n.length + e.length);
|
||||
|
||||
return indexes;
|
||||
} else {
|
||||
return NewIndexesTypedArray([0, 2, 1, 3]);
|
||||
}
|
||||
}
|
||||
|
||||
initTextureCoordsTable(pow) {
|
||||
var table = [];
|
||||
for (var i = 0; i <= pow; i++) {
|
||||
var d = Math.pow(2, i);
|
||||
table[i] = createTextureCoords(d);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
let instance = new SegmentHelper();
|
||||
|
||||
export function getInstance() {
|
||||
return instance;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @module og/shaders/drawnode
|
||||
* @module og/shaders/geoObject
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/terrainProvider/EmptyTerrain
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { binarySearchFast } from "../utils/shared.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/utils/FontAtlas
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Deferred } from '../Deferred.js';
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/utils/NormalMapCreator
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Lock } from "../Lock.js";
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/utils/VectorTileCreator
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { doubleToTwoFloats2 } from '../math/coder.js';
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* @module og/webgl/Framebuffer
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { ImageCanvas } from "../ImageCanvas.js";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user