mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
Merge branch 'openglobus:master' into more-unit-tests2
This commit is contained in:
commit
3c7e319422
@ -11,14 +11,14 @@ import { LonLat } from './LonLat.js';
|
||||
/**
|
||||
* Represents geographical coordinates extent.
|
||||
* @class
|
||||
* @param {og.LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {og.LonLat} [ne] - North East extent corner coordiantes.
|
||||
* @param {LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {LonLat} [ne] - North East extent corner coordiantes.
|
||||
*/
|
||||
export class Extent {
|
||||
|
||||
/**
|
||||
* @param {og.LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {og.LonLat} [ne] - North East extent corner coordiantes.
|
||||
* @param {LonLat} [sw] - South West extent corner coordiantes.
|
||||
* @param {LonLat} [ne] - North East extent corner coordiantes.
|
||||
*/
|
||||
constructor(sw, ne) {
|
||||
/**
|
||||
@ -62,8 +62,8 @@ export class Extent {
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {[og.LonLat]} arr - Coordinate array.
|
||||
* @return {og.Extent} Extent object.
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinates(arr) {
|
||||
let lonmin = math.MAX, lonmax = math.MIN,
|
||||
@ -81,7 +81,7 @@ export class Extent {
|
||||
/**
|
||||
* Creates bound extent instance by coordinate array.
|
||||
* @static
|
||||
* @param {[[number,number]]} arr - Coordinate array.
|
||||
* @param {Array.<Array<number>>} arr - Coordinate array. (exactly 2 entries)
|
||||
* @return {og.Extent} Extent object.
|
||||
*/
|
||||
static createByCoordinatesArr(arr) {
|
||||
@ -126,7 +126,7 @@ export class Extent {
|
||||
/**
|
||||
* Sets current bounding extent object by coordinate array.
|
||||
* @public
|
||||
* @param {[og.LonLat]} arr - Coordinate array.
|
||||
* @param {Array.<LonLat>} arr - Coordinate array.
|
||||
* @return {og.Extent} Current extent.
|
||||
*/
|
||||
setByCoordinates(arr) {
|
||||
@ -291,7 +291,7 @@ export class Extent {
|
||||
* Gets cartesian bounding bounds of the current ellipsoid.
|
||||
* @public
|
||||
* @param {og.Ellipsoid} ellipsoid - Ellipsoid.
|
||||
* @return {[number,number,number,number,number,number]} Cartesian 3d coordinate array.
|
||||
* @return {Array.<number>} Cartesian 3d coordinate array. (exactly 6 entries)
|
||||
*/
|
||||
getCartesianBounds(ellipsoid) {
|
||||
let xmin = math.MAX, xmax = math.MIN, ymin = math.MAX,
|
||||
|
||||
@ -64,6 +64,7 @@ const PLANET_NAME_PREFIX = "globus_planet_";
|
||||
* @param {boolean} [options.useSpecularTexture] - use specular water mask
|
||||
* @param {boolean} [options.useNightTexture] - show night cities
|
||||
*/
|
||||
|
||||
class Globe {
|
||||
constructor(options) {
|
||||
// Canvas creation
|
||||
@ -182,12 +183,12 @@ class Globe {
|
||||
options.useEarthNavigation
|
||||
? new EarthNavigation()
|
||||
: new MouseNavigation({
|
||||
minSlope: options.minSlope
|
||||
}),
|
||||
minSlope: options.minSlope
|
||||
}),
|
||||
new TouchNavigation(),
|
||||
new EarthCoordinates(),
|
||||
new ScaleControl(),
|
||||
new CompassButton()
|
||||
new CompassButton(options)
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ export class LonLat {
|
||||
* Creates coordinates array.
|
||||
* @static
|
||||
* @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
|
||||
* @return{Array.<og.LonLat>} the same coordinates array but each element is LonLat instance.
|
||||
* @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
|
||||
*/
|
||||
static join(arr) {
|
||||
var res = [];
|
||||
@ -73,7 +73,7 @@ export class LonLat {
|
||||
* Creates an object by coordinate array.
|
||||
* @static
|
||||
* @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
static createFromArray(arr) {
|
||||
return new LonLat(arr[0], arr[1], arr[2]);
|
||||
@ -85,7 +85,7 @@ export class LonLat {
|
||||
* @param {number} lon - Degrees longitude.
|
||||
* @param {number} lat - Degrees latitude.
|
||||
* @param {number} [height] - Height.
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
static forwardMercator(lon, lat, height) {
|
||||
return new LonLat(lon * mercator.POLE_BY_180,
|
||||
@ -99,7 +99,7 @@ export class LonLat {
|
||||
* @param {number} x - Mercator longitude.
|
||||
* @param {number} y - Mercator latitude.
|
||||
* @param {number} [height] - Height.
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
static inverseMercator(x, y, height) {
|
||||
return new LonLat(x * mercator.INV_POLE_BY_180,
|
||||
@ -113,7 +113,7 @@ export class LonLat {
|
||||
* @param {number} [lon] - Longitude.
|
||||
* @param {number} [lat] - Latitude.
|
||||
* @param {number} [height] - Height.
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
set(lon, lat, height) {
|
||||
this.lon = lon || 0;
|
||||
@ -125,8 +125,8 @@ export class LonLat {
|
||||
/**
|
||||
* Copy coordinates.
|
||||
* @public
|
||||
* @param {og.LonLat} [lonLat] - Coordinates to copy.
|
||||
* @returns {og.LonLat} -
|
||||
* @param {LonLat} [lonLat] - Coordinates to copy.
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
copy(lonLat) {
|
||||
this.lon = lonLat.lon;
|
||||
@ -138,7 +138,7 @@ export class LonLat {
|
||||
/**
|
||||
* Clone the coordiante.
|
||||
* @public
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
clone() {
|
||||
return new LonLat(this.lon, this.lat, this.height);
|
||||
@ -147,7 +147,7 @@ export class LonLat {
|
||||
/**
|
||||
* Converts to mercator coordinates.
|
||||
* @public
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
forwardMercator() {
|
||||
return LonLat.forwardMercator(this.lon, this.lat, this.height);
|
||||
@ -168,7 +168,7 @@ export class LonLat {
|
||||
/**
|
||||
* Converts from mercator coordinates.
|
||||
* @public
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
inverseMercator() {
|
||||
return LonLat.inverseMercator(this.lon, this.lat, this.height);
|
||||
@ -177,7 +177,7 @@ export class LonLat {
|
||||
/**
|
||||
* Compares coordinates.
|
||||
* @public
|
||||
* @param {og.LonLat} b - Coordinate to compare with.
|
||||
* @param {LonLat} b - Coordinate to compare with.
|
||||
* @returns {boolean} -
|
||||
*/
|
||||
equal(b) {
|
||||
|
||||
@ -13,6 +13,11 @@ import { Vec3 } from '../math/Vec3.js';
|
||||
* @param {og.Vec3} [center] - Bounding sphere coordiantes.
|
||||
*/
|
||||
class Sphere {
|
||||
/**
|
||||
*
|
||||
* @param {number} radius
|
||||
* @param {Vec3} center
|
||||
*/
|
||||
constructor(radius, center) {
|
||||
|
||||
/**
|
||||
|
||||
@ -71,14 +71,14 @@ class PlanetCamera extends Camera {
|
||||
/**
|
||||
* Current geographical degree position.
|
||||
* @protected
|
||||
* @type {og.LonLat}
|
||||
* @type {LonLat}
|
||||
*/
|
||||
this._lonLat = this.planet.ellipsoid.cartesianToLonLat(this.eye);
|
||||
|
||||
/**
|
||||
* Current geographical mercator position.
|
||||
* @protected
|
||||
* @type {og.LonLat}
|
||||
* @type {LonLat}
|
||||
*/
|
||||
this._lonLatMerc = this._lonLat.forwardMercator();
|
||||
|
||||
@ -107,7 +107,7 @@ class PlanetCamera extends Camera {
|
||||
* Coordinates that depends on what segment class we are fling over.
|
||||
* It can be WGS84 or Mercator coordinates. Gets in og.quadTree.Node
|
||||
* @protected
|
||||
* @type {og.LonLat}
|
||||
* @type {LonLat}
|
||||
*/
|
||||
this._insideSegmentPosition = new LonLat();
|
||||
|
||||
@ -176,8 +176,8 @@ class PlanetCamera extends Camera {
|
||||
/**
|
||||
* Places camera to view to the geographical point.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - New camera and camera view position.
|
||||
* @param {og.LonLat} [lookLonLat] - Look up coordinates.
|
||||
* @param {LonLat} lonlat - New camera and camera view position.
|
||||
* @param {LonLat} [lookLonLat] - Look up coordinates.
|
||||
* @param {og.Vec3} [up] - Camera UP vector. Default (0,1,0)
|
||||
*/
|
||||
setLonLat(lonlat, lookLonLat, up) {
|
||||
@ -193,7 +193,7 @@ class PlanetCamera extends Camera {
|
||||
/**
|
||||
* Returns camera geographical position.
|
||||
* @public
|
||||
* @returns {og.LonLat}
|
||||
* @returns {LonLat}
|
||||
*/
|
||||
getLonLat() {
|
||||
return this._lonLat;
|
||||
@ -452,7 +452,7 @@ class PlanetCamera extends Camera {
|
||||
/**
|
||||
* Flies to the geo coordiantes.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - Finish coordinates.
|
||||
* @param {LonLat} lonlat - Finish coordinates.
|
||||
* @param {og.Vec3} [look] - Camera LOOK in the end of flying. Default - (0,0,0)
|
||||
* @param {og.Vec3} [up] - Camera UP vector in the end of flying. Default - (0,1,0)
|
||||
* @param {Number} [ampl] - Altitude amplitude factor.
|
||||
|
||||
@ -93,13 +93,15 @@ class CompassButton extends Control {
|
||||
|
||||
this.planet = null;
|
||||
|
||||
this.compassSvg = options.compassSvg || svg;
|
||||
|
||||
this._heading = null;
|
||||
|
||||
this._svg = null;
|
||||
}
|
||||
|
||||
oninit() {
|
||||
var btnEl = parseHTML(`<div class="og-compass-button">${svg}</div>`)[0];
|
||||
var btnEl = parseHTML(`<div class="og-compass-button">${this.compassSvg}</div>`)[0];
|
||||
|
||||
this._svg = btnEl.querySelector("svg");
|
||||
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
import * as math from "../math.js";
|
||||
import { Control } from "./Control.js";
|
||||
import { input } from "../input/input.js";
|
||||
import { Key } from "../Lock.js";
|
||||
import { Sphere } from "../bv/Sphere.js";
|
||||
import { LonLat } from "../LonLat.js";
|
||||
import { Mat4 } from "../math/Mat4.js";
|
||||
import { Quat } from "../math/Quat.js";
|
||||
import { Ray } from "../math/Ray.js";
|
||||
import { Sphere } from "../bv/Sphere.js";
|
||||
import { Vec3 } from "../math/Vec3.js";
|
||||
import { Control } from "./Control.js";
|
||||
|
||||
class EarthNavigation extends Control {
|
||||
constructor(options) {
|
||||
|
||||
@ -52,9 +52,9 @@ class Ellipsoid {
|
||||
|
||||
/**
|
||||
* Returns the midpoint between two points on the great circle.
|
||||
* @param {og.LonLat} lonLat1 - Longitude/latitude of first point.
|
||||
* @param {og.LonLat} lonLat2 - Longitude/latitude of second point.
|
||||
* @return {og.LonLat} Midpoint between points.
|
||||
* @param {LonLat} lonLat1 - Longitude/latitude of first point.
|
||||
* @param {LonLat} lonLat2 - Longitude/latitude of second point.
|
||||
* @return {LonLat} Midpoint between points.
|
||||
*/
|
||||
static getMiddlePointOnGreatCircle(lonLat1, lonLat2) {
|
||||
var f1 = lonLat1.lat * math.RADIANS,
|
||||
@ -76,10 +76,10 @@ class Ellipsoid {
|
||||
|
||||
/**
|
||||
* Returns the point at given fraction between two points on the great circle.
|
||||
* @param {og.LonLat} lonLat1 - Longitude/Latitude of source point.
|
||||
* @param {og.LonLat} lonLat2 - Longitude/Latitude of destination point.
|
||||
* @param {LonLat} lonLat1 - Longitude/Latitude of source point.
|
||||
* @param {LonLat} lonLat2 - Longitude/Latitude of destination point.
|
||||
* @param {number} fraction - Fraction between the two points (0 = source point, 1 = destination point).
|
||||
* @returns {og.LonLat} Intermediate point between points.
|
||||
* @returns {LonLat} Intermediate point between points.
|
||||
*/
|
||||
static getIntermediatePointOnGreatCircle(lonLat1, lonLat2, fraction) {
|
||||
var f1 = lonLat1.lat * math.RADIANS, l1 = lonLat1.lon * math.RADIANS;
|
||||
@ -129,8 +129,8 @@ class Ellipsoid {
|
||||
|
||||
/**
|
||||
* Returns the (initial) bearing from source to destination point on the great circle.
|
||||
* @param {og.LonLat} lonLat1 - Longitude/latitude of source point.
|
||||
* @param {og.LonLat} lonLat2 - Longitude/latitude of destination point.
|
||||
* @param {LonLat} lonLat1 - Longitude/latitude of source point.
|
||||
* @param {LonLat} lonLat2 - Longitude/latitude of destination point.
|
||||
* @return {number} Initial bearing in degrees from north.
|
||||
*/
|
||||
static getInitialBearing(lonLat1, lonLat2) {
|
||||
@ -146,11 +146,11 @@ class Ellipsoid {
|
||||
|
||||
/**
|
||||
* Returns the point of intersection of two paths defined by point and bearing.
|
||||
* @param {og.LonLat} p1 - First point.
|
||||
* @param {LonLat} p1 - First point.
|
||||
* @param {number} brng1 - Initial bearing from first point.
|
||||
* @param {og.LonLat} p2 - Second point.
|
||||
* @param {LonLat} p2 - Second point.
|
||||
* @param {number} brng2 - Initial bearing from second point.
|
||||
* @return {og.LonLat|null} Destination point (null if no unique intersection defined).
|
||||
* @return {LonLat|null} Destination point (null if no unique intersection defined).
|
||||
*/
|
||||
static intersection(p1, brng1, p2, brng2) {
|
||||
var f1 = p1.lat * math.RADIANS,
|
||||
@ -195,8 +195,8 @@ class Ellipsoid {
|
||||
/**
|
||||
* Returns final bearing arriving at destination destination point from lonLat1 point; the final bearing
|
||||
* will differ from the initial bearing by varying degrees according to distance and latitude.
|
||||
* @param {og.LonLat} lonLat1 - Longitude/latitude of source point.
|
||||
* @param {og.LonLat} lonLat2 - Longitude/latitude of destination point.
|
||||
* @param {LonLat} lonLat1 - Longitude/latitude of source point.
|
||||
* @param {LonLat} lonLat2 - Longitude/latitude of destination point.
|
||||
* @return {number} Final bearing in degrees from north.
|
||||
*/
|
||||
static getFinalBearing(lonLat1, lonLat2) {
|
||||
@ -225,7 +225,7 @@ class Ellipsoid {
|
||||
/**
|
||||
* Gets cartesian ECEF from Wgs84 geodetic coordiantes.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - Degrees geodetic coordiantes.
|
||||
* @param {LonLat} lonlat - Degrees geodetic coordiantes.
|
||||
* @returns {og.Vec3} -
|
||||
*/
|
||||
lonLatToCartesian(lonlat) {
|
||||
@ -246,7 +246,7 @@ class Ellipsoid {
|
||||
/**
|
||||
* Gets cartesian ECEF from Wgs84 geodetic coordiantes.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - Degrees geodetic coordiantes.
|
||||
* @param {LonLat} lonlat - Degrees geodetic coordiantes.
|
||||
* @param {og.Vec3} res - Output result.
|
||||
* @returns {og.Vec3} -
|
||||
*/
|
||||
@ -293,7 +293,7 @@ class Ellipsoid {
|
||||
* Gets Wgs84 geodetic coordiantes from cartesian ECEF.
|
||||
* @public
|
||||
* @param {og.Vec3} cartesian - Cartesian coordinates.
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
cartesianToLonLat(cartesian) {
|
||||
var x = cartesian.z, y = cartesian.x, z = cartesian.y;
|
||||
@ -344,8 +344,8 @@ class Ellipsoid {
|
||||
|
||||
/**
|
||||
* Returns the distance from one point to another(using haversine formula) on the great circle.
|
||||
* @param {og.LonLat} lonLat1 - Longitude/latitude of source point.
|
||||
* @param {og.LonLat} lonLat2 - Longitude/latitude of destination point.
|
||||
* @param {LonLat} lonLat1 - Longitude/latitude of source point.
|
||||
* @param {LonLat} lonLat2 - Longitude/latitude of destination point.
|
||||
* @return {number} Distance between points.
|
||||
*/
|
||||
getGreatCircleDistance(lonLat1, lonLat2) {
|
||||
|
||||
@ -26,7 +26,7 @@ import { Vec3 } from '../math/Vec3.js';
|
||||
* @param {Object} [options] - Entity options:
|
||||
* @param {string} [options.name] - A human readable name to display to users. It does not have to be unique.
|
||||
* @param {og.Vec3|Array.<number>} [options.cartesian] - Spatial entities like billboard, label, sphere etc. cartesian position.
|
||||
* @param {og.LonLat} [options.lonlat] - Geodetic coordiantes for an entities like billboard, label, sphere etc.
|
||||
* @param {LonLat} [options.lonlat] - Geodetic coordiantes for an entities like billboard, label, sphere etc.
|
||||
* @param {boolean} [options.aground] - True for entities that have to be placed on the relief.
|
||||
* @param {boolean} [options.visibility] - Entity visibility.
|
||||
* @param {*} [options.billboard] - Billboard options(see {@link og.Billboard}).
|
||||
@ -91,14 +91,14 @@ class Entity {
|
||||
/**
|
||||
* Geodetic entity coordiantes.
|
||||
* @protected
|
||||
* @type {og.LonLat}
|
||||
* @type {LonLat}
|
||||
*/
|
||||
this._lonlat = utils.createLonLat(options.lonlat);
|
||||
|
||||
/**
|
||||
* World Mercator entity coordinates.
|
||||
* @protected
|
||||
* @type {og.LonLat}
|
||||
* @type {LonLat}
|
||||
*/
|
||||
this._lonlatMerc = null;
|
||||
|
||||
@ -405,7 +405,7 @@ class Entity {
|
||||
/**
|
||||
* Gets entity geodetic coordinates.
|
||||
* @public
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
getLonLat() {
|
||||
return this._lonlat.clone();
|
||||
@ -414,7 +414,7 @@ class Entity {
|
||||
/**
|
||||
* Sets geodetic coordinates of the entity point object.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - WGS84 coordinates.
|
||||
* @param {LonLat} lonlat - WGS84 coordinates.
|
||||
*/
|
||||
setLonLat(lonlat) {
|
||||
var l = this._lonlat;
|
||||
|
||||
@ -175,7 +175,7 @@ class EntityCollection {
|
||||
* Second index - far distance to the entity, when entity becomes zero scale.
|
||||
* Third index - far distance to the entity, when entity becomes invisible.
|
||||
* @public
|
||||
* @type {[number,number,number]}
|
||||
* @type {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
this.scaleByDistance = options.scaleByDistance || [math.MAX32, math.MAX32, math.MAX32];
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ class Geometry {
|
||||
* Returns geometry feature extent.
|
||||
@static
|
||||
@param {Object} geometryObj - GeoJSON style geometry feature.
|
||||
@param {og.LonLat[]} outCoordinates - Geometry feature coordinates clone.
|
||||
@param {LonLat[]} outCoordinates - Geometry feature coordinates clone.
|
||||
@returns {og.Extent} -
|
||||
*/
|
||||
static getExtent(geometryObj, outCoordinates) {
|
||||
|
||||
@ -15,7 +15,7 @@ const PICKING_COLOR_BUFFER = 2;
|
||||
* PointCloud object.
|
||||
* @class
|
||||
* @param {*} [options] - Point cloud options:
|
||||
* @param {Array.<Array.<number,number,number,number,number,number,number,*>>} [options.points] - Points cartesian coordinates array,
|
||||
* @param {Array.<Array.<number>>} [options.points] - Points cartesian coordinates array,
|
||||
* where first three is cartesian coordinates, next fourth is a RGBA color, and last is an point properties.
|
||||
* @param {number} [options.pointSize] - Point screen size in pixels.
|
||||
* @param {number} [options.pickingDistance] - Point border picking size in screen pixels.
|
||||
@ -208,7 +208,7 @@ class PointCloud {
|
||||
/**
|
||||
* Adds points to render.
|
||||
* @public
|
||||
* @param {[[number,number,number,number,number,number,number,*]]} points - Point cloud array.
|
||||
* @param {Array.<Array<number>>} points - Point cloud array.
|
||||
* @example
|
||||
* var points = [[0, 0, 0, 255, 255, 255, 255, { 'name': 'White point' }], [100, 100, 0, 255, 0, 0, 255, { 'name': 'Red point' }]];
|
||||
*/
|
||||
|
||||
@ -36,9 +36,9 @@ const A = 3;
|
||||
* @param {Boolean} [options.opacity] - Line opacity.
|
||||
* @param {Boolean} [options.visibility] - Polyline visibility. True default.
|
||||
* @param {Boolean} [options.isClosed] - Closed geometry type identificator.
|
||||
* @param {Array.<Array.<number,number,number>>} [options.pathLonLat] - Polyline geodetic coordinates array.
|
||||
* @param {Array.<Array.<number,number,number>>} [options.path3v] - LinesString cartesian coordinates array. [[0,0,0], [1,1,1],...]
|
||||
* @param {Array.<Array.<number,number,number, number>>} [options.pathColors] - Coordinates color. [[1,0,0,1], [0,1,0,1],...] for right and green colors.
|
||||
* @param {Array.<Array.<number>>} [options.pathLonLat] - Polyline geodetic coordinates array. [[0,0,0], [1,1,1],...]
|
||||
* @param {Array.<Array.<number>>} [options.path3v] - LinesString cartesian coordinates array. [[0,0,0], [1,1,1],...]
|
||||
* @param {Array.<Array.<number>>} [options.pathColors] - Coordinates color. [[1,0,0,1], [0,1,0,1],...] for right and green colors.
|
||||
*/
|
||||
class Polyline {
|
||||
constructor(options) {
|
||||
@ -64,7 +64,7 @@ class Polyline {
|
||||
/**
|
||||
* Polyline RGBA color.
|
||||
* @public
|
||||
* @type {Array<Number,Number,Number,Number>}
|
||||
* @type {Array<number>} - (exactly 4 entries)
|
||||
*/
|
||||
this._defaultColor = htmlColorToFloat32Array(
|
||||
options.color || DEFAULT_COLOR,
|
||||
@ -97,14 +97,14 @@ class Polyline {
|
||||
/**
|
||||
* Polyline geodetic degrees coordiantes.
|
||||
* @private
|
||||
* @type {Array.<og.LonLat>}
|
||||
* @type {Array.<LonLat>}
|
||||
*/
|
||||
this._pathLonLat = [];
|
||||
|
||||
/**
|
||||
* Polyline geodetic mercator coordinates.
|
||||
* @private
|
||||
* @type {Array.<og.LonLat>}
|
||||
* @type {Array.<LonLat>}
|
||||
*/
|
||||
this._pathLonLatMerc = [];
|
||||
|
||||
@ -178,15 +178,15 @@ class Polyline {
|
||||
|
||||
/**
|
||||
* Appends to the line array new cartesian coordinates line data.
|
||||
* @param {[[number, number, number]]} path3v - Line coordinates path array.
|
||||
* @param {Array.<Array.<number>>} path3v - Line coordinates path array. [[0,0,0], [1,1,1],...]
|
||||
* @param {Boolean} isClosed - Identificator for the closed line data creation.
|
||||
* @param {Number[]} outVertices - Out vertices data array.
|
||||
* @param {Number[]} outOrders - Out vertices orders data array.
|
||||
* @param {Number[]} outIndexes - Out vertices indexes data array.
|
||||
* @param {og.Ellipsoid} [ellipsoid] - Ellipsoid to coordinates transformation.
|
||||
* @param {[[og.LonLat]]} [outTransformedPathLonLat] - Geodetic coordinates out array.
|
||||
* @param {[[og.LonLat]]} [outPath3v] - Cartesian coordinates out array.
|
||||
* @param {[[og.LonLat]]} [outTransformedPathMerc] - Mercator coordinates out array.
|
||||
* @param {Array.<Array.<LonLat>>} [outTransformedPathLonLat] - Geodetic coordinates out array.
|
||||
* @param {Array.<Array.<LonLat>>} [outPath3v] - Cartesian coordinates out array.
|
||||
* @param {Array.<Array.<LonLat>>} [outTransformedPathMerc] - Mercator coordinates out array.
|
||||
* @param {og.Extent} [outExtent] - Geodetic line extent.
|
||||
* @param {Array} [outColors]
|
||||
* @static
|
||||
@ -449,15 +449,15 @@ class Polyline {
|
||||
|
||||
/**
|
||||
* Appends to the line new cartesian coordinates point data.
|
||||
* @param {[[number, number, number]]} path3v - Line coordinates path array.
|
||||
* @param {Array.<Array.<number>>} path3v - Line coordinates path array. [[0,0,0], [1,1,1],...]
|
||||
* @param {Boolean} isClosed - Identificator for the closed line data creation.
|
||||
* @param {Number[]} outVertices - Out vertices data array.
|
||||
* @param {Number[]} outOrders - Out vertices orders data array.
|
||||
* @param {Number[]} outIndexes - Out vertices indexes data array.
|
||||
* @param {og.Ellipsoid} [ellipsoid] - Ellipsoid to coordinates transformation.
|
||||
* @param {[[og.LonLat]]} [outTransformedPathLonLat] - Geodetic coordinates out array.
|
||||
* @param {[[og.LonLat]]} [outPath3v] - Cartesian coordinates out array.
|
||||
* @param {[[og.LonLat]]} [outTransformedPathMerc] - Mercator coordinates out array.
|
||||
* @param {Array.<Array.<LonLat>>} [outTransformedPathLonLat] - Geodetic coordinates out array.
|
||||
* @param {Array.<Array.<LonLat>>} [outPath3v] - Cartesian coordinates out array.
|
||||
* @param {Array.<Array.<LonLat>>} [outTransformedPathMerc] - Mercator coordinates out array.
|
||||
* @param {og.Extent} [outExtent] - Geodetic line extent.
|
||||
* @static
|
||||
*/
|
||||
@ -701,15 +701,15 @@ class Polyline {
|
||||
|
||||
/**
|
||||
* Appends to the line array new geodetic coordinates line data.
|
||||
* @param {[[number, number, number]]} pathLonLat - Line geodetic coordinates path array.
|
||||
* @param {Array.<Array.<number>>} pathLonLat - Line geodetic coordinates path array. [[0,0,0], [1,1,1],...]
|
||||
* @param {Boolean} isClosed - Identificator for the closed line data creation.
|
||||
* @param {Number[]} outVertices - Out vertices data array.
|
||||
* @param {Number[]} outOrders - Out vertices orders data array.
|
||||
* @param {Number[]} outIndexes - Out indexes data array.
|
||||
* @param {og.Ellipsoid} ellipsoid - Ellipsoid to coordinates transformation.
|
||||
* @param {[[Number, Number, Number]]} outTransformedPathCartesian - Cartesian coordinates out array.
|
||||
* @param {[[og.LonLat]]} outPathLonLat - Geographic coordinates out array.
|
||||
* @param {[[og.LonLat]]} outTransformedPathMerc - Mercator coordinates out array.
|
||||
* @param {Array.<Array.<number>>} outTransformedPathCartesian - Cartesian coordinates out array. [[0,0,0], [1,1,1],...]
|
||||
* @param {Array.<Array.<LonLat>>} outPathLonLat - Geographic coordinates out array.
|
||||
* @param {Array.<Array.<LonLat>>} outTransformedPathMerc - Mercator coordinates out array.
|
||||
* @param {og.Extent} outExtent - Geodetic line extent.
|
||||
* @static
|
||||
*/
|
||||
@ -1157,7 +1157,7 @@ class Polyline {
|
||||
/**
|
||||
* Sets polyline with geodetic coordinates.
|
||||
* @protected
|
||||
* @param {og.LonLat[]} pathLonLat - Geodetic polyline path coordinates.
|
||||
* @param {LonLat[]} pathLonLat - Geodetic polyline path coordinates.
|
||||
*/
|
||||
_setEqualPathLonLat(pathLonLat) {
|
||||
var extent = this._extent;
|
||||
@ -1640,7 +1640,7 @@ class Polyline {
|
||||
/**
|
||||
* Adds a new geodetic point in the end of the path.
|
||||
* @public
|
||||
* @param {og.LonLat} lonLat - New coordinate.
|
||||
* @param {LonLat} lonLat - New coordinate.
|
||||
* @param {number} [multiLineIndex=0] - Path part index, first by default.
|
||||
*/
|
||||
addPointLonLat(lonLat, multiLineIndex = 0) {
|
||||
@ -1886,7 +1886,7 @@ class Polyline {
|
||||
|
||||
/**
|
||||
* Returns geodetic path coordinates.
|
||||
* @return {Array.<og.LonLat>} Polyline path.
|
||||
* @return {Array.<LonLat>} Polyline path.
|
||||
*/
|
||||
getPathLonLat() {
|
||||
return this._pathLonLat;
|
||||
@ -1932,7 +1932,7 @@ class Polyline {
|
||||
/**
|
||||
* Sets geodetic coordinates.
|
||||
* @public
|
||||
* @param {Array.<Array.<number,number,number>>} pathLonLat - Polyline path cartesian coordinates.
|
||||
* @param {Array.<Array.<number>>} pathLonLat - Polyline path cartesian coordinates. (exactly 3 entries)
|
||||
* @param {Boolean} [forceEqual=false] - Makes assigning faster for size equal coordinates array.
|
||||
*/
|
||||
setPathLonLat(pathLonLat, forceEqual) {
|
||||
@ -1955,7 +1955,7 @@ class Polyline {
|
||||
/**
|
||||
* Sets Polyline cartesian coordinates.
|
||||
* @public
|
||||
* @param {Array.<Array.<number,number,number>>} path3v - Polyline path cartesian coordinates.
|
||||
* @param {Array.<Array.<number>>} path3v - Polyline path cartesian coordinates. (exactly 3 entries)
|
||||
* @param {Boolean} [forceEqual=false] - Makes assigning faster for size equal coordinates array.
|
||||
*/
|
||||
setPath3v(path3v, pathColors, forceEqual) {
|
||||
|
||||
@ -54,7 +54,7 @@ class BaseGeoImage extends Layer {
|
||||
/**
|
||||
* Gets corners coordinates.
|
||||
* @public
|
||||
* @return {[og.LonLat,og.LonLat,og.LonLat,og.LonLat]} -
|
||||
* @return {Array.<LonLat>} - (exactly 4 entries)
|
||||
*/
|
||||
getCornersLonLat() {
|
||||
var c = this._cornersWgs84;
|
||||
@ -65,7 +65,7 @@ class BaseGeoImage extends Layer {
|
||||
/**
|
||||
* Gets corners coordinates.
|
||||
* @public
|
||||
* @return {[[number,number,number]]} -
|
||||
* @return {Array.<Array<number>>} - (exactly 3 entries)
|
||||
*/
|
||||
getCorners() {
|
||||
var c = this._cornersWgs84;
|
||||
@ -75,7 +75,7 @@ class BaseGeoImage extends Layer {
|
||||
/**
|
||||
* Sets geoImage geographical corners coordinates.
|
||||
* @public
|
||||
* @param {[[number,number,number]]} corners - GeoImage corners coordinates. Where first coordinate
|
||||
* @param {Array.<Array.<number>>} corners - GeoImage corners coordinates. Where first coordinate (exactly 3 entries)
|
||||
* coincedents to the left top image corner, secont to the right top image corner, third to the right bottom
|
||||
* and fourth - left bottom image corner.
|
||||
*/
|
||||
@ -86,9 +86,9 @@ class BaseGeoImage extends Layer {
|
||||
/**
|
||||
* Sets geoImage geographical corners coordinates.
|
||||
* @public
|
||||
* @param {[og.LonLat, og.LonLat, og.LonLat, og.LonLat]} corners - GeoImage corners coordinates. Where first coordinate
|
||||
* @param {Array.<LonLat>} corners - GeoImage corners coordinates. Where first coordinate
|
||||
* coincedents to the left top image corner, secont to the right top image corner, third to the right bottom
|
||||
* and fourth - left bottom image corner.
|
||||
* and fourth - left bottom image corner. (exactly 4 entries)
|
||||
*/
|
||||
setCornersLonLat(corners) {
|
||||
this._refreshFrame = true;
|
||||
@ -228,7 +228,7 @@ class BaseGeoImage extends Layer {
|
||||
* @virtual
|
||||
* @protected
|
||||
* @param {og.planetSegment.Material} material - GeoImage material.
|
||||
* @returns {[Number, Number, Number, Number]} -
|
||||
* @returns {Array<number> } -
|
||||
*/
|
||||
applyMaterial(material) {
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ const EVENT_NAMES = [
|
||||
* @param {String} [name="noname"] - Layer name.
|
||||
* @param {Object} options:
|
||||
* @param {number} [options.opacity=1.0] - Layer opacity.
|
||||
* @param {Array.<number,number,number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color.
|
||||
* @param {Array.<number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color. (exactly 3 entries)
|
||||
* @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.
|
||||
|
||||
@ -22,7 +22,7 @@ export const FADING_FACTOR = 0.29;
|
||||
* @param {String} [name="noname"] - Layer name.
|
||||
* @param {Object} [options] - Layer options:
|
||||
* @param {number} [options.opacity=1.0] - Layer opacity.
|
||||
* @param {Array.<number,number,number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color.
|
||||
* @param {Array.<number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color. (exactly 3 entries)
|
||||
* @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.
|
||||
@ -87,7 +87,7 @@ class Layer {
|
||||
/**
|
||||
* Transparent RGB color mask.
|
||||
* @public
|
||||
* @type {Array.<number,number,number>}
|
||||
* @type {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
this.transparentColor = options.transparentColor || [-1, -1, -1];
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ function _entitiesConstructor(entities) {
|
||||
* @param {boolean} [options.visibility=true] - Layer visibility. True is default.
|
||||
* @param {boolean} [options.isBaseLayer=false] - Layer base layer. False is default.
|
||||
* @param {Array.<og.Entity>} [options.entities] - Entities array.
|
||||
* @param {Array.<number,number,number>} [options.scaleByDistance] - Scale by distance parameters.
|
||||
* @param {Array.<number>} [options.scaleByDistance] - Scale by distance parameters. (exactly 3 entries)
|
||||
* First index - near distance to the entity, after entity becomes full scale.
|
||||
* Second index - far distance to the entity, when entity becomes zero scale.
|
||||
* Third index - far distance to the entity, when entity becomes invisible.
|
||||
@ -88,7 +88,7 @@ class Vector extends Layer {
|
||||
* Second index - far distance to the entity, when entity becomes zero scale.
|
||||
* Third index - far distance to the entity, when entity becomes invisible.
|
||||
* @public
|
||||
* @type {Array.<number,number,number>}
|
||||
* @type {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
this.scaleByDistance = options.scaleByDistance || [math.MAX32, math.MAX32, math.MAX32];
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ import { XYZ } from './XYZ.js';
|
||||
* @param {string} name - Layer name.
|
||||
* @param {Object} options - Options:
|
||||
* @param {number} [options.opacity=1.0] - Layer opacity.
|
||||
* @param {Array.<number,number,number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color.
|
||||
* @param {Array.<number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color.
|
||||
* @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.
|
||||
|
||||
@ -17,7 +17,7 @@ import { RENDERING } from '../quadTree/quadTree.js';
|
||||
* @param {string} name - Layer name.
|
||||
* @param {Object} options:
|
||||
* @param {number} [options.opacity=1.0] - Layer opacity.
|
||||
* @param {Array.<number,number,number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color.
|
||||
* @param {Array.<number>} [options.transparentColor=[-1,-1,-1]] - RGB color that defines transparent color. (exactly 3 entries)
|
||||
* @param {Array.<string>} [options.subdomains=['a','b','c']] - Subdomains of the tile service.
|
||||
* @param {number} [options.minZoom=0] - Minimal visibility zoom level.
|
||||
* @param {number} [options.maxZoom=0] - Maximal visibility zoom level.
|
||||
|
||||
@ -6,27 +6,27 @@
|
||||
|
||||
import { Vec2 } from './Vec2.js';
|
||||
|
||||
const Line2 = function (a, b, c) {
|
||||
this.a = a || 0;
|
||||
this.b = b || 0;
|
||||
this.c = c || 0;
|
||||
};
|
||||
export class Line2 {
|
||||
constructor(a, b, c) {
|
||||
this.a = a || 0;
|
||||
this.b = b || 0;
|
||||
this.c = c || 0;
|
||||
}
|
||||
|
||||
Line2.get = function (p0, p1) {
|
||||
return new Line2(p1.y - p0.y, p0.x - p1.x, p1.x * p0.y - p0.x * p1.y);
|
||||
};
|
||||
static get(p0, p1) {
|
||||
return new Line2(p1.y - p0.y, p0.x - p1.x, p1.x * p0.y - p0.x * p1.y);
|
||||
};
|
||||
|
||||
Line2.getParallel = function (l, p) {
|
||||
return new Line2(l.a, l.b, -l.a * p.x - l.b * p.y);
|
||||
};
|
||||
static getParallel(l, p) {
|
||||
return new Line2(l.a, l.b, -l.a * p.x - l.b * p.y);
|
||||
};
|
||||
|
||||
Line2.getIntersection = function (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);
|
||||
};
|
||||
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);
|
||||
};
|
||||
|
||||
Line2.prototype.intersects = function (l) {
|
||||
return Line2.getIntersection(this, l);
|
||||
};
|
||||
|
||||
export { Line2 };
|
||||
intersects(l) {
|
||||
return Line2.getIntersection(this, l);
|
||||
};
|
||||
}
|
||||
|
||||
@ -3,137 +3,138 @@
|
||||
import * as math from '../math.js';
|
||||
import { Vec3 } from './Vec3.js';
|
||||
|
||||
const Line3 = function (p0, p1) {
|
||||
this.p0 = p0 || new Vec3();
|
||||
this.p1 = p1 || new Vec3();
|
||||
};
|
||||
export class Line3 {
|
||||
constructor(p0, p1) {
|
||||
this.p0 = p0 || new Vec3();
|
||||
this.p1 = p1 || new Vec3();
|
||||
};
|
||||
|
||||
Line3.prototype.getMagnitude = function () {
|
||||
return this.p0.distance(this.p1);
|
||||
};
|
||||
getMagnitude() {
|
||||
return this.p0.distance(this.p1);
|
||||
};
|
||||
|
||||
Line3.prototype.getSphereIntersection = function (sphere) {
|
||||
var p0 = this.p0,
|
||||
p1 = this.p1;
|
||||
getSphereIntersection(sphere) {
|
||||
var p0 = this.p0,
|
||||
p1 = this.p1;
|
||||
|
||||
var cx = sphere.x,
|
||||
cy = sphere.y,
|
||||
cz = sphere.z;
|
||||
var cx = sphere.x,
|
||||
cy = sphere.y,
|
||||
cz = sphere.z;
|
||||
|
||||
var px = p0.x,
|
||||
py = p0.y,
|
||||
pz = p0.z;
|
||||
var px = p0.x,
|
||||
py = p0.y,
|
||||
pz = p0.z;
|
||||
|
||||
var vx = p1.x - px,
|
||||
vy = p1.y - py,
|
||||
vz = p1.z - pz;
|
||||
var vx = p1.x - px,
|
||||
vy = p1.y - py,
|
||||
vz = p1.z - pz;
|
||||
|
||||
var A = vx * vx + vy * vy + vz * vz,
|
||||
B = 2.0 * (px * vx + py * vy + pz * vz - vx * cx - vy * cy - vz * cz),
|
||||
C = px * px - 2 * px * cx + cx * cx + py * py - 2 * py * cy + cy * cy +
|
||||
pz * pz - 2 * pz * cz + cz * cz - sphere.radius * sphere.radius;
|
||||
var D = B * B - 4 * A * C;
|
||||
var A = vx * vx + vy * vy + vz * vz,
|
||||
B = 2.0 * (px * vx + py * vy + pz * vz - vx * cx - vy * cy - vz * cz),
|
||||
C = px * px - 2 * px * cx + cx * cx + py * py - 2 * py * cy + cy * cy +
|
||||
pz * pz - 2 * pz * cz + cz * cz - sphere.radius * sphere.radius;
|
||||
var D = B * B - 4 * A * C;
|
||||
|
||||
if (D < 0) {
|
||||
return null;
|
||||
}
|
||||
if (D < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var t1 = (-B - Math.Sqrt(D)) / (2.0 * A);
|
||||
var t1 = (-B - Math.Sqrt(D)) / (2.0 * A);
|
||||
|
||||
var solution1 = new Vec3(
|
||||
p0.x * (1 - t1) + t1 * p1.x,
|
||||
p0.y * (1 - t1) + t1 * p1.y,
|
||||
p0.z * (1 - t1) + t1 * p1.z);
|
||||
var solution1 = new Vec3(
|
||||
p0.x * (1 - t1) + t1 * p1.x,
|
||||
p0.y * (1 - t1) + t1 * p1.y,
|
||||
p0.z * (1 - t1) + t1 * p1.z);
|
||||
|
||||
if (D == 0) {
|
||||
return solution1;
|
||||
}
|
||||
if (D == 0) {
|
||||
return solution1;
|
||||
}
|
||||
|
||||
var t2 = (-B + Math.Sqrt(D)) / (2.0 * A);
|
||||
var solution2 = new Vec3(
|
||||
p0.x * (1 - t2) + t2 * p1.x,
|
||||
p0.y * (1 - t2) + t2 * p1.y,
|
||||
p0.z * (1 - t2) + t2 * p1.z);
|
||||
var t2 = (-B + Math.Sqrt(D)) / (2.0 * A);
|
||||
var solution2 = new Vec3(
|
||||
p0.x * (1 - t2) + t2 * p1.x,
|
||||
p0.y * (1 - t2) + t2 * p1.y,
|
||||
p0.z * (1 - t2) + t2 * p1.z);
|
||||
|
||||
// prefer a solution that's on the line segment itself
|
||||
if (Math.Abs(t1 - 0.5) < Math.abs(t2 - 0.5)) {
|
||||
return [solution1, solution2];
|
||||
}
|
||||
// prefer a solution that's on the line segment itself
|
||||
if (Math.Abs(t1 - 0.5) < Math.abs(t2 - 0.5)) {
|
||||
return [solution1, solution2];
|
||||
}
|
||||
|
||||
return [solution2, solution1];
|
||||
};
|
||||
return [solution2, solution1];
|
||||
};
|
||||
|
||||
Line3.prototype.intersects = function (line, res, res2) {
|
||||
intersects(line, res, res2) {
|
||||
|
||||
let p13 = this.p0.sub(line.p0),
|
||||
p43 = line.p1.sub(line.p0);
|
||||
let p13 = this.p0.sub(line.p0),
|
||||
p43 = line.p1.sub(line.p0);
|
||||
|
||||
if (Math.abs(p43.x) < math.EPSILON10 && Math.abs(p43.y) < math.EPSILON10 && Math.abs(p43.z) < math.EPSILON10) {
|
||||
return false;
|
||||
}
|
||||
if (Math.abs(p43.x) < math.EPSILON10 && Math.abs(p43.y) < math.EPSILON10 && Math.abs(p43.z) < math.EPSILON10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let p21 = this.p1.sub(this.p0);
|
||||
let p21 = this.p1.sub(this.p0);
|
||||
|
||||
if (Math.abs(p21.x) < math.EPSILON10 && Math.abs(p21.y) < math.EPSILON10 && Math.abs(p21.z) < math.EPSILON10) {
|
||||
return false;
|
||||
}
|
||||
if (Math.abs(p21.x) < math.EPSILON10 && Math.abs(p21.y) < math.EPSILON10 && Math.abs(p21.z) < math.EPSILON10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z,
|
||||
d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z,
|
||||
d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z,
|
||||
d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z,
|
||||
d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
|
||||
let d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z,
|
||||
d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z,
|
||||
d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z,
|
||||
d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z,
|
||||
d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
|
||||
|
||||
let denom = d2121 * d4343 - d4321 * d4321;
|
||||
let denom = d2121 * d4343 - d4321 * d4321;
|
||||
|
||||
if (Math.abs(denom) < math.EPSILON10) {
|
||||
return false;
|
||||
}
|
||||
if (Math.abs(denom) < math.EPSILON10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let numer = d1343 * d4321 - d1321 * d4343;
|
||||
let numer = d1343 * d4321 - d1321 * d4343;
|
||||
|
||||
let mua = numer / denom;
|
||||
let mua = numer / denom;
|
||||
|
||||
res.x = this.p0.x + mua * p21.x;
|
||||
res.y = this.p0.y + mua * p21.y;
|
||||
res.z = this.p0.z + mua * p21.z;
|
||||
res.x = this.p0.x + mua * p21.x;
|
||||
res.y = this.p0.y + mua * p21.y;
|
||||
res.z = this.p0.z + mua * p21.z;
|
||||
|
||||
if (res2) {
|
||||
if (res2) {
|
||||
|
||||
let mub = (d1343 + d4321 * mua) / d4343;
|
||||
let mub = (d1343 + d4321 * mua) / d4343;
|
||||
|
||||
res2.x = line.p0.x + mub * p43.x;
|
||||
res2.y = line.p0.y + mub * p43.y;
|
||||
res2.z = line.p0.z + mub * p43.z;
|
||||
}
|
||||
res2.x = line.p0.x + mub * p43.x;
|
||||
res2.y = line.p0.y + mub * p43.y;
|
||||
res2.z = line.p0.z + mub * p43.z;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
Line3.prototype.getNearestDistancePoint = function (point, res) {
|
||||
getNearestDistancePoint(point, res) {
|
||||
|
||||
let p0 = this.p0,
|
||||
p1 = this.p1;
|
||||
let p0 = this.p0,
|
||||
p1 = this.p1;
|
||||
|
||||
let mag = this.getMagnitude();
|
||||
let mag = this.getMagnitude();
|
||||
|
||||
let u =
|
||||
(
|
||||
((point.x - p0.x) * (p1.x - p0.x)) +
|
||||
((point.y - p0.y) * (p1.y - p0.y)) +
|
||||
((point.z - p0.z) * (p1.z - p0.z))
|
||||
) /
|
||||
(mag * mag);
|
||||
let u =
|
||||
(
|
||||
((point.x - p0.x) * (p1.x - p0.x)) +
|
||||
((point.y - p0.y) * (p1.y - p0.y)) +
|
||||
((point.z - p0.z) * (p1.z - p0.z))
|
||||
) /
|
||||
(mag * mag);
|
||||
|
||||
res.x = p0.x + u * (p1.x - p0.x);
|
||||
res.y = p0.y + u * (p1.y - p0.y);
|
||||
res.z = p0.z + u * (p1.z - p0.z);
|
||||
res.x = p0.x + u * (p1.x - p0.x);
|
||||
res.y = p0.y + u * (p1.y - p0.y);
|
||||
res.z = p0.z + u * (p1.z - p0.z);
|
||||
|
||||
if (u < 0.0 || u > 1.0) {
|
||||
return false;
|
||||
}
|
||||
if (u < 0.0 || u > 1.0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
export { Line3 };
|
||||
}
|
||||
@ -11,133 +11,134 @@ import { Vec3 } from './Vec3.js';
|
||||
* Class represents a 3x3 matrix.
|
||||
* @class
|
||||
*/
|
||||
const Mat3 = function () {
|
||||
export class Mat3 {
|
||||
|
||||
constructor() {
|
||||
/**
|
||||
* A 3x3 matrix, indexable as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this._m = new Array(9);
|
||||
};
|
||||
|
||||
/**
|
||||
* A 3x3 matrix, indexable as a column-major order array.
|
||||
* Sets column-major order array matrix.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {og.Mat3}
|
||||
*/
|
||||
this._m = new Array(9);
|
||||
};
|
||||
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 {og.Mat3}
|
||||
*/
|
||||
clone() {
|
||||
var res = new Mat3();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy matrix.
|
||||
* @public
|
||||
* @param {og.Mat3} a - Matrix to copy.
|
||||
* @returns {og.Mat3}
|
||||
*/
|
||||
copy(a) {
|
||||
return this.set(a._m);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates trasposed matrix from the current.
|
||||
* @public
|
||||
* @returns {og.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 {og.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 {og.Vec3} p - 3d vector.
|
||||
* @returns {og.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 {og.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 {og.Mat3}
|
||||
*/
|
||||
|
||||
export function mat3() {
|
||||
return new Mat3();
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets column-major order array matrix.
|
||||
* @public
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {og.Mat3}
|
||||
*/
|
||||
Mat3.prototype.set = function (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 {og.Mat3}
|
||||
*/
|
||||
Mat3.prototype.clone = function () {
|
||||
var res = new Mat3();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy matrix.
|
||||
* @public
|
||||
* @param {og.Mat3} a - Matrix to copy.
|
||||
* @returns {og.Mat3}
|
||||
*/
|
||||
Mat3.prototype.copy = function (a) {
|
||||
return this.set(a._m);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates trasposed matrix from the current.
|
||||
* @public
|
||||
* @returns {og.Mat3}
|
||||
*/
|
||||
Mat3.prototype.transposeTo = function () {
|
||||
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 {og.Mat3}
|
||||
*/
|
||||
Mat3.prototype.setIdentity = function () {
|
||||
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 {og.Vec3} p - 3d vector.
|
||||
* @returns {og.Vec3}
|
||||
*/
|
||||
Mat3.prototype.mulVec = function (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 {og.Mat4}
|
||||
*/
|
||||
Mat3.prototype.toMatrix4 = function () {
|
||||
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;
|
||||
};
|
||||
|
||||
export { Mat3 };
|
||||
@ -9,14 +9,445 @@ import { Vec4 } from './Vec4.js';
|
||||
* Class represents a 4x4 matrix.
|
||||
* @class
|
||||
*/
|
||||
const Mat4 = function () {
|
||||
export class Mat4 {
|
||||
constructor() {
|
||||
/**
|
||||
* A 4x4 matrix, indexable as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this._m = new Array(16);
|
||||
};
|
||||
|
||||
/**
|
||||
* A 4x4 matrix, indexable as a column-major order array.
|
||||
* @public
|
||||
* @type {Array.<number>}
|
||||
* Returns identity matrix instance.
|
||||
* @static
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
this._m = new Array(16);
|
||||
};
|
||||
static get identity() {
|
||||
var res = new Mat4();
|
||||
res._m[0] = 1; res._m[1] = 0; res._m[2] = 0; res._m[3] = 0;
|
||||
res._m[4] = 0; res._m[5] = 1; res._m[6] = 0; res._m[7] = 0;
|
||||
res._m[8] = 0; res._m[9] = 0; res._m[10] = 1; res._m[11] = 0;
|
||||
res._m[12] = 0; res._m[13] = 0; res._m[14] = 0; res._m[15] = 1;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets column-major order array matrix.
|
||||
* @public
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
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];
|
||||
this._m[9] = m[9];
|
||||
this._m[10] = m[10];
|
||||
this._m[11] = m[11];
|
||||
this._m[12] = m[12];
|
||||
this._m[13] = m[13];
|
||||
this._m[14] = m[14];
|
||||
this._m[15] = m[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Duplicates a Matrix3 instance.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
clone() {
|
||||
var res = new Mat4();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy matrix.
|
||||
* @public
|
||||
* @param {og.Mat3} a - Matrix to copy.
|
||||
*/
|
||||
copy(a) {
|
||||
this.set(a._m);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts to 3x3 matrix.
|
||||
* @public
|
||||
* @returns {og.Mat3} -
|
||||
*/
|
||||
toMatrix3() {
|
||||
var res = new Mat3();
|
||||
var a = this._m,
|
||||
b = res._m;
|
||||
b[0] = a[0];
|
||||
b[1] = a[1];
|
||||
b[2] = a[2];
|
||||
b[3] = a[4];
|
||||
b[4] = a[5];
|
||||
b[5] = a[6];
|
||||
b[6] = a[8];
|
||||
b[7] = a[9];
|
||||
b[8] = a[10];
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiply to 3d vector.
|
||||
* @public
|
||||
* @param {og.Vec3} p - 3d vector.
|
||||
* @returns {og.Vec3} -
|
||||
*/
|
||||
mulVec3(p) {
|
||||
var d = p.x, e = p.y, g = p.z;
|
||||
return new Vec3(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiply to 4d vector.
|
||||
* @public
|
||||
* @param {og.Vec4} p - 4d vector.
|
||||
* @returns {og.Vec4} -
|
||||
*/
|
||||
mulVec4(p) {
|
||||
var d = p.x, e = p.y, g = p.z, f = p.w;
|
||||
return new Vec4(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14] * f,
|
||||
this._m[3] * d + this._m[7] * e + this._m[11] * g + this._m[15] * f
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an inversed 3x3 matrix of the current.
|
||||
* @public
|
||||
* @returns {og.Mat3} -
|
||||
*/
|
||||
toInverseMatrix3() {
|
||||
var a = this._m;
|
||||
var c = a[0], d = a[1], e = a[2],
|
||||
g = a[4], f = a[5], h = a[6],
|
||||
i = a[8], j = a[9], k = a[10],
|
||||
l = k * f - h * j,
|
||||
o = -k * g + h * i,
|
||||
m = j * g - f * i,
|
||||
n = c * l + d * o + e * m;
|
||||
|
||||
if (!n) {
|
||||
return null;
|
||||
}
|
||||
|
||||
n = 1 / n;
|
||||
|
||||
var res = new Mat3();
|
||||
res._m[0] = l * n;
|
||||
res._m[1] = (-k * d + e * j) * n;
|
||||
res._m[2] = (h * d - e * f) * n;
|
||||
res._m[3] = o * n;
|
||||
res._m[4] = (k * c - e * i) * n;
|
||||
res._m[5] = (-h * c + e * g) * n;
|
||||
res._m[6] = m * n;
|
||||
res._m[7] = (-j * c + d * i) * n;
|
||||
res._m[8] = (f * c - d * g) * n;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an inversed matrix of the current.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
inverseTo(res) {
|
||||
var c = this._m[0], d = this._m[1], e = this._m[2], g = this._m[3],
|
||||
f = this._m[4], h = this._m[5], i = this._m[6], j = this._m[7],
|
||||
k = this._m[8], l = this._m[9], o = this._m[10], m = this._m[11],
|
||||
n = this._m[12], p = this._m[13], r = this._m[14], s = this._m[15],
|
||||
A = c * h - d * f,
|
||||
B = c * i - e * f,
|
||||
t = c * j - g * f,
|
||||
u = d * i - e * h,
|
||||
v = d * j - g * h,
|
||||
w = e * j - g * i,
|
||||
x = k * p - l * n,
|
||||
y = k * r - o * n,
|
||||
z = k * s - m * n,
|
||||
C = l * r - o * p,
|
||||
D = l * s - m * p,
|
||||
E = o * s - m * r,
|
||||
q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x),
|
||||
res = res || new Mat4();
|
||||
|
||||
res._m[0] = (h * E - i * D + j * C) * q; res._m[1] = (-d * E + e * D - g * C) * q; res._m[2] = (p * w - r * v + s * u) * q; res._m[3] = (-l * w + o * v - m * u) * q;
|
||||
res._m[4] = (-f * E + i * z - j * y) * q; res._m[5] = (c * E - e * z + g * y) * q; res._m[6] = (-n * w + r * t - s * B) * q; res._m[7] = (k * w - o * t + m * B) * q;
|
||||
res._m[8] = (f * D - h * z + j * x) * q; res._m[9] = (-c * D + d * z - g * x) * q; res._m[10] = (n * v - p * t + s * A) * q; res._m[11] = (-k * v + l * t - m * A) * q;
|
||||
res._m[12] = (-f * C + h * y - i * x) * q; res._m[13] = (c * C - d * y + e * x) * q; res._m[14] = (-n * u + p * B - r * A) * q; res._m[15] = (k * u - l * B + o * A) * q;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a trasposed matrix of the current.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
transposeTo() {
|
||||
var res = new Mat4();
|
||||
res._m[0] = this._m[0]; res._m[1] = this._m[4]; res._m[2] = this._m[8]; res._m[3] = this._m[12];
|
||||
res._m[4] = this._m[1]; res._m[5] = this._m[5]; res._m[6] = this._m[9]; res._m[7] = this._m[13];
|
||||
res._m[8] = this._m[2]; res._m[9] = this._m[6]; res._m[10] = this._m[10]; res._m[11] = this._m[14];
|
||||
res._m[12] = this._m[3]; res._m[13] = this._m[7]; res._m[14] = this._m[11]; res._m[15] = this._m[15];
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets matrix to identity.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
setIdentity() {
|
||||
this._m[0] = 1; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
|
||||
this._m[4] = 0; this._m[5] = 1; this._m[6] = 0; this._m[7] = 0;
|
||||
this._m[8] = 0; this._m[9] = 0; this._m[10] = 1; this._m[11] = 0;
|
||||
this._m[12] = 0; this._m[13] = 0; this._m[14] = 0; this._m[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes the product of two matrices.
|
||||
* @public
|
||||
* @param {og.Mat4} mx - Matrix to multiply.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
mul(mx) {
|
||||
let d = this._m[0], e = this._m[1], g = this._m[2], f = this._m[3],
|
||||
h = this._m[4], i = this._m[5], j = this._m[6], k = this._m[7],
|
||||
l = this._m[8], o = this._m[9], m = this._m[10], n = this._m[11],
|
||||
p = this._m[12], r = this._m[13], s = this._m[14], a = this._m[15];
|
||||
|
||||
let A = mx._m[0], B = mx._m[1], t = mx._m[2], u = mx._m[3],
|
||||
v = mx._m[4], w = mx._m[5], x = mx._m[6], y = mx._m[7],
|
||||
z = mx._m[8], C = mx._m[9], D = mx._m[10], E = mx._m[11],
|
||||
q = mx._m[12], F = mx._m[13], G = mx._m[14], b = mx._m[15];
|
||||
|
||||
var res = new Mat4();
|
||||
res._m[0] = A * d + B * h + t * l + u * p; res._m[1] = A * e + B * i + t * o + u * r; res._m[2] = A * g + B * j + t * m + u * s; res._m[3] = A * f + B * k + t * n + u * a;
|
||||
res._m[4] = v * d + w * h + x * l + y * p; res._m[5] = v * e + w * i + x * o + y * r; res._m[6] = v * g + w * j + x * m + y * s; res._m[7] = v * f + w * k + x * n + y * a;
|
||||
res._m[8] = z * d + C * h + D * l + E * p; res._m[9] = z * e + C * i + D * o + E * r; res._m[10] = z * g + C * j + D * m + E * s; res._m[11] = z * f + C * k + D * n + E * a;
|
||||
res._m[12] = q * d + F * h + G * l + b * p; res._m[13] = q * e + F * i + G * o + b * r; res._m[14] = q * g + F * j + G * m + b * s; res._m[15] = q * f + F * k + G * n + b * a;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add translation vector to the current matrix.
|
||||
* @public
|
||||
* @param {og.Vec3} v - Translate vector.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
translate(v) {
|
||||
var d = v.x, e = v.y, b = v.z;
|
||||
var a = this._m;
|
||||
a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
|
||||
a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
|
||||
a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
|
||||
a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets translation matrix to the position.
|
||||
* @public
|
||||
* @param {og.Vec3} v - Translate to position.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
translateToPosition(v) {
|
||||
var a = this._m;
|
||||
a[12] = v.x;
|
||||
a[13] = v.y;
|
||||
a[14] = v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Rotate currrent matrix around the aligned axis and angle.
|
||||
* @public
|
||||
* @param {og.Vec3} u - Aligned axis.
|
||||
* @param {number} angle - Aligned axis angle in radians.
|
||||
* @returns {og.Mat4} -
|
||||
* @todo: OPTIMIZE: reveal multiplication
|
||||
*/
|
||||
rotate(u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var rot = new Mat4();
|
||||
var mx = rot._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
return this.mul(rot);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets current rotation matrix around the aligned axis and angle.
|
||||
* @public
|
||||
* @param {og.Vec3} u - Aligned axis.
|
||||
* @param {number} angle - Aligned axis angle in radians.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
setRotation(u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var mx = this._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the rotation matrix from one vector to another.
|
||||
* @public
|
||||
* @param {og.Vec3} a - Firtst vector.
|
||||
* @param {og.Vec3} b - Second vector.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
rotateBetweenVectors(a, b) {
|
||||
var q = Quat.getRotationBetweenVectors(a, b);
|
||||
return q.getMat4();
|
||||
};
|
||||
|
||||
/**
|
||||
* Scale current matrix to the vector values.
|
||||
* @public
|
||||
* @param {og.Vec3} v - Scale vector.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
scale(v) {
|
||||
var mx = this._m;
|
||||
mx[0] = mx[0] * v.x; mx[1] = mx[1] * v.x; mx[2] = mx[2] * v.x; mx[3] = mx[3] * v.x;
|
||||
mx[4] = mx[4] * v.y; mx[5] = mx[5] * v.y; mx[6] = mx[6] * v.y; mx[7] = mx[7] * v.y;
|
||||
mx[8] = mx[8] * v.z; mx[9] = mx[9] * v.z; mx[10] = mx[10] * v.z; mx[11] = mx[11] * v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets perspective projection matrix frustum values.
|
||||
* @public
|
||||
* @param {number} left -
|
||||
* @param {number} right -
|
||||
* @param {number} bottom -
|
||||
* @param {number} top -
|
||||
* @param {number} near -
|
||||
* @param {number} far -
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
setPerspective(left, right, bottom, top, near, far) {
|
||||
var h = right - left, i = top - bottom, j = far - near;
|
||||
this._m[0] = near * 2 / h;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
this._m[3] = 0;
|
||||
this._m[4] = 0;
|
||||
this._m[5] = near * 2 / i;
|
||||
this._m[6] = 0;
|
||||
this._m[7] = 0;
|
||||
this._m[8] = (right + left) / h;
|
||||
this._m[9] = (top + bottom) / i;
|
||||
this._m[10] = -(far + near) / j;
|
||||
this._m[11] = -1;
|
||||
this._m[12] = 0;
|
||||
this._m[13] = 0;
|
||||
this._m[14] = -(far * near * 2) / j;
|
||||
this._m[15] = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates current orthographic projection matrix.
|
||||
* @public
|
||||
* @param {number} left -
|
||||
* @param {number} right -
|
||||
* @param {number} bottom -
|
||||
* @param {number} top -
|
||||
* @param {number} near -
|
||||
* @param {number} far -
|
||||
* @return {og.Mat4} -
|
||||
*/
|
||||
setOrtho(left, right, bottom, top, near, far) {
|
||||
|
||||
var lr = 1.0 / (left - right),
|
||||
bt = 1.0 / (bottom - top),
|
||||
nf = 1.0 / (near - far),
|
||||
m = this._m;
|
||||
|
||||
m[0] = -2.0 * lr;
|
||||
m[1] = 0;
|
||||
m[2] = 0;
|
||||
m[3] = 0;
|
||||
m[4] = 0;
|
||||
m[5] = -2.0 * bt;
|
||||
m[6] = 0;
|
||||
m[7] = 0;
|
||||
m[8] = 0;
|
||||
m[9] = 0;
|
||||
m[10] = 2.0 * nf;
|
||||
m[11] = 0;
|
||||
m[12] = (left + right) * lr;
|
||||
m[13] = (top + bottom) * bt;
|
||||
m[14] = (far + near) * nf;
|
||||
m[15] = 1.0;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets current rotation matrix by euler's angles.
|
||||
* @public
|
||||
* @param {number} ax - Rotation angle in radians arond X axis.
|
||||
* @param {number} ay - Rotation angle in radians arond Y axis.
|
||||
* @param {number} az - Rotation angle in radians arond Z axis.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
eulerToMatrix(ax, ay, az) {
|
||||
var a = Math.cos(ax),
|
||||
b = Math.sin(ax),
|
||||
c = Math.cos(ay),
|
||||
d = Math.sin(ay),
|
||||
e = Math.cos(az),
|
||||
f = Math.sin(az);
|
||||
|
||||
var ad = a * d,
|
||||
bd = b * d;
|
||||
|
||||
var mat = this._m;
|
||||
|
||||
mat[0] = c * e;
|
||||
mat[1] = -c * f;
|
||||
mat[2] = -d;
|
||||
mat[4] = -bd * e + a * f;
|
||||
mat[5] = bd * f + a * e;
|
||||
mat[6] = -b * c;
|
||||
mat[8] = ad * e + b * f;
|
||||
mat[9] = -ad * f + b * e;
|
||||
mat[10] = a * c;
|
||||
mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
|
||||
mat[15] = 1;
|
||||
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Mat4 factory.
|
||||
@ -26,434 +457,3 @@ const Mat4 = function () {
|
||||
export function mat4() {
|
||||
return new og.Mat4();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns identity matrix instance.
|
||||
* @static
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.identity = function () {
|
||||
var res = new Mat4();
|
||||
res._m[0] = 1; res._m[1] = 0; res._m[2] = 0; res._m[3] = 0;
|
||||
res._m[4] = 0; res._m[5] = 1; res._m[6] = 0; res._m[7] = 0;
|
||||
res._m[8] = 0; res._m[9] = 0; res._m[10] = 1; res._m[11] = 0;
|
||||
res._m[12] = 0; res._m[13] = 0; res._m[14] = 0; res._m[15] = 1;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets column-major order array matrix.
|
||||
* @public
|
||||
* @param {Array.<number>} m - Matrix array.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.set = function (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];
|
||||
this._m[9] = m[9];
|
||||
this._m[10] = m[10];
|
||||
this._m[11] = m[11];
|
||||
this._m[12] = m[12];
|
||||
this._m[13] = m[13];
|
||||
this._m[14] = m[14];
|
||||
this._m[15] = m[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Duplicates a Matrix3 instance.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.clone = function () {
|
||||
var res = new Mat4();
|
||||
res.set(this);
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy matrix.
|
||||
* @public
|
||||
* @param {og.Mat3} a - Matrix to copy.
|
||||
*/
|
||||
Mat4.prototype.copy = function (a) {
|
||||
this.set(a._m);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts to 3x3 matrix.
|
||||
* @public
|
||||
* @returns {og.Mat3} -
|
||||
*/
|
||||
Mat4.prototype.toMatrix3 = function () {
|
||||
var res = new Mat3();
|
||||
var a = this._m,
|
||||
b = res._m;
|
||||
b[0] = a[0];
|
||||
b[1] = a[1];
|
||||
b[2] = a[2];
|
||||
b[3] = a[4];
|
||||
b[4] = a[5];
|
||||
b[5] = a[6];
|
||||
b[6] = a[8];
|
||||
b[7] = a[9];
|
||||
b[8] = a[10];
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiply to 3d vector.
|
||||
* @public
|
||||
* @param {og.Vec3} p - 3d vector.
|
||||
* @returns {og.Vec3} -
|
||||
*/
|
||||
Mat4.prototype.mulVec3 = function (p) {
|
||||
var d = p.x, e = p.y, g = p.z;
|
||||
return new Vec3(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12],
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13],
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiply to 4d vector.
|
||||
* @public
|
||||
* @param {og.Vec4} p - 4d vector.
|
||||
* @returns {og.Vec4} -
|
||||
*/
|
||||
Mat4.prototype.mulVec4 = function (p) {
|
||||
var d = p.x, e = p.y, g = p.z, f = p.w;
|
||||
return new Vec4(
|
||||
this._m[0] * d + this._m[4] * e + this._m[8] * g + this._m[12] * f,
|
||||
this._m[1] * d + this._m[5] * e + this._m[9] * g + this._m[13] * f,
|
||||
this._m[2] * d + this._m[6] * e + this._m[10] * g + this._m[14] * f,
|
||||
this._m[3] * d + this._m[7] * e + this._m[11] * g + this._m[15] * f
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an inversed 3x3 matrix of the current.
|
||||
* @public
|
||||
* @returns {og.Mat3} -
|
||||
*/
|
||||
Mat4.prototype.toInverseMatrix3 = function () {
|
||||
var a = this._m;
|
||||
var c = a[0], d = a[1], e = a[2],
|
||||
g = a[4], f = a[5], h = a[6],
|
||||
i = a[8], j = a[9], k = a[10],
|
||||
l = k * f - h * j,
|
||||
o = -k * g + h * i,
|
||||
m = j * g - f * i,
|
||||
n = c * l + d * o + e * m;
|
||||
|
||||
if (!n) {
|
||||
return null;
|
||||
}
|
||||
|
||||
n = 1 / n;
|
||||
|
||||
var res = new Mat3();
|
||||
res._m[0] = l * n;
|
||||
res._m[1] = (-k * d + e * j) * n;
|
||||
res._m[2] = (h * d - e * f) * n;
|
||||
res._m[3] = o * n;
|
||||
res._m[4] = (k * c - e * i) * n;
|
||||
res._m[5] = (-h * c + e * g) * n;
|
||||
res._m[6] = m * n;
|
||||
res._m[7] = (-j * c + d * i) * n;
|
||||
res._m[8] = (f * c - d * g) * n;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an inversed matrix of the current.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.inverseTo = function (res) {
|
||||
var c = this._m[0], d = this._m[1], e = this._m[2], g = this._m[3],
|
||||
f = this._m[4], h = this._m[5], i = this._m[6], j = this._m[7],
|
||||
k = this._m[8], l = this._m[9], o = this._m[10], m = this._m[11],
|
||||
n = this._m[12], p = this._m[13], r = this._m[14], s = this._m[15],
|
||||
A = c * h - d * f,
|
||||
B = c * i - e * f,
|
||||
t = c * j - g * f,
|
||||
u = d * i - e * h,
|
||||
v = d * j - g * h,
|
||||
w = e * j - g * i,
|
||||
x = k * p - l * n,
|
||||
y = k * r - o * n,
|
||||
z = k * s - m * n,
|
||||
C = l * r - o * p,
|
||||
D = l * s - m * p,
|
||||
E = o * s - m * r,
|
||||
q = 1 / (A * E - B * D + t * C + u * z - v * y + w * x),
|
||||
res = res || new Mat4();
|
||||
|
||||
res._m[0] = (h * E - i * D + j * C) * q; res._m[1] = (-d * E + e * D - g * C) * q; res._m[2] = (p * w - r * v + s * u) * q; res._m[3] = (-l * w + o * v - m * u) * q;
|
||||
res._m[4] = (-f * E + i * z - j * y) * q; res._m[5] = (c * E - e * z + g * y) * q; res._m[6] = (-n * w + r * t - s * B) * q; res._m[7] = (k * w - o * t + m * B) * q;
|
||||
res._m[8] = (f * D - h * z + j * x) * q; res._m[9] = (-c * D + d * z - g * x) * q; res._m[10] = (n * v - p * t + s * A) * q; res._m[11] = (-k * v + l * t - m * A) * q;
|
||||
res._m[12] = (-f * C + h * y - i * x) * q; res._m[13] = (c * C - d * y + e * x) * q; res._m[14] = (-n * u + p * B - r * A) * q; res._m[15] = (k * u - l * B + o * A) * q;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a trasposed matrix of the current.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.transposeTo = function () {
|
||||
var res = new Mat4();
|
||||
res._m[0] = this._m[0]; res._m[1] = this._m[4]; res._m[2] = this._m[8]; res._m[3] = this._m[12];
|
||||
res._m[4] = this._m[1]; res._m[5] = this._m[5]; res._m[6] = this._m[9]; res._m[7] = this._m[13];
|
||||
res._m[8] = this._m[2]; res._m[9] = this._m[6]; res._m[10] = this._m[10]; res._m[11] = this._m[14];
|
||||
res._m[12] = this._m[3]; res._m[13] = this._m[7]; res._m[14] = this._m[11]; res._m[15] = this._m[15];
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets matrix to identity.
|
||||
* @public
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.setIdentity = function () {
|
||||
this._m[0] = 1; this._m[1] = 0; this._m[2] = 0; this._m[3] = 0;
|
||||
this._m[4] = 0; this._m[5] = 1; this._m[6] = 0; this._m[7] = 0;
|
||||
this._m[8] = 0; this._m[9] = 0; this._m[10] = 1; this._m[11] = 0;
|
||||
this._m[12] = 0; this._m[13] = 0; this._m[14] = 0; this._m[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes the product of two matrices.
|
||||
* @public
|
||||
* @param {og.Mat4} mx - Matrix to multiply.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.mul = function (mx) {
|
||||
let d = this._m[0], e = this._m[1], g = this._m[2], f = this._m[3],
|
||||
h = this._m[4], i = this._m[5], j = this._m[6], k = this._m[7],
|
||||
l = this._m[8], o = this._m[9], m = this._m[10], n = this._m[11],
|
||||
p = this._m[12], r = this._m[13], s = this._m[14], a = this._m[15];
|
||||
|
||||
let A = mx._m[0], B = mx._m[1], t = mx._m[2], u = mx._m[3],
|
||||
v = mx._m[4], w = mx._m[5], x = mx._m[6], y = mx._m[7],
|
||||
z = mx._m[8], C = mx._m[9], D = mx._m[10], E = mx._m[11],
|
||||
q = mx._m[12], F = mx._m[13], G = mx._m[14], b = mx._m[15];
|
||||
|
||||
var res = new Mat4();
|
||||
res._m[0] = A * d + B * h + t * l + u * p; res._m[1] = A * e + B * i + t * o + u * r; res._m[2] = A * g + B * j + t * m + u * s; res._m[3] = A * f + B * k + t * n + u * a;
|
||||
res._m[4] = v * d + w * h + x * l + y * p; res._m[5] = v * e + w * i + x * o + y * r; res._m[6] = v * g + w * j + x * m + y * s; res._m[7] = v * f + w * k + x * n + y * a;
|
||||
res._m[8] = z * d + C * h + D * l + E * p; res._m[9] = z * e + C * i + D * o + E * r; res._m[10] = z * g + C * j + D * m + E * s; res._m[11] = z * f + C * k + D * n + E * a;
|
||||
res._m[12] = q * d + F * h + G * l + b * p; res._m[13] = q * e + F * i + G * o + b * r; res._m[14] = q * g + F * j + G * m + b * s; res._m[15] = q * f + F * k + G * n + b * a;
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add translation vector to the current matrix.
|
||||
* @public
|
||||
* @param {og.Vec3} v - Translate vector.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.translate = function (v) {
|
||||
var d = v.x, e = v.y, b = v.z;
|
||||
var a = this._m;
|
||||
a[12] = a[0] * d + a[4] * e + a[8] * b + a[12];
|
||||
a[13] = a[1] * d + a[5] * e + a[9] * b + a[13];
|
||||
a[14] = a[2] * d + a[6] * e + a[10] * b + a[14];
|
||||
a[15] = a[3] * d + a[7] * e + a[11] * b + a[15];
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets translation matrix to the position.
|
||||
* @public
|
||||
* @param {og.Vec3} v - Translate to position.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.translateToPosition = function (v) {
|
||||
var a = this._m;
|
||||
a[12] = v.x;
|
||||
a[13] = v.y;
|
||||
a[14] = v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Rotate currrent matrix around the aligned axis and angle.
|
||||
* @public
|
||||
* @param {og.Vec3} u - Aligned axis.
|
||||
* @param {number} angle - Aligned axis angle in radians.
|
||||
* @returns {og.Mat4} -
|
||||
* @todo: OPTIMIZE: reveal multiplication
|
||||
*/
|
||||
Mat4.prototype.rotate = function (u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var rot = new Mat4();
|
||||
var mx = rot._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
return this.mul(rot);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets current rotation matrix around the aligned axis and angle.
|
||||
* @public
|
||||
* @param {og.Vec3} u - Aligned axis.
|
||||
* @param {number} angle - Aligned axis angle in radians.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.setRotation = function (u, angle) {
|
||||
var c = Math.cos(angle),
|
||||
s = Math.sin(angle);
|
||||
var mx = this._m;
|
||||
mx[0] = c + (1 - c) * u.x * u.x; mx[1] = (1 - c) * u.y * u.x - s * u.z; mx[2] = (1 - c) * u.z * u.x + s * u.y; mx[3] = 0;
|
||||
mx[4] = (1 - c) * u.x * u.y + s * u.z; mx[5] = c + (1 - c) * u.y * u.y; mx[6] = (1 - c) * u.z * u.y - s * u.x; mx[7] = 0;
|
||||
mx[8] = (1 - c) * u.x * u.z - s * u.y; mx[9] = (1 - c) * u.y * u.z + s * u.x; mx[10] = c + (1 - c) * u.z * u.z; mx[11] = 0;
|
||||
mx[12] = 0; mx[13] = 0; mx[14] = 0; mx[15] = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the rotation matrix from one vector to another.
|
||||
* @public
|
||||
* @param {og.Vec3} a - Firtst vector.
|
||||
* @param {og.Vec3} b - Second vector.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.rotateBetweenVectors = function (a, b) {
|
||||
var q = Quat.getRotationBetweenVectors(a, b);
|
||||
return q.getMat4();
|
||||
};
|
||||
|
||||
/**
|
||||
* Scale current matrix to the vector values.
|
||||
* @public
|
||||
* @param {og.Vec3} v - Scale vector.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.scale = function (v) {
|
||||
var mx = this._m;
|
||||
mx[0] = mx[0] * v.x; mx[1] = mx[1] * v.x; mx[2] = mx[2] * v.x; mx[3] = mx[3] * v.x;
|
||||
mx[4] = mx[4] * v.y; mx[5] = mx[5] * v.y; mx[6] = mx[6] * v.y; mx[7] = mx[7] * v.y;
|
||||
mx[8] = mx[8] * v.z; mx[9] = mx[9] * v.z; mx[10] = mx[10] * v.z; mx[11] = mx[11] * v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets perspective projection matrix frustum values.
|
||||
* @public
|
||||
* @param {number} left -
|
||||
* @param {number} right -
|
||||
* @param {number} bottom -
|
||||
* @param {number} top -
|
||||
* @param {number} near -
|
||||
* @param {number} far -
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.setPerspective = function (left, right, bottom, top, near, far) {
|
||||
var h = right - left, i = top - bottom, j = far - near;
|
||||
this._m[0] = near * 2 / h;
|
||||
this._m[1] = 0;
|
||||
this._m[2] = 0;
|
||||
this._m[3] = 0;
|
||||
this._m[4] = 0;
|
||||
this._m[5] = near * 2 / i;
|
||||
this._m[6] = 0;
|
||||
this._m[7] = 0;
|
||||
this._m[8] = (right + left) / h;
|
||||
this._m[9] = (top + bottom) / i;
|
||||
this._m[10] = -(far + near) / j;
|
||||
this._m[11] = -1;
|
||||
this._m[12] = 0;
|
||||
this._m[13] = 0;
|
||||
this._m[14] = -(far * near * 2) / j;
|
||||
this._m[15] = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates current orthographic projection matrix.
|
||||
* @public
|
||||
* @param {number} left -
|
||||
* @param {number} right -
|
||||
* @param {number} bottom -
|
||||
* @param {number} top -
|
||||
* @param {number} near -
|
||||
* @param {number} far -
|
||||
* @return {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.setOrtho = function (left, right, bottom, top, near, far) {
|
||||
|
||||
var lr = 1.0 / (left - right),
|
||||
bt = 1.0 / (bottom - top),
|
||||
nf = 1.0 / (near - far),
|
||||
m = this._m;
|
||||
|
||||
m[0] = -2.0 * lr;
|
||||
m[1] = 0;
|
||||
m[2] = 0;
|
||||
m[3] = 0;
|
||||
m[4] = 0;
|
||||
m[5] = -2.0 * bt;
|
||||
m[6] = 0;
|
||||
m[7] = 0;
|
||||
m[8] = 0;
|
||||
m[9] = 0;
|
||||
m[10] = 2.0 * nf;
|
||||
m[11] = 0;
|
||||
m[12] = (left + right) * lr;
|
||||
m[13] = (top + bottom) * bt;
|
||||
m[14] = (far + near) * nf;
|
||||
m[15] = 1.0;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets current rotation matrix by euler's angles.
|
||||
* @public
|
||||
* @param {number} ax - Rotation angle in radians arond X axis.
|
||||
* @param {number} ay - Rotation angle in radians arond Y axis.
|
||||
* @param {number} az - Rotation angle in radians arond Z axis.
|
||||
* @returns {og.Mat4} -
|
||||
*/
|
||||
Mat4.prototype.eulerToMatrix = function (ax, ay, az) {
|
||||
var a = Math.cos(ax),
|
||||
b = Math.sin(ax),
|
||||
c = Math.cos(ay),
|
||||
d = Math.sin(ay),
|
||||
e = Math.cos(az),
|
||||
f = Math.sin(az);
|
||||
|
||||
var ad = a * d,
|
||||
bd = b * d;
|
||||
|
||||
var mat = this._m;
|
||||
|
||||
mat[0] = c * e;
|
||||
mat[1] = -c * f;
|
||||
mat[2] = -d;
|
||||
mat[4] = -bd * e + a * f;
|
||||
mat[5] = bd * f + a * e;
|
||||
mat[6] = -b * c;
|
||||
mat[8] = ad * e + b * f;
|
||||
mat[9] = -ad * f + b * e;
|
||||
mat[10] = a * c;
|
||||
mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
|
||||
mat[15] = 1;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
export { Mat4 };
|
||||
1864
src/og/math/Quat.js
1864
src/og/math/Quat.js
File diff suppressed because it is too large
Load Diff
@ -13,22 +13,213 @@ import { Vec3 } from './Vec3.js';
|
||||
* @param {og.Vec3} origin - The origin of the ray.
|
||||
* @param {og.Vec3} direction - The direction of the ray.
|
||||
*/
|
||||
const Ray = function (origin, direction) {
|
||||
export class Ray {
|
||||
constructor(origin, direction) {
|
||||
|
||||
/**
|
||||
* The origin of the ray.
|
||||
* @public
|
||||
* @type {og.Vec3}
|
||||
*/
|
||||
this.origin = origin || new Vec3();
|
||||
|
||||
/**
|
||||
* The direction of the ray.
|
||||
* @public
|
||||
* @type {og.Vec3}
|
||||
*/
|
||||
this.direction = direction || new Vec3();
|
||||
};
|
||||
|
||||
/** @const */
|
||||
static get OUTSIDE() { return 0; }
|
||||
|
||||
/** @const */
|
||||
static get INSIDE() { return 1; }
|
||||
/** @const */
|
||||
static get INPLANE() { return 2; }
|
||||
/** @const */
|
||||
static get AWAY() { return 3; }
|
||||
|
||||
/**
|
||||
* The origin of the ray.
|
||||
* Sets a ray parameters.
|
||||
* @public
|
||||
* @type {og.Vec3}
|
||||
* @param {og.Vec3} origin - The origin of the ray.
|
||||
* @param {og.Vec3} direction - The direction of the ray.
|
||||
* @returns {og.Ray}
|
||||
*/
|
||||
this.origin = origin || new Vec3();
|
||||
set(origin, direction) {
|
||||
this.origin = origin;
|
||||
this.direction = direction;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* The direction of the ray.
|
||||
* Computes the point along the ray on the distance.
|
||||
* @public
|
||||
* @type {og.Vec3}
|
||||
* @param {number} distance - Point distance.
|
||||
* @returns {og.Vec3}
|
||||
*/
|
||||
this.direction = direction || new Vec3();
|
||||
};
|
||||
getPoint(distance) {
|
||||
return Vec3.add(this.origin, this.direction.scaleTo(distance));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns ray hit a triange result.
|
||||
* @public
|
||||
* @param {og.Vec3} v0 - First triangle corner coordinate.
|
||||
* @param {og.Vec3} v1 - Second triangle corner coordinate.
|
||||
* @param {og.Vec3} v2 - Third triangle corner coordinate.
|
||||
* @param {og.Vec3} res - Hit point object pointer that stores hit result.
|
||||
* @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
|
||||
* 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
|
||||
*/
|
||||
hitTriangle(v0, v1, v2, res, normal) {
|
||||
var u = v1.sub(v0);
|
||||
var v = v2.sub(v0);
|
||||
var n = u.cross(v);
|
||||
|
||||
var w0 = this.origin.sub(v0);
|
||||
var a = -n.dot(w0);
|
||||
var b = n.dot(this.direction);
|
||||
|
||||
// ray is parallel to triangle plane
|
||||
if (Math.abs(b) < math.EPSILON10) {
|
||||
if (a === 0) {
|
||||
res.copy(this.origin);
|
||||
// ray lies in triangle plane
|
||||
return Ray.INPLANE;
|
||||
} else {
|
||||
// ray disjoint from plane
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
var r = a / b;
|
||||
|
||||
// intersect point of ray and plane
|
||||
res.copy(this.origin.add(this.direction.scaleTo(r)));
|
||||
|
||||
// ray goes away from triangle
|
||||
if (r < 0.0) {
|
||||
return Ray.AWAY;
|
||||
}
|
||||
|
||||
// is res point inside the triangle?
|
||||
var uu = u.dot(u);
|
||||
var uv = u.dot(v);
|
||||
var vv = v.dot(v);
|
||||
var w = res.sub(v0);
|
||||
var wu = w.dot(u);
|
||||
var wv = w.dot(v);
|
||||
var D = uv * uv - uu * vv;
|
||||
|
||||
var s = (uv * wv - vv * wu) / D;
|
||||
if (s < 0.0 || s > 1.0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
|
||||
var t = (uv * wu - uu * wv) / D;
|
||||
if (t < 0.0 || (s + t) > 1.0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
|
||||
return Ray.INSIDE;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
|
||||
* @public
|
||||
* @param {og.Vec3} v0 - First plane point.
|
||||
* @param {og.Vec3} v1 - Second plane point.
|
||||
* @param {og.Vec3} v2 - Third plane point.
|
||||
* @param {og.Vec3} res - Hit point object pointer that stores hit result.
|
||||
* @returns {number}
|
||||
*/
|
||||
hitPlane(v0, v1, v2, res) {
|
||||
var u = Vec3.sub(v1, v0);
|
||||
var v = Vec3.sub(v2, v0);
|
||||
var n = u.cross(v);
|
||||
|
||||
var w0 = Vec3.sub(this.origin, v0);
|
||||
var a = -n.dot(w0);
|
||||
var b = n.dot(this.direction);
|
||||
|
||||
// ray is parallel to the plane
|
||||
if (Math.abs(b) < math.EPSILON10) {
|
||||
if (a === 0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
var r = a / b;
|
||||
|
||||
if (r < 0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
|
||||
var d = this.direction.scaleTo(r);
|
||||
|
||||
// intersect point of ray and plane
|
||||
res.x = this.origin.x + d.x;
|
||||
res.y = this.origin.y + d.y;
|
||||
res.z = this.origin.z + d.z;
|
||||
|
||||
return Ray.INSIDE;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a ray hit sphere coordiante. If there isn't hit returns null.
|
||||
* @public
|
||||
* @param {og.bv.Sphere} sphere - Sphere object.
|
||||
* @returns {og.Vec3}
|
||||
*/
|
||||
hitSphere(sphere) {
|
||||
var r = sphere.radius,
|
||||
c = sphere.center,
|
||||
o = this.origin,
|
||||
d = this.direction;
|
||||
var vpc = Vec3.sub(c, o);
|
||||
if (vpc.dot(d) < 0) {
|
||||
var l = vpc.length();
|
||||
if (l > r) {
|
||||
return null;
|
||||
} else if (l === r) {
|
||||
return o.clone();
|
||||
}
|
||||
let pc = c.projToRay(o, vpc);
|
||||
var lc = Vec3.sub(pc, c).length();
|
||||
let dist = Math.sqrt(r * r - lc * lc);
|
||||
let di1 = dist - Vec3.sub(pc, o).length();
|
||||
let intersection = Vec3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
} else {
|
||||
let pc = c.projToRay(o, d);
|
||||
var cpcl = Vec3.sub(c, pc).length();
|
||||
if (cpcl > sphere.radius) {
|
||||
return null;
|
||||
} else {
|
||||
let dist = Math.sqrt(r * r - cpcl * cpcl);
|
||||
let di1;
|
||||
pc.subA(o);
|
||||
if (vpc.length() > r) {
|
||||
di1 = pc.length() - dist;
|
||||
} else {
|
||||
di1 = pc.length() + dist;
|
||||
}
|
||||
let intersection = Vec3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
hitBox(box) {
|
||||
//
|
||||
// TODO
|
||||
//
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ray object creator.
|
||||
@ -41,191 +232,3 @@ export function ray(origin, direction) {
|
||||
return new Ray(origin, direction);
|
||||
};
|
||||
|
||||
/** @const */
|
||||
Ray.OUTSIDE = 0;
|
||||
/** @const */
|
||||
Ray.INSIDE = 1;
|
||||
/** @const */
|
||||
Ray.INPLANE = 2;
|
||||
/** @const */
|
||||
Ray.AWAY = 3;
|
||||
|
||||
/**
|
||||
* Sets a ray parameters.
|
||||
* @public
|
||||
* @param {og.Vec3} origin - The origin of the ray.
|
||||
* @param {og.Vec3} direction - The direction of the ray.
|
||||
* @returns {og.Ray}
|
||||
*/
|
||||
Ray.prototype.set = function (origin, direction) {
|
||||
this.origin = origin;
|
||||
this.direction = direction;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes the point along the ray on the distance.
|
||||
* @public
|
||||
* @param {number} distance - Point distance.
|
||||
* @returns {og.Vec3}
|
||||
*/
|
||||
Ray.prototype.getPoint = function (distance) {
|
||||
return Vec3.add(this.origin, this.direction.scaleTo(distance));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns ray hit a triange result.
|
||||
* @public
|
||||
* @param {og.Vec3} v0 - First triangle corner coordinate.
|
||||
* @param {og.Vec3} v1 - Second triangle corner coordinate.
|
||||
* @param {og.Vec3} v2 - Third triangle corner coordinate.
|
||||
* @param {og.Vec3} res - Hit point object pointer that stores hit result.
|
||||
* @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
|
||||
* 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
|
||||
*/
|
||||
Ray.prototype.hitTriangle = function (v0, v1, v2, res, normal) {
|
||||
var u = v1.sub(v0);
|
||||
var v = v2.sub(v0);
|
||||
var n = u.cross(v);
|
||||
|
||||
var w0 = this.origin.sub(v0);
|
||||
var a = -n.dot(w0);
|
||||
var b = n.dot(this.direction);
|
||||
|
||||
// ray is parallel to triangle plane
|
||||
if (Math.abs(b) < math.EPSILON10) {
|
||||
if (a === 0) {
|
||||
res.copy(this.origin);
|
||||
// ray lies in triangle plane
|
||||
return Ray.INPLANE;
|
||||
} else {
|
||||
// ray disjoint from plane
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
var r = a / b;
|
||||
|
||||
// intersect point of ray and plane
|
||||
res.copy(this.origin.add(this.direction.scaleTo(r)));
|
||||
|
||||
// ray goes away from triangle
|
||||
if (r < 0.0) {
|
||||
return Ray.AWAY;
|
||||
}
|
||||
|
||||
// is res point inside the triangle?
|
||||
var uu = u.dot(u);
|
||||
var uv = u.dot(v);
|
||||
var vv = v.dot(v);
|
||||
var w = res.sub(v0);
|
||||
var wu = w.dot(u);
|
||||
var wv = w.dot(v);
|
||||
var D = uv * uv - uu * vv;
|
||||
|
||||
var s = (uv * wv - vv * wu) / D;
|
||||
if (s < 0.0 || s > 1.0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
|
||||
var t = (uv * wu - uu * wv) / D;
|
||||
if (t < 0.0 || (s + t) > 1.0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
|
||||
return Ray.INSIDE;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
|
||||
* @public
|
||||
* @param {og.Vec3} v0 - First plane point.
|
||||
* @param {og.Vec3} v1 - Second plane point.
|
||||
* @param {og.Vec3} v2 - Third plane point.
|
||||
* @param {og.Vec3} res - Hit point object pointer that stores hit result.
|
||||
* @returns {number}
|
||||
*/
|
||||
Ray.prototype.hitPlane = function (v0, v1, v2, res) {
|
||||
var u = Vec3.sub(v1, v0);
|
||||
var v = Vec3.sub(v2, v0);
|
||||
var n = u.cross(v);
|
||||
|
||||
var w0 = Vec3.sub(this.origin, v0);
|
||||
var a = -n.dot(w0);
|
||||
var b = n.dot(this.direction);
|
||||
|
||||
// ray is parallel to the plane
|
||||
if (Math.abs(b) < math.EPSILON10) {
|
||||
if (a === 0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
var r = a / b;
|
||||
|
||||
if (r < 0) {
|
||||
return Ray.OUTSIDE;
|
||||
}
|
||||
|
||||
var d = this.direction.scaleTo(r);
|
||||
|
||||
// intersect point of ray and plane
|
||||
res.x = this.origin.x + d.x;
|
||||
res.y = this.origin.y + d.y;
|
||||
res.z = this.origin.z + d.z;
|
||||
|
||||
return Ray.INSIDE;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a ray hit sphere coordiante. If there isn't hit returns null.
|
||||
* @public
|
||||
* @param {og.bv.Sphere} sphere - Sphere object.
|
||||
* @returns {og.Vec3}
|
||||
*/
|
||||
Ray.prototype.hitSphere = function (sphere) {
|
||||
var r = sphere.radius,
|
||||
c = sphere.center,
|
||||
o = this.origin,
|
||||
d = this.direction;
|
||||
var vpc = Vec3.sub(c, o);
|
||||
if (vpc.dot(d) < 0) {
|
||||
var l = vpc.length();
|
||||
if (l > r) {
|
||||
return null;
|
||||
} else if (l === r) {
|
||||
return o.clone();
|
||||
}
|
||||
let pc = c.projToRay(o, vpc);
|
||||
var lc = Vec3.sub(pc, c).length();
|
||||
let dist = Math.sqrt(r * r - lc * lc);
|
||||
let di1 = dist - Vec3.sub(pc, o).length();
|
||||
let intersection = Vec3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
} else {
|
||||
let pc = c.projToRay(o, d);
|
||||
var cpcl = Vec3.sub(c, pc).length();
|
||||
if (cpcl > sphere.radius) {
|
||||
return null;
|
||||
} else {
|
||||
let dist = Math.sqrt(r * r - cpcl * cpcl);
|
||||
let di1;
|
||||
pc.subA(o);
|
||||
if (vpc.length() > r) {
|
||||
di1 = pc.length() - dist;
|
||||
} else {
|
||||
di1 = pc.length() + dist;
|
||||
}
|
||||
let intersection = Vec3.add(o, d.scaleTo(di1));
|
||||
return intersection;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ray.prototype.hitBox = function (box) {
|
||||
//
|
||||
// TODO
|
||||
//
|
||||
};
|
||||
|
||||
export { Ray };
|
||||
@ -309,7 +309,7 @@ export class Vec2 {
|
||||
/**
|
||||
* Gets vectors dot production.
|
||||
* @public
|
||||
* @param {[number,number]} arr - Array vector.
|
||||
* @param {Array.<number>} arr - Array vector. (exactly 2 entries)
|
||||
* @returns {number}
|
||||
*/
|
||||
dotArr(arr) {
|
||||
@ -370,7 +370,7 @@ export class Vec2 {
|
||||
/**
|
||||
* Converts vector to a number array.
|
||||
* @public
|
||||
* @returns {[number,number]}
|
||||
* @returns {Array.<number>} - (exactly 2 entries)
|
||||
*/
|
||||
toVec() {
|
||||
return [this.x, this.y];
|
||||
|
||||
@ -64,7 +64,7 @@ export class Vec3 {
|
||||
* @param {number} value - Double type value.
|
||||
* @param {Vec3} high - Out vector high values.
|
||||
* @param {Vec3} low - Out vector low values.
|
||||
* @returns {[number,number]} Encoded array.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
static doubleToTwoFloats(v, high, low) {
|
||||
|
||||
@ -107,7 +107,7 @@ export class Vec3 {
|
||||
* @param {number} value - Double type value.
|
||||
* @param {Float32Array} high - Out vector high values.
|
||||
* @param {Float32Array} low - Out vector low values.
|
||||
* @returns {[number,number]} Encoded array.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
static doubleToTwoFloat32Array(v, high, low) {
|
||||
|
||||
@ -147,7 +147,7 @@ export class Vec3 {
|
||||
/**
|
||||
* Creates 3d vector from array.
|
||||
* @function
|
||||
* @param {[number,number,number]} arr - Input array
|
||||
* @param {Array.<number>} arr - Input array (exactly 3 entries)
|
||||
* @returns {og.Vec3} -
|
||||
*/
|
||||
static fromVec(arr) {
|
||||
@ -517,7 +517,7 @@ export class Vec3 {
|
||||
/**
|
||||
* Gets vectors dot production.
|
||||
* @public
|
||||
* @param {[number,number,number]} arr - Array vector.
|
||||
* @param {Array.<number>} arr - Array vector. (exactly 3 entries)
|
||||
* @returns {number} -
|
||||
*/
|
||||
dotArr(arr) {
|
||||
@ -657,7 +657,7 @@ export class Vec3 {
|
||||
/**
|
||||
* Converts vector to a number array.
|
||||
* @public
|
||||
* @returns {[number,number,number]} -
|
||||
* @returns {Array.<number>} - (exactly 3 entries)
|
||||
* @deprecated
|
||||
*/
|
||||
toVec() {
|
||||
@ -667,7 +667,7 @@ export class Vec3 {
|
||||
/**
|
||||
* Converts vector to a number array.
|
||||
* @public
|
||||
* @returns {[number,number,number]} -
|
||||
* @returns {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
toArray() {
|
||||
return [this.x, this.y, this.z];
|
||||
|
||||
@ -53,7 +53,7 @@ export class Vec4 {
|
||||
/**
|
||||
* Creates 4d vector from array.
|
||||
* @function
|
||||
* @param {[number,number,number,number]}
|
||||
* @param {Array.<number>} - (exactly 4 entries)
|
||||
* @returns {og.math.Vec4}
|
||||
*/
|
||||
static fromVec(arr) {
|
||||
@ -104,7 +104,7 @@ export class Vec4 {
|
||||
/**
|
||||
* Converts vector to a number array.
|
||||
* @public
|
||||
* @returns {[number,number,number,number]}
|
||||
* @returns {Array.<number>} - (exactly 4 entries)
|
||||
* @deprecated
|
||||
*/
|
||||
toVec() {
|
||||
@ -114,7 +114,7 @@ export class Vec4 {
|
||||
/**
|
||||
* Converts vector to a number array.
|
||||
* @public
|
||||
* @returns {[number,number,number,number]}
|
||||
* @returns {Array.<number>} - (exactly 4 entries)
|
||||
*/
|
||||
toArray() {
|
||||
return [this.x, this.y, this.z, this.w];
|
||||
|
||||
@ -49,7 +49,7 @@ export function decodeFloatFromRGBAArr(arr, use32) {
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number,number>} Encoded array.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloats(value) {
|
||||
var high, low;
|
||||
@ -69,7 +69,7 @@ export function doubleToTwoFloats(value) {
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number,number>} Encoded array.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloats2(value, highLowArr) {
|
||||
if (value >= 0.0) {
|
||||
@ -88,7 +88,7 @@ export function doubleToTwoFloats2(value, highLowArr) {
|
||||
* Separate 64 bit value to two 32 bit float values.
|
||||
* @function
|
||||
* @param {number} value - Double type value.
|
||||
* @returns {Array.<number,number>} Encoded array.
|
||||
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
||||
*/
|
||||
export function doubleToTwoFloatsV2(value, highLowVec) {
|
||||
if (value >= 0.0) {
|
||||
|
||||
@ -117,8 +117,8 @@ export function getTileY(lat, zoom) {
|
||||
/**
|
||||
* Converts geodetic coordinate array to mercator coordinate array.
|
||||
* @function
|
||||
* @param {Array.<og.LonLat>} lonLatArr - LonLat array to convert.
|
||||
* @returns {Array.<og.LonLat>}
|
||||
* @param {Array.<LonLat>} lonLatArr - LonLat array to convert.
|
||||
* @returns {Array.<LonLat>}
|
||||
*/
|
||||
export function forwardArray(lonlatArr) {
|
||||
var res = [];
|
||||
|
||||
@ -169,14 +169,14 @@ const Renderer = function (handler, params) {
|
||||
/**
|
||||
* Stores current picking rgb color.
|
||||
* @private
|
||||
* @type {Array.<number,number,number>}
|
||||
* @type {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
this._currPickingColor = new Uint8Array(4);
|
||||
|
||||
/**
|
||||
* Stores previous picked rgb color.
|
||||
* @private
|
||||
* @type {Array.<number,number,number>}
|
||||
* @type {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
this._prevPickingColor = [0, 0, 0];
|
||||
|
||||
|
||||
@ -1469,7 +1469,7 @@ export class Planet extends RenderNode {
|
||||
* Returns 2d screen coordanates projection point to the planet ellipsoid geographical coordinates.
|
||||
* @public
|
||||
* @param {og.math.Pixel} px - 2D screen coordinates.
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
getLonLatFromPixelEllipsoid(px) {
|
||||
var coords = this.getCartesianFromPixelEllipsoid(px);
|
||||
@ -1518,7 +1518,7 @@ export class Planet extends RenderNode {
|
||||
* @public
|
||||
* @param {og.Vec2} px - Pixel screen 2d coordinates.
|
||||
* @param {Boolean} [force=false] - Force framebuffer rendering.
|
||||
* @returns {og.LonLat} -
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
getLonLatFromPixelTerrain(px, force) {
|
||||
var coords = this.getCartesianFromPixelTerrain(px, force);
|
||||
@ -1541,7 +1541,7 @@ export class Planet extends RenderNode {
|
||||
/**
|
||||
* Returns projected 2d screen coordinates by geographical coordinates.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - Geographical coordinates.
|
||||
* @param {LonLat} lonlat - Geographical coordinates.
|
||||
* @returns {og.Vec2} -
|
||||
*/
|
||||
getPixelFromLonLat(lonlat) {
|
||||
@ -1623,7 +1623,7 @@ export class Planet extends RenderNode {
|
||||
/**
|
||||
* Sets camera to the planet geographical extent.
|
||||
* @public
|
||||
* @param {[number,number,number,number]} extentArr - Geographical extent array,
|
||||
* @param {Array.<number>} extentArr - Geographical extent array, (exactly 4 entries)
|
||||
* where index 0 - southwest longitude, 1 - latitude southwest, 2 - longitude northeast, 3 - latitude northeast.
|
||||
*/
|
||||
viewExtentArr(extentArr) {
|
||||
@ -1669,7 +1669,7 @@ export class Planet extends RenderNode {
|
||||
/**
|
||||
* Sets camera to the planet geographical position.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - New geographical position.
|
||||
* @param {LonLat} lonlat - New geographical position.
|
||||
* @param {og.Vec3} [up] - Camera UP vector.
|
||||
*/
|
||||
viewLonLat(lonlat, up) {
|
||||
@ -1723,7 +1723,7 @@ export class Planet extends RenderNode {
|
||||
/**
|
||||
* Fly camera to the new geographical position.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - Fly geographical coordiantes.
|
||||
* @param {LonLat} lonlat - Fly geographical coordiantes.
|
||||
* @param {og.Vec3} [look] - Camera "look at" point on the end of a flying.
|
||||
* @param {og.Vec3} [up] - Camera UP vector on the end of a flying.
|
||||
* @param {Number} [ampl] - Altitude amplitude factor.
|
||||
|
||||
@ -259,7 +259,7 @@ window.ELLNORM = false;
|
||||
* Returns distance from object to terrain coordinates and terrain point that calculates out in the res parameter.
|
||||
* @public
|
||||
* @param {og.Vec3} xyz - Cartesian object position.
|
||||
* @param {og.LonLat} insideSegmentPosition - Geodetic object position.
|
||||
* @param {LonLat} insideSegmentPosition - Geodetic object position.
|
||||
* @param {og.Vec3} [res] - Result cartesian coordiantes on the terrain.
|
||||
* @param {og.Vec3} [normal] - Terrain point normal.
|
||||
* @returns {number} -
|
||||
@ -345,8 +345,8 @@ Segment.prototype.getTerrainPoint = function (xyz, insideSegmentPosition, res, n
|
||||
/**
|
||||
* Project wgs86 to segment native projection.
|
||||
* @public
|
||||
* @param {og.LonLat} lonlat - Coordinates to project.
|
||||
* @returns {og.LonLat} -
|
||||
* @param {LonLat} lonlat - Coordinates to project.
|
||||
* @returns {LonLat} -
|
||||
*/
|
||||
Segment.prototype.projectNative = function (lonlat) {
|
||||
return lonlat.forwardMercator();
|
||||
|
||||
@ -15,7 +15,7 @@ import { Mat4 } from '../math/Mat4.js';
|
||||
* @param {og.Vec3} [options.position] - Shape position.
|
||||
* @param {og.Quat} [options.orientation] - Shape orientation(rotation).
|
||||
* @param {og.Vec3} [options.scale] - Scale vector.
|
||||
* @param {Array.<number,number,number,number>} [options.color] - Shape RGBA color.
|
||||
* @param {Array.<number>} [options.color] - Shape RGBA color. (exactly 4 entries)
|
||||
* @param {string} [options.src] - Texture image url source.
|
||||
* @param {boolean} [options.visibility] - Shape visibility.
|
||||
*/
|
||||
@ -57,7 +57,7 @@ class BaseShape {
|
||||
/**
|
||||
* Shape RGBA color.
|
||||
* @public
|
||||
* @type {Array.<number,number,number,number>}
|
||||
* @type {Array.<number>} - (exactly 4 entries)
|
||||
*/
|
||||
this.color = options.color ? new Float32Array(options.color) : new Float32Array([1.0, 1.0, 1.0, 1.0]);
|
||||
|
||||
@ -164,7 +164,7 @@ class BaseShape {
|
||||
/**
|
||||
* Assigned picking color.
|
||||
* @protected
|
||||
* @type {Array.<number,number,number>}
|
||||
* @type {Array.<number>} - (exactly 3 entries)
|
||||
*/
|
||||
this._pickingColor = [0.0, 0.0, 0.0, 0.0];
|
||||
|
||||
@ -228,7 +228,7 @@ class BaseShape {
|
||||
/**
|
||||
* Sets shape color.
|
||||
* @public
|
||||
* @param {Array.<number,number,number,number>} color - RGBA color values array.
|
||||
* @param {Array.<number>} color - RGBA color values array. (exactly 4 entries)
|
||||
*/
|
||||
setColor(color) {
|
||||
this.color[0] = color[0];
|
||||
|
||||
@ -13,7 +13,7 @@ import { BaseShape } from './BaseShape.js';
|
||||
* @param {og.Vec3} [options.position] - Icosphere position.
|
||||
* @param {og.Quat} [options.orientation] - Icosphere orientation(rotation).
|
||||
* @param {og.Vec3} [options.scale] - Scale vector.
|
||||
* @param {Array.<number,number,number,number>} [options.color] - Icosphere RGBA color.
|
||||
* @param {Array.<number>} [options.color] - Icosphere RGBA color. (exactly 4 entries)
|
||||
* @param {string} [options.src] - Texture image url source.
|
||||
* @param {boolean} [options.visibility] - Icosphere visibility.
|
||||
* @param {number} [options.size] - Icosphere radius.
|
||||
|
||||
@ -13,7 +13,7 @@ import { BaseShape } from './BaseShape.js';
|
||||
* @param {og.Vec3} [options.position] - Sphere position.
|
||||
* @param {og.Quat} [options.orientation] - Sphere orientation(rotation).
|
||||
* @param {og.Vec3} [options.scale] - Scale vector.
|
||||
* @param {Array.<number,number,number,number>} [options.color] - Sphere RGBA color.
|
||||
* @param {Array.<number>} [options.color] - Sphere RGBA color. (exactly 4 entries)
|
||||
* @param {string} [options.src] - Texture image url source.
|
||||
* @param {boolean} [options.visibility] - Sphere visibility.
|
||||
* @param {number} [options.radius=100] - Sphere radius.
|
||||
|
||||
@ -29,7 +29,7 @@ export class GeoImageCreator {
|
||||
/**
|
||||
* Creates geoImage corners coordinates grid buffer.
|
||||
* @public
|
||||
* @param{Array.<og.LonLat>} c - GeoImage corners coordinates.
|
||||
* @param{Array.<LonLat>} c - GeoImage corners coordinates.
|
||||
* @return{WebGLBuffer} Grid coordinates buffer.
|
||||
*/
|
||||
createGridBuffer(c, toMerc) {
|
||||
|
||||
58
tests/math/Quat.test.js
Normal file
58
tests/math/Quat.test.js
Normal file
@ -0,0 +1,58 @@
|
||||
import { Mat4 } from '../../src/og/math/Mat4';
|
||||
import { Quat, quat } from '../../src/og/math/Quat';
|
||||
import { Vec3 } from '../../src/og/math/Vec3';
|
||||
|
||||
describe('Quat class', () => {
|
||||
test('methods', () => {
|
||||
const item = new Quat(1, 1, 2, 3);
|
||||
quat(1, 2, 3, 4);
|
||||
expect(item).toBeTruthy();
|
||||
expect(item.isZero()).toBe(false);
|
||||
expect(item.clear()).toBeTruthy();
|
||||
expect(item.copy(new Quat())).toBeTruthy();
|
||||
expect(item.setIdentity()).toBeTruthy();
|
||||
expect(item.add(new Quat())).toBeTruthy();
|
||||
expect(item.sub(2)).toBeTruthy();
|
||||
expect(item.scale(2)).toBeTruthy();
|
||||
expect(item.scaleTo(2)).toBeTruthy();
|
||||
expect(item.toVec()).toBeTruthy();
|
||||
expect(item.setFromSphericalCoords(1, 1, 1)).toBeTruthy();
|
||||
expect(item.setLookRotation(new Vec3(), new Vec3())).toBeTruthy();
|
||||
expect(item.toSphericalCoords()).toBeTruthy();
|
||||
expect(item.setFromAxisAngle(new Vec3(), 3)).toBeTruthy();
|
||||
expect(item.getAxisAngle()).toBeTruthy();
|
||||
expect(item.setFromEulerAngles(1, 1, 1)).toBeTruthy();
|
||||
expect(item.getEulerAngles()).toBeTruthy();
|
||||
expect(item.setFromMatrix4(new Mat4())).toBeTruthy();
|
||||
expect(item.getMat4(new Mat4())).toBeTruthy();
|
||||
expect(item.getMat3()).toBeTruthy();
|
||||
expect(item.mulVec3(new Vec3())).toBeTruthy();
|
||||
expect(item.mul(new Quat())).toBeTruthy();
|
||||
expect(item.mulA(new Quat())).toBeTruthy();
|
||||
expect(item.conjugate()).toBeTruthy();
|
||||
expect(item.inverse()).toBeTruthy();
|
||||
expect(item.magnitude()).toBeFalsy();
|
||||
expect(item.magnitude2()).toBeFalsy();
|
||||
expect(item.dot(new Quat())).toBeFalsy();
|
||||
expect(item.isEqual(new Quat())).toBe(false);
|
||||
expect(item.slerp(new Quat(), 3)).toBeTruthy();
|
||||
expect(item.getRoll(true)).toBeFalsy();
|
||||
expect(item.getPitch(true)).toBeFalsy();
|
||||
expect(item.getYaw(true)).toBeFalsy();
|
||||
});
|
||||
test('static methods', () => {
|
||||
expect(Quat.IDENTITY).toBeTruthy();
|
||||
const rota = Quat.xRotation(0.3);
|
||||
expect(rota.x > 0).toBe(true);
|
||||
expect(Quat.yRotation(1)).toBeTruthy();
|
||||
expect(Quat.zRotation(1)).toBeTruthy();
|
||||
const vect3 = new Vec3();
|
||||
expect(Quat.axisAngleToQuat(vect3)).toBeTruthy();
|
||||
expect(Quat.axisAngleToQuat(new Vec3(), new Vec3())).toBeTruthy();
|
||||
expect(Quat.getLookRotation(new Vec3(), new Vec3())).toBeTruthy();
|
||||
expect(Quat.getLookAtSourceDest(new Vec3(), new Vec3())).toBeTruthy();
|
||||
expect(Quat.getRotationBetweenVectors(new Vec3(), new Vec3())).toBeTruthy();
|
||||
expect(Quat.getRotationBetweenVectorsRes(new Vec3(), new Vec3(), new Quat())).toBeTruthy();
|
||||
expect(Quat.getRotationBetweenVectorsUp(new Vec3(), new Vec3(), new Vec3())).toBeTruthy();
|
||||
});
|
||||
});
|
||||
18
tests/math/Ray.test.js
Normal file
18
tests/math/Ray.test.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { ray, Ray } from '../../src/og/math/Ray';
|
||||
import { Vec3 } from '../../src/og/math/Vec3';
|
||||
|
||||
describe('Ray class', () => {
|
||||
test('methods', () => {
|
||||
const item = new Ray();
|
||||
expect(Ray.OUTSIDE).toBe(0);
|
||||
expect(Ray.INSIDE).toBe(1);
|
||||
expect(Ray.INPLANE).toBe(2);
|
||||
expect(Ray.AWAY).toBe(3);
|
||||
expect(item.set(new Vec3(), new Vec3())).toBeTruthy();
|
||||
expect(item.getPoint(1000)).toBeTruthy();
|
||||
expect(item.hitTriangle(new Vec3(), new Vec3(), new Vec3(), new Vec3(), 1000)).toBeTruthy();
|
||||
expect(item.hitPlane(new Vec3(), new Vec3(), new Vec3(), new Vec3())).toBe(0);
|
||||
// expect(item.hitPlane(new Sphere(1, new Vec3()))).toBeTruthy();
|
||||
expect(ray()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user