@openglobus/og 0.22.2 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/css/og.css +137 -1
  2. package/lib/@openglobus/js/Globe.d.ts +0 -1
  3. package/lib/@openglobus/js/Object3d.d.ts +20 -10
  4. package/lib/@openglobus/js/camera/Camera.d.ts +57 -15
  5. package/lib/@openglobus/js/camera/Frustum.d.ts +3 -0
  6. package/lib/@openglobus/js/camera/PlanetCamera.d.ts +13 -0
  7. package/lib/@openglobus/js/control/CameraLock.d.ts +38 -0
  8. package/lib/@openglobus/js/control/MouseNavigation.d.ts +62 -51
  9. package/lib/@openglobus/js/control/OldMouseNavigation.d.ts +64 -0
  10. package/lib/@openglobus/js/control/SimpleNavigation.d.ts +27 -10
  11. package/lib/@openglobus/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  12. package/lib/@openglobus/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  13. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  14. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  15. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  16. package/lib/@openglobus/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  17. package/lib/@openglobus/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  18. package/lib/@openglobus/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  19. package/lib/@openglobus/js/control/geoObjectEditor/colors.d.ts +8 -0
  20. package/lib/@openglobus/js/control/index.d.ts +3 -2
  21. package/lib/@openglobus/js/entity/Entity.d.ts +282 -19
  22. package/lib/@openglobus/js/entity/EntityCollection.d.ts +8 -9
  23. package/lib/@openglobus/js/entity/GeoObject.d.ts +135 -39
  24. package/lib/@openglobus/js/entity/GeoObjectHandler.d.ts +39 -63
  25. package/lib/@openglobus/js/entity/InstanceData.d.ts +76 -0
  26. package/lib/@openglobus/js/entity/Polyline.d.ts +19 -6
  27. package/lib/@openglobus/js/entity/PolylineHandler.d.ts +7 -0
  28. package/lib/@openglobus/js/index.d.ts +2 -1
  29. package/lib/@openglobus/js/input/MouseHandler.d.ts +1 -0
  30. package/lib/@openglobus/js/layer/Vector.d.ts +4 -0
  31. package/lib/@openglobus/js/light/LightSource.d.ts +1 -139
  32. package/lib/@openglobus/js/math/Mat3.d.ts +1 -1
  33. package/lib/@openglobus/js/math/Mat4.d.ts +10 -1
  34. package/lib/@openglobus/js/math/Plane.d.ts +3 -1
  35. package/lib/@openglobus/js/math/Quat.d.ts +47 -33
  36. package/lib/@openglobus/js/math/Ray.d.ts +10 -14
  37. package/lib/@openglobus/js/math/Vec2.d.ts +22 -0
  38. package/lib/@openglobus/js/math/Vec3.d.ts +15 -0
  39. package/lib/@openglobus/js/math.d.ts +2 -2
  40. package/lib/@openglobus/js/quadTree/EntityCollectionNode.d.ts +2 -2
  41. package/lib/@openglobus/js/quadTree/Node.d.ts +1 -1
  42. package/lib/@openglobus/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  43. package/lib/@openglobus/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  44. package/lib/@openglobus/js/renderer/Renderer.d.ts +63 -44
  45. package/lib/@openglobus/js/renderer/RendererEvents.d.ts +2 -0
  46. package/lib/@openglobus/js/scene/Planet.d.ts +15 -7
  47. package/lib/@openglobus/js/scene/RenderNode.d.ts +10 -25
  48. package/lib/@openglobus/js/shaders/drawnode.d.ts +1 -0
  49. package/lib/@openglobus/js/shaders/geoObject.d.ts +1 -0
  50. package/lib/@openglobus/js/shaders/utils.d.ts +1 -1
  51. package/lib/@openglobus/js/ui/Checkbox.d.ts +31 -0
  52. package/lib/@openglobus/js/ui/Dialog.d.ts +3 -0
  53. package/lib/@openglobus/js/ui/Input.d.ts +32 -0
  54. package/lib/@openglobus/js/ui/View.d.ts +3 -1
  55. package/lib/@openglobus/js/utils/objParser.d.ts +44 -12
  56. package/lib/@openglobus/js/utils/shared.d.ts +22 -0
  57. package/lib/@openglobus/js/webgl/BaseFramebuffer.d.ts +0 -1
  58. package/lib/@openglobus/js/webgl/Framebuffer.d.ts +35 -8
  59. package/lib/@openglobus/js/webgl/Handler.d.ts +22 -12
  60. package/lib/@openglobus/og.css +1 -1
  61. package/lib/@openglobus/og.esm.js +1 -1
  62. package/lib/@openglobus/og.esm.js.map +1 -1
  63. package/lib/@openglobus/og.umd.js +1 -1
  64. package/lib/@openglobus/og.umd.js.map +1 -1
  65. package/lib/js/Globe.d.ts +0 -1
  66. package/lib/js/Globe.js +4 -2
  67. package/lib/js/Object3d.d.ts +20 -10
  68. package/lib/js/Object3d.js +124 -48
  69. package/lib/js/Popup.js +1 -1
  70. package/lib/js/camera/Camera.d.ts +57 -15
  71. package/lib/js/camera/Camera.js +109 -29
  72. package/lib/js/camera/Frustum.d.ts +3 -0
  73. package/lib/js/camera/Frustum.js +7 -0
  74. package/lib/js/camera/PlanetCamera.d.ts +13 -0
  75. package/lib/js/camera/PlanetCamera.js +52 -5
  76. package/lib/js/control/Atmosphere.js +10 -6
  77. package/lib/js/control/CameraLock.d.ts +38 -0
  78. package/lib/js/control/CameraLock.js +216 -0
  79. package/lib/js/control/Control.js +1 -1
  80. package/lib/js/control/DebugInfo.js +38 -8
  81. package/lib/js/control/KeyboardNavigation.js +9 -9
  82. package/lib/js/control/MouseNavigation.d.ts +62 -51
  83. package/lib/js/control/MouseNavigation.js +361 -305
  84. package/lib/js/control/MouseWheelZoomControl.d.ts +0 -44
  85. package/lib/js/control/MouseWheelZoomControl.js +270 -181
  86. package/lib/js/control/OldMouseNavigation.d.ts +64 -0
  87. package/lib/js/control/OldMouseNavigation.js +368 -0
  88. package/lib/js/control/ScaleControl.js +11 -5
  89. package/lib/js/control/SimpleNavigation.d.ts +27 -10
  90. package/lib/js/control/SimpleNavigation.js +149 -49
  91. package/lib/js/control/Sun.js +6 -6
  92. package/lib/js/control/TouchNavigation.js +11 -8
  93. package/lib/js/control/elevationProfile/ElevationProfileScene.js +6 -5
  94. package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  95. package/lib/js/control/geoObjectEditor/ArrowEntity.js +59 -0
  96. package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  97. package/lib/js/control/geoObjectEditor/AxisTrackEntity.js +93 -0
  98. package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  99. package/lib/js/control/geoObjectEditor/GeoObjectEditor.js +30 -0
  100. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  101. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +488 -0
  102. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  103. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +487 -43
  104. package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  105. package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +107 -0
  106. package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  107. package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +31 -0
  108. package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  109. package/lib/js/control/geoObjectEditor/RotateEntity.js +105 -0
  110. package/lib/js/control/geoObjectEditor/colors.d.ts +8 -0
  111. package/lib/js/control/geoObjectEditor/colors.js +8 -0
  112. package/lib/js/control/index.d.ts +3 -2
  113. package/lib/js/control/index.js +3 -2
  114. package/lib/js/control/timeline/TimelineControl.js +2 -0
  115. package/lib/js/control/visibleExtent/Segment.js +4 -4
  116. package/lib/js/entity/Entity.d.ts +282 -19
  117. package/lib/js/entity/Entity.js +497 -62
  118. package/lib/js/entity/EntityCollection.d.ts +8 -9
  119. package/lib/js/entity/EntityCollection.js +48 -45
  120. package/lib/js/entity/GeoObject.d.ts +135 -39
  121. package/lib/js/entity/GeoObject.js +150 -90
  122. package/lib/js/entity/GeoObjectHandler.d.ts +39 -63
  123. package/lib/js/entity/GeoObjectHandler.js +198 -295
  124. package/lib/js/entity/InstanceData.d.ts +76 -0
  125. package/lib/js/entity/InstanceData.js +347 -0
  126. package/lib/js/entity/Polyline.d.ts +19 -6
  127. package/lib/js/entity/Polyline.js +76 -36
  128. package/lib/js/entity/PolylineHandler.d.ts +7 -0
  129. package/lib/js/entity/PolylineHandler.js +26 -1
  130. package/lib/js/index.d.ts +2 -1
  131. package/lib/js/index.js +2 -1
  132. package/lib/js/input/MouseHandler.d.ts +1 -0
  133. package/lib/js/input/MouseHandler.js +12 -1
  134. package/lib/js/layer/Bing.js +2 -2
  135. package/lib/js/layer/Vector.d.ts +4 -0
  136. package/lib/js/layer/Vector.js +16 -0
  137. package/lib/js/light/LightSource.d.ts +1 -139
  138. package/lib/js/light/LightSource.js +21 -227
  139. package/lib/js/math/Mat3.d.ts +1 -1
  140. package/lib/js/math/Mat3.js +1 -1
  141. package/lib/js/math/Mat4.d.ts +10 -1
  142. package/lib/js/math/Mat4.js +17 -1
  143. package/lib/js/math/Plane.d.ts +3 -1
  144. package/lib/js/math/Plane.js +11 -1
  145. package/lib/js/math/Quat.d.ts +47 -33
  146. package/lib/js/math/Quat.js +92 -90
  147. package/lib/js/math/Ray.d.ts +10 -14
  148. package/lib/js/math/Ray.js +56 -33
  149. package/lib/js/math/Vec2.d.ts +22 -0
  150. package/lib/js/math/Vec2.js +32 -0
  151. package/lib/js/math/Vec3.d.ts +15 -0
  152. package/lib/js/math/Vec3.js +30 -1
  153. package/lib/js/math.d.ts +2 -2
  154. package/lib/js/math.js +3 -3
  155. package/lib/js/quadTree/EntityCollectionNode.d.ts +2 -2
  156. package/lib/js/quadTree/EntityCollectionNode.js +8 -8
  157. package/lib/js/quadTree/Node.d.ts +1 -1
  158. package/lib/js/quadTree/Node.js +2 -2
  159. package/lib/js/quadTree/QuadTreeStrategy.js +1 -1
  160. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  161. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.js +2 -2
  162. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  163. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.js +2 -2
  164. package/lib/js/renderer/Renderer.d.ts +63 -44
  165. package/lib/js/renderer/Renderer.js +267 -266
  166. package/lib/js/renderer/RendererEvents.d.ts +2 -0
  167. package/lib/js/renderer/RendererEvents.js +5 -2
  168. package/lib/js/scene/Planet.d.ts +15 -7
  169. package/lib/js/scene/Planet.js +133 -90
  170. package/lib/js/scene/RenderNode.d.ts +10 -25
  171. package/lib/js/scene/RenderNode.js +70 -58
  172. package/lib/js/segment/Segment.js +4 -4
  173. package/lib/js/shaders/depth.js +2 -5
  174. package/lib/js/shaders/drawnode.d.ts +1 -0
  175. package/lib/js/shaders/drawnode.js +51 -52
  176. package/lib/js/shaders/geoObject.d.ts +1 -0
  177. package/lib/js/shaders/geoObject.js +154 -91
  178. package/lib/js/shaders/polyline.js +68 -51
  179. package/lib/js/shaders/utils.d.ts +1 -1
  180. package/lib/js/shaders/utils.js +11 -0
  181. package/lib/js/terrain/GlobusTerrain.js +2 -2
  182. package/lib/js/ui/Checkbox.d.ts +31 -0
  183. package/lib/js/ui/Checkbox.js +110 -0
  184. package/lib/js/ui/Color.js +2 -1
  185. package/lib/js/ui/Dialog.d.ts +3 -0
  186. package/lib/js/ui/Dialog.js +20 -0
  187. package/lib/js/ui/Input.d.ts +32 -0
  188. package/lib/js/ui/Input.js +107 -0
  189. package/lib/js/ui/View.d.ts +3 -1
  190. package/lib/js/ui/View.js +6 -0
  191. package/lib/js/utils/objParser.d.ts +44 -12
  192. package/lib/js/utils/objParser.js +241 -149
  193. package/lib/js/utils/shared.d.ts +22 -0
  194. package/lib/js/utils/shared.js +34 -0
  195. package/lib/js/webgl/BaseFramebuffer.d.ts +0 -1
  196. package/lib/js/webgl/Framebuffer.d.ts +35 -8
  197. package/lib/js/webgl/Framebuffer.js +136 -29
  198. package/lib/js/webgl/Handler.d.ts +22 -12
  199. package/lib/js/webgl/Handler.js +53 -34
  200. package/lib/js/webgl/Program.js +0 -8
  201. package/package.json +5 -3
  202. package/lib/@openglobus/js/control/EarthNavigation.d.ts +0 -50
  203. package/lib/@openglobus/js/control/MouseWheelZoomControl.d.ts +0 -44
  204. package/lib/js/control/EarthNavigation.d.ts +0 -50
  205. package/lib/js/control/EarthNavigation.js +0 -202
@@ -118,13 +118,18 @@ export declare class Quat {
118
118
  * @returns {Quat} -
119
119
  */
120
120
  static getRotationBetweenVectorsUp(source: Vec3, dest: Vec3, up: Vec3): Quat;
121
- static setFromEulerAngles(pitch: number, yaw: number, roll: number): Quat;
122
121
  /**
123
122
  * Returns true if the components are zero.
124
123
  * @public
125
124
  * @returns {boolean} -
126
125
  */
127
126
  isZero(): boolean;
127
+ /**
128
+ * Returns true if a component is NaN.
129
+ * @public
130
+ * @returns {boolean} -
131
+ */
132
+ isNaN(): boolean;
128
133
  /**
129
134
  * Clear Quat. Sets zeroes.
130
135
  * @public
@@ -167,6 +172,13 @@ export declare class Quat {
167
172
  * @returns {Quat} -
168
173
  */
169
174
  add(q: Quat): Quat;
175
+ /**
176
+ * Computes the componentwise sum of two Quats.
177
+ * @public
178
+ * @param {Quat} q - Quat to add.
179
+ * @returns {Quat} -
180
+ */
181
+ addRes(q: Quat, res: Quat): Quat;
170
182
  /**
171
183
  * Computes the componentwise difference of two Quats.
172
184
  * @public
@@ -194,6 +206,15 @@ export declare class Quat {
194
206
  * @returns {Array.<number>} - (exactly 4 entries)
195
207
  */
196
208
  toVec(): [number, number, number, number];
209
+ get xyz(): Vec3;
210
+ /**
211
+ * Sets rotation with the given heading and up vectors.
212
+ * @static
213
+ * @param {Vec3} forward - Heading target coordinates.
214
+ * @param {Vec3} up - Up vector.
215
+ * @returns {Quat} -
216
+ */
217
+ setLookRotation(forward: Vec3, up: Vec3): Quat;
197
218
  /**
198
219
  * Sets current quaternion by spherical coordinates.
199
220
  * @public
@@ -203,20 +224,12 @@ export declare class Quat {
203
224
  * @returns {Quat} -
204
225
  */
205
226
  setFromSphericalCoords(lat: number, lon: number, angle: number): Quat;
206
- /**
207
- * Sets rotation with the given heading and up vectors.
208
- * @static
209
- * @param {Vec3} forward - Heading target coordinates.
210
- * @param {Vec3} up - Up vector.
211
- * @returns {Quat} -
212
- */
213
- setLookRotation(forward: Vec3, up: Vec3): Quat;
214
227
  /**
215
228
  * Gets spherical coordinates.
216
229
  * @public
217
230
  * @returns {Object} Returns object with latitude, longitude and alpha.
218
231
  */
219
- toSphericalCoords(): any;
232
+ getSphericalCoords(): any;
220
233
  /**
221
234
  * Sets current Quat representing a rotation around an axis.
222
235
  * @public
@@ -228,9 +241,16 @@ export declare class Quat {
228
241
  /**
229
242
  * Returns axis and angle of the current Quat.
230
243
  * @public
231
- * @returns {Object} -
244
+ * @returns { axis: Vec3, angle: number } -
232
245
  */
233
- getAxisAngle(): any;
246
+ getAxisAngle(): {
247
+ axis: Vec3;
248
+ angle: number;
249
+ };
250
+ getPitch(): number;
251
+ getYaw(): number;
252
+ getRoll(): number;
253
+ setPitchYawRoll(pitchRad: number, yawRad: number, rollRad: number, frame?: Quat): Quat;
234
254
  /**
235
255
  * Sets current Quat by Euler's angles.
236
256
  * @public
@@ -274,6 +294,14 @@ export declare class Quat {
274
294
  * @returns {Vec3} -
275
295
  */
276
296
  mulVec3(v: Vec3): Vec3;
297
+ /**
298
+ * Returns quaternion and vector production.
299
+ * @public
300
+ * @param {Vec3} v - 3d Vector.
301
+ * @param {Vec3} res - result output vector.
302
+ * @returns {Vec3} -
303
+ */
304
+ mulVec3Res(v: Vec3, res: Vec3): Vec3;
277
305
  /**
278
306
  * Computes the product of two Quats.
279
307
  * @public
@@ -281,6 +309,13 @@ export declare class Quat {
281
309
  * @returns {Quat} -
282
310
  */
283
311
  mul(q: Quat): Quat;
312
+ /**
313
+ * Computes the product of two Quats.
314
+ * @public
315
+ * @param {Quat} q - Quat to multiply.
316
+ * @returns {Quat} -
317
+ */
318
+ mulRes(q: Quat, res: Quat): Quat;
284
319
  /**
285
320
  * Computes the product of two Quats.
286
321
  * @public
@@ -340,27 +375,6 @@ export declare class Quat {
340
375
  * @returns {Quat} -
341
376
  */
342
377
  slerp(b: Quat, t: number): Quat;
343
- /**
344
- * Returns a roll angle in radians.
345
- * @public
346
- * @param {Boolean} [reprojectAxis] -
347
- * @returns {Number} -
348
- */
349
- getRoll(reprojectAxis?: boolean): number;
350
- /**
351
- * Returns a pitch angle in radians.
352
- * @public
353
- * @param {Boolean} [reprojectAxis] -
354
- * @returns {number} -
355
- */
356
- getPitch(reprojectAxis?: boolean): number;
357
- /**
358
- * Returns a yaw angle in radians.
359
- * @public
360
- * @param {Boolean} [reprojectAxis] -
361
- * @returns {number} -
362
- */
363
- getYaw(reprojectAxis?: boolean): number;
364
378
  }
365
379
  /**
366
380
  * Creates Quat instance.
@@ -2,6 +2,7 @@ import * as math from "../math";
2
2
  import { Vec3 } from "./Vec3";
3
3
  import { Mat4 } from "./Mat4";
4
4
  import { Mat3 } from "./Mat3";
5
+ import { PI_TWO } from "../math";
5
6
  /**
6
7
  * A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.
7
8
  * @constructor
@@ -166,10 +167,10 @@ export class Quat {
166
167
  let rotAxis = source.cross(dest).normalize();
167
168
  return Quat.axisAngleToQuat(rotAxis, rotAngle);
168
169
  }
169
- static setFromEulerAngles(pitch, yaw, roll) {
170
- let res = new Quat();
171
- return res.setFromEulerAngles(pitch, yaw, roll);
172
- }
170
+ // static setFromEulerAngles(pitch: number, yaw: number, roll: number): Quat {
171
+ // let res = new Quat();
172
+ // return res.setFromEulerAngles(pitch, yaw, roll);
173
+ // }
173
174
  /**
174
175
  * Returns true if the components are zero.
175
176
  * @public
@@ -178,6 +179,14 @@ export class Quat {
178
179
  isZero() {
179
180
  return this.x === 0.0 && this.y === 0.0 && this.z === 0.0 && this.w === 0.0;
180
181
  }
182
+ /**
183
+ * Returns true if a component is NaN.
184
+ * @public
185
+ * @returns {boolean} -
186
+ */
187
+ isNaN() {
188
+ return isNaN(this.x) || isNaN(this.y) || isNaN(this.z) || isNaN(this.w);
189
+ }
181
190
  /**
182
191
  * Clear Quat. Sets zeroes.
183
192
  * @public
@@ -245,6 +254,15 @@ export class Quat {
245
254
  add(q) {
246
255
  return new Quat(this.x + q.x, this.y + q.y, this.z + q.z, this.w + q.w);
247
256
  }
257
+ /**
258
+ * Computes the componentwise sum of two Quats.
259
+ * @public
260
+ * @param {Quat} q - Quat to add.
261
+ * @returns {Quat} -
262
+ */
263
+ addRes(q, res) {
264
+ return res.set(this.x + q.x, this.y + q.y, this.z + q.z, this.w + q.w);
265
+ }
248
266
  /**
249
267
  * Computes the componentwise difference of two Quats.
250
268
  * @public
@@ -284,26 +302,8 @@ export class Quat {
284
302
  toVec() {
285
303
  return [this.x, this.y, this.z, this.w];
286
304
  }
287
- /**
288
- * Sets current quaternion by spherical coordinates.
289
- * @public
290
- * @param {number} lat - Latitude.
291
- * @param {number} lon - Longitude.
292
- * @param {number} angle - Angle in radians.
293
- * @returns {Quat} -
294
- */
295
- setFromSphericalCoords(lat, lon, angle) {
296
- let sin_a = Math.sin(angle / 2);
297
- let cos_a = Math.cos(angle / 2);
298
- let sin_lat = Math.sin(lat);
299
- let cos_lat = Math.cos(lat);
300
- let sin_long = Math.sin(lon);
301
- let cos_long = Math.cos(lon);
302
- this.x = sin_a * cos_lat * sin_long;
303
- this.y = sin_a * sin_lat;
304
- this.z = sin_a * sin_lat * cos_long;
305
- this.w = cos_a;
306
- return this;
305
+ get xyz() {
306
+ return new Vec3(this.x, this.y, this.z);
307
307
  }
308
308
  /**
309
309
  * Sets rotation with the given heading and up vectors.
@@ -347,12 +347,33 @@ export class Quat {
347
347
  }
348
348
  return this;
349
349
  }
350
+ /**
351
+ * Sets current quaternion by spherical coordinates.
352
+ * @public
353
+ * @param {number} lat - Latitude.
354
+ * @param {number} lon - Longitude.
355
+ * @param {number} angle - Angle in radians.
356
+ * @returns {Quat} -
357
+ */
358
+ setFromSphericalCoords(lat, lon, angle) {
359
+ let sin_a = Math.sin(angle / 2);
360
+ let cos_a = Math.cos(angle / 2);
361
+ let sin_lat = Math.sin(lat);
362
+ let cos_lat = Math.cos(lat);
363
+ let sin_long = Math.sin(lon);
364
+ let cos_long = Math.cos(lon);
365
+ this.x = sin_a * cos_lat * sin_long;
366
+ this.y = sin_a * sin_lat;
367
+ this.z = sin_a * sin_lat * cos_long;
368
+ this.w = cos_a;
369
+ return this;
370
+ }
350
371
  /**
351
372
  * Gets spherical coordinates.
352
373
  * @public
353
374
  * @returns {Object} Returns object with latitude, longitude and alpha.
354
375
  */
355
- toSphericalCoords() {
376
+ getSphericalCoords() {
356
377
  let cos_a = this.w;
357
378
  let sin_a = Math.sqrt(1.0 - cos_a * cos_a);
358
379
  // var angle = Math.acos(cos_a) * 2;
@@ -395,7 +416,7 @@ export class Quat {
395
416
  /**
396
417
  * Returns axis and angle of the current Quat.
397
418
  * @public
398
- * @returns {Object} -
419
+ * @returns { axis: Vec3, angle: number } -
399
420
  */
400
421
  getAxisAngle() {
401
422
  let x = this.x, y = this.y, z = this.z, w = this.w;
@@ -420,6 +441,24 @@ export class Quat {
420
441
  angle: angle
421
442
  };
422
443
  }
444
+ getPitch() {
445
+ let sinPitch = -2 * (this.y * this.z - this.w * this.x);
446
+ return Math.abs(sinPitch) >= 1
447
+ ? Math.sign(sinPitch) * PI_TWO
448
+ : Math.asin(sinPitch);
449
+ }
450
+ getYaw() {
451
+ return -Math.atan2(2 * (this.x * this.z + this.w * this.y), 1 - 2 * (this.y * this.y + this.x * this.x));
452
+ }
453
+ getRoll() {
454
+ return Math.atan2(2 * (this.x * this.y + this.w * this.z), 1 - 2 * (this.z * this.z + this.x * this.x));
455
+ }
456
+ setPitchYawRoll(pitchRad, yawRad, rollRad, frame = Quat.IDENTITY) {
457
+ let qp = Quat.xRotation(-pitchRad);
458
+ let qy = Quat.yRotation(yawRad);
459
+ let qr = Quat.zRotation(-rollRad);
460
+ return this.copy(qr.mul(qp).mul(qy).mul(frame).conjugate());
461
+ }
423
462
  /**
424
463
  * Sets current Quat by Euler's angles.
425
464
  * @public
@@ -574,6 +613,22 @@ export class Quat {
574
613
  d = -b * d - f * e - h * g;
575
614
  return new Vec3(i * a + d * -b + j * -h - k * -f, j * a + d * -f + k * -b - i * -h, k * a + d * -h + i * -f - j * -b);
576
615
  }
616
+ /**
617
+ * Returns quaternion and vector production.
618
+ * @public
619
+ * @param {Vec3} v - 3d Vector.
620
+ * @param {Vec3} res - result output vector.
621
+ * @returns {Vec3} -
622
+ */
623
+ mulVec3Res(v, res) {
624
+ // t = 2 * cross(q.xyz, v)
625
+ // v' = v + q.w * t + cross(q.xyz, t)
626
+ let d = v.x, e = v.y, g = v.z;
627
+ let b = this.x, f = this.y, h = this.z, a = this.w;
628
+ let i = a * d + f * g - h * e, j = a * e + h * d - b * g, k = a * g + b * e - f * d;
629
+ d = -b * d - f * e - h * g;
630
+ return res.set(i * a + d * -b + j * -h - k * -f, j * a + d * -f + k * -b - i * -h, k * a + d * -h + i * -f - j * -b);
631
+ }
577
632
  /**
578
633
  * Computes the product of two Quats.
579
634
  * @public
@@ -585,6 +640,17 @@ export class Quat {
585
640
  let f = q.x, h = q.y, i = q.z, b = q.w;
586
641
  return new Quat(d * b + a * f + e * i - g * h, e * b + a * h + g * f - d * i, g * b + a * i + d * h - e * f, a * b - d * f - e * h - g * i);
587
642
  }
643
+ /**
644
+ * Computes the product of two Quats.
645
+ * @public
646
+ * @param {Quat} q - Quat to multiply.
647
+ * @returns {Quat} -
648
+ */
649
+ mulRes(q, res) {
650
+ let d = this.x, e = this.y, g = this.z, a = this.w;
651
+ let f = q.x, h = q.y, i = q.z, b = q.w;
652
+ return res.set(d * b + a * f + e * i - g * h, e * b + a * h + g * f - d * i, g * b + a * i + d * h - e * f, a * b - d * f - e * h - g * i);
653
+ }
588
654
  /**
589
655
  * Computes the product of two Quats.
590
656
  * @public
@@ -708,70 +774,6 @@ export class Quat {
708
774
  }
709
775
  return new Quat(scale0 * ax + scale1 * bx, scale0 * ay + scale1 * by, scale0 * az + scale1 * bz, scale0 * aw + scale1 * bw);
710
776
  }
711
- /**
712
- * Returns a roll angle in radians.
713
- * @public
714
- * @param {Boolean} [reprojectAxis] -
715
- * @returns {Number} -
716
- */
717
- getRoll(reprojectAxis = false) {
718
- let x = this.x, y = this.y, z = this.z, w = this.w;
719
- if (reprojectAxis) {
720
- let fTy = 2.0 * y;
721
- let fTz = 2.0 * z;
722
- let fTwz = fTz * w;
723
- let fTxy = fTy * x;
724
- let fTyy = fTy * y;
725
- let fTzz = fTz * z;
726
- return Math.atan2(fTxy + fTwz, 1.0 - (fTyy + fTzz));
727
- }
728
- else {
729
- return Math.atan2(2 * (x * y + w * z), w * w + x * x - y * y - z * z);
730
- }
731
- }
732
- /**
733
- * Returns a pitch angle in radians.
734
- * @public
735
- * @param {Boolean} [reprojectAxis] -
736
- * @returns {number} -
737
- */
738
- getPitch(reprojectAxis = false) {
739
- let x = this.x, y = this.y, z = this.z, w = this.w;
740
- if (reprojectAxis) {
741
- let fTx = 2.0 * x;
742
- let fTz = 2.0 * z;
743
- let fTwx = fTx * w;
744
- let fTxx = fTx * x;
745
- let fTyz = fTz * y;
746
- let fTzz = fTz * z;
747
- return Math.atan2(fTyz + fTwx, 1.0 - (fTxx + fTzz));
748
- }
749
- else {
750
- return Math.atan2(2 * (y * z + w * x), w * w - x * x - y * y + z * z);
751
- }
752
- }
753
- /**
754
- * Returns a yaw angle in radians.
755
- * @public
756
- * @param {Boolean} [reprojectAxis] -
757
- * @returns {number} -
758
- */
759
- getYaw(reprojectAxis = false) {
760
- let x = this.x, y = this.y, z = this.z, w = this.w;
761
- if (reprojectAxis) {
762
- let fTx = 2.0 * x;
763
- let fTy = 2.0 * y;
764
- let fTz = 2.0 * z;
765
- let fTwy = fTy * w;
766
- let fTxx = fTx * x;
767
- let fTxz = fTz * x;
768
- let fTyy = fTy * y;
769
- return Math.atan2(fTxz + fTwy, 1.0 - (fTxx + fTyy));
770
- }
771
- else {
772
- return Math.asin(-2 * (x * z - w * y));
773
- }
774
- }
775
777
  }
776
778
  /**
777
779
  * Creates Quat instance.
@@ -1,6 +1,7 @@
1
1
  import { Box } from "../bv/Box";
2
2
  import { Sphere } from "../bv/Sphere";
3
3
  import { Vec3 } from "./Vec3";
4
+ import { Plane } from "./Plane";
4
5
  /**
5
6
  * Represents a ray that extends infinitely from the provided origin in the provided direction.
6
7
  * @class
@@ -38,14 +39,13 @@ export declare class Ray {
38
39
  */
39
40
  set(origin: Vec3, direction: Vec3): Ray;
40
41
  /**
41
- * Computes the point along the ray on the distance.
42
- * @public
43
- * @param {number} distance - Point distance.
44
- * @returns {Vec3}
42
+ * Get a point on the ray at a given distance `t`.
43
+ * @param {number} distance - Distance from the origin along the ray.
44
+ * @returns {Vec3} The point at distance `t`.
45
45
  */
46
46
  getPoint(distance: number): Vec3;
47
47
  /**
48
- * Returns ray hit a triange result.
48
+ * Returns ray hit a triangle result.
49
49
  * @public
50
50
  * @param {Vec3} v0 - First triangle corner coordinate.
51
51
  * @param {Vec3} v1 - Second triangle corner coordinate.
@@ -54,17 +54,13 @@ export declare class Ray {
54
54
  * @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
55
55
  * 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
56
56
  */
57
- hitTriangle(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number;
57
+ hitTriangleRes(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number;
58
58
  /**
59
- * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
60
- * @public
61
- * @param {Vec3} v0 - First plane point.
62
- * @param {Vec3} v1 - Second plane point.
63
- * @param {Vec3} v2 - Third plane point.
64
- * @param {Vec3} res - Hit point object pointer that stores hit result.
65
- * @returns {number}
59
+ * Finds the intersection of the ray with a plane.
60
+ * @param {Plane} plane - The plane to intersect with.
61
+ * @returns {Vec3 | null} The intersection point or null if no intersection.
66
62
  */
67
- hitPlane(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number;
63
+ hitPlaneRes(plane: Plane, res: Vec3): number;
68
64
  /**
69
65
  * Returns a ray hit sphere coordiante. If there isn't hit returns null.
70
66
  * @public
@@ -40,16 +40,15 @@ export class Ray {
40
40
  return this;
41
41
  }
42
42
  /**
43
- * Computes the point along the ray on the distance.
44
- * @public
45
- * @param {number} distance - Point distance.
46
- * @returns {Vec3}
43
+ * Get a point on the ray at a given distance `t`.
44
+ * @param {number} distance - Distance from the origin along the ray.
45
+ * @returns {Vec3} The point at distance `t`.
47
46
  */
48
47
  getPoint(distance) {
49
48
  return Vec3.add(this.origin, this.direction.scaleTo(distance));
50
49
  }
51
50
  /**
52
- * Returns ray hit a triange result.
51
+ * Returns ray hit a triangle result.
53
52
  * @public
54
53
  * @param {Vec3} v0 - First triangle corner coordinate.
55
54
  * @param {Vec3} v1 - Second triangle corner coordinate.
@@ -58,7 +57,7 @@ export class Ray {
58
57
  * @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
59
58
  * 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
60
59
  */
61
- hitTriangle(v0, v1, v2, res) {
60
+ hitTriangleRes(v0, v1, v2, res) {
62
61
  let u = v1.sub(v0);
63
62
  let v = v2.sub(v0);
64
63
  let n = u.cross(v);
@@ -102,37 +101,61 @@ export class Ray {
102
101
  }
103
102
  return Ray.INSIDE;
104
103
  }
104
+ // /**
105
+ // * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
106
+ // * @public
107
+ // * @param {Vec3} v0 - First plane point.
108
+ // * @param {Vec3} v1 - Second plane point.
109
+ // * @param {Vec3} v2 - Third plane point.
110
+ // * @param {Vec3} res - Hit point object pointer that stores hit result.
111
+ // * @returns {number}
112
+ // */
113
+ // public hitPlaneRes(v0: Vec3, v1: Vec3, v2: Vec3, res: Vec3): number {
114
+ // let u = Vec3.sub(v1, v0);
115
+ // let v = Vec3.sub(v2, v0);
116
+ // let n = u.cross(v);
117
+ //
118
+ // let w0 = Vec3.sub(this.origin, v0);
119
+ // let a = -n.dot(w0);
120
+ // let b = n.dot(this.direction);
121
+ //
122
+ // // ray is parallel to the plane
123
+ // if (Math.abs(b) < EPS10) {
124
+ // if (a === 0) {
125
+ // return Ray.OUTSIDE;
126
+ // }
127
+ // }
128
+ //
129
+ // let r = a / b;
130
+ //
131
+ // if (r < 0) {
132
+ // return Ray.OUTSIDE;
133
+ // }
134
+ //
135
+ // let d = this.direction.scaleTo(r);
136
+ //
137
+ // // intersect point of ray and plane
138
+ // res.x = this.origin.x + d.x;
139
+ // res.y = this.origin.y + d.y;
140
+ // res.z = this.origin.z + d.z;
141
+ //
142
+ // return Ray.INSIDE;
143
+ // }
105
144
  /**
106
- * Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
107
- * @public
108
- * @param {Vec3} v0 - First plane point.
109
- * @param {Vec3} v1 - Second plane point.
110
- * @param {Vec3} v2 - Third plane point.
111
- * @param {Vec3} res - Hit point object pointer that stores hit result.
112
- * @returns {number}
145
+ * Finds the intersection of the ray with a plane.
146
+ * @param {Plane} plane - The plane to intersect with.
147
+ * @returns {Vec3 | null} The intersection point or null if no intersection.
113
148
  */
114
- hitPlane(v0, v1, v2, res) {
115
- let u = Vec3.sub(v1, v0);
116
- let v = Vec3.sub(v2, v0);
117
- let n = u.cross(v);
118
- let w0 = Vec3.sub(this.origin, v0);
119
- let a = -n.dot(w0);
120
- let b = n.dot(this.direction);
121
- // ray is parallel to the plane
122
- if (Math.abs(b) < EPS10) {
123
- if (a === 0) {
124
- return Ray.OUTSIDE;
125
- }
126
- }
127
- let r = a / b;
128
- if (r < 0) {
149
+ hitPlaneRes(plane, res) {
150
+ const d = this.direction.dot(plane.n);
151
+ if (Math.abs(d) < EPS10) {
129
152
  return Ray.OUTSIDE;
130
153
  }
131
- let d = this.direction.scaleTo(r);
132
- // intersect point of ray and plane
133
- res.x = this.origin.x + d.x;
134
- res.y = this.origin.y + d.y;
135
- res.z = this.origin.z + d.z;
154
+ const t = plane.p.sub(this.origin).dot(plane.n) / d;
155
+ if (t < 0) {
156
+ return Ray.AWAY;
157
+ }
158
+ res.copy(this.getPoint(t));
136
159
  return Ray.INSIDE;
137
160
  }
138
161
  /**
@@ -92,6 +92,15 @@ export declare class Vec2 {
92
92
  * @returns {Vec2}
93
93
  */
94
94
  static orthoNormalize(normal: Vec2, tangent: Vec2): Vec2;
95
+ /**
96
+ * Get projection of the vector to plane where n - normal to the plane.
97
+ * @static
98
+ * @param {Vec2} b - Vector to project.
99
+ * @param {Vec2} n - Plane normal.
100
+ * @param {Vec2} [def] - Default value for non existed result.
101
+ * @returns {Vec2} -
102
+ */
103
+ static proj_b_to_plane(b: Vec2, n: Vec2, def?: Vec3): Vec2;
95
104
  /**
96
105
  * Converts to 3d vector, third value is 0.0.
97
106
  * @public
@@ -221,10 +230,17 @@ export declare class Vec2 {
221
230
  clear(): Vec2;
222
231
  /**
223
232
  * Returns normalized vector.
233
+ * @deprecated
224
234
  * @public
225
235
  * @returns {Vec2}
226
236
  */
227
237
  normal(): Vec2;
238
+ /**
239
+ * Returns normalized vector.
240
+ * @public
241
+ * @returns {Vec2}
242
+ */
243
+ getNormal(): Vec2;
228
244
  /**
229
245
  * Normalize current vector.
230
246
  * @public
@@ -299,6 +315,12 @@ export declare class Vec2 {
299
315
  * @returns {Vec2}
300
316
  */
301
317
  slerp(v2: Vec2, t: number): Vec2;
318
+ /**
319
+ * Returns true if vector's values are zero.
320
+ * @public
321
+ * @returns {boolean} -
322
+ */
323
+ isZero(): boolean;
302
324
  }
303
325
  /**
304
326
  * Vector 2d object creator.
@@ -122,6 +122,21 @@ export class Vec2 {
122
122
  normal.scale(tangent.dot(normal));
123
123
  return tangent.sub(normal).normalize();
124
124
  }
125
+ /**
126
+ * Get projection of the vector to plane where n - normal to the plane.
127
+ * @static
128
+ * @param {Vec2} b - Vector to project.
129
+ * @param {Vec2} n - Plane normal.
130
+ * @param {Vec2} [def] - Default value for non existed result.
131
+ * @returns {Vec2} -
132
+ */
133
+ static proj_b_to_plane(b, n, def) {
134
+ let res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
135
+ if (def && res.isZero()) {
136
+ return new Vec2(def.x, def.y);
137
+ }
138
+ return res;
139
+ }
125
140
  /**
126
141
  * Converts to 3d vector, third value is 0.0.
127
142
  * @public
@@ -302,10 +317,19 @@ export class Vec2 {
302
317
  }
303
318
  /**
304
319
  * Returns normalized vector.
320
+ * @deprecated
305
321
  * @public
306
322
  * @returns {Vec2}
307
323
  */
308
324
  normal() {
325
+ return this.getNormal();
326
+ }
327
+ /**
328
+ * Returns normalized vector.
329
+ * @public
330
+ * @returns {Vec2}
331
+ */
332
+ getNormal() {
309
333
  let res = new Vec2();
310
334
  res.copy(this);
311
335
  let length = 1.0 / res.length();
@@ -450,6 +474,14 @@ export class Vec2 {
450
474
  }
451
475
  return Vec2.add(this.scale(scale0), v2.scale(scale1));
452
476
  }
477
+ /**
478
+ * Returns true if vector's values are zero.
479
+ * @public
480
+ * @returns {boolean} -
481
+ */
482
+ isZero() {
483
+ return !(this.x || this.y);
484
+ }
453
485
  }
454
486
  /**
455
487
  * Vector 2d object creator.