@openglobus/og 0.10.6 → 0.11.1

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 (163) hide show
  1. package/package.json +10 -7
  2. package/src/og/Extent.js +1 -1
  3. package/src/og/LonLat.js +7 -2
  4. package/src/og/Popup.js +2 -1
  5. package/src/og/camera/PlanetCamera.js +4 -2
  6. package/src/og/entity/EntityCollection.js +1 -1
  7. package/src/og/entity/LabelHandler.js +366 -74
  8. package/src/og/entity/Polyline.js +3 -2
  9. package/src/og/layer/KML.js +7 -5
  10. package/src/og/layer/Vector.js +5 -0
  11. package/src/og/layer/index.js +2 -1
  12. package/src/og/math/Vec2.js +448 -448
  13. package/src/og/math/Vec3.js +759 -757
  14. package/src/og/math/Vec4.js +216 -215
  15. package/src/og/scene/Planet.js +14 -4
  16. package/src/og/segment/SegmentLonLat.js +7 -0
  17. package/src/og/terrain/GlobusTerrain.js +4 -0
  18. package/src/og/utils/GeoImageCreator.js +123 -121
  19. package/src/og/utils/Loader.js +81 -80
  20. package/src/og/utils/NormalMapCreator.js +320 -318
  21. package/src/og/utils/VectorTileCreator.js +251 -250
  22. package/src/og/webgl/Framebuffer.js +265 -264
  23. package/src/og/webgl/Handler.js +1022 -1022
  24. package/src/og/webgl/Multisample.js +169 -168
  25. package/src/og/webgl/ProgramController.js +113 -112
  26. package/types/Clock.d.ts +90 -0
  27. package/types/Deferred.d.ts +6 -0
  28. package/types/Events.d.ts +73 -0
  29. package/types/Extent.d.ts +162 -0
  30. package/types/Globe.d.ts +80 -0
  31. package/types/ImageCanvas.d.ts +121 -0
  32. package/types/Lock.d.ts +12 -0
  33. package/types/LonLat.d.ts +108 -0
  34. package/types/Popup.d.ts +38 -0
  35. package/types/QueueArray.d.ts +15 -0
  36. package/types/Rectangle.d.ts +74 -0
  37. package/types/Stack.d.ts +15 -0
  38. package/types/ajax.d.ts +24 -0
  39. package/types/arial.d.ts +48 -0
  40. package/types/astro/astro.d.ts +38 -0
  41. package/types/astro/earth.d.ts +6 -0
  42. package/types/astro/jd.d.ts +254 -0
  43. package/types/bv/Box.d.ts +25 -0
  44. package/types/bv/Sphere.d.ts +32 -0
  45. package/types/bv/index.d.ts +3 -0
  46. package/types/camera/Camera.d.ts +303 -0
  47. package/types/camera/Frustum.d.ts +129 -0
  48. package/types/camera/PlanetCamera.d.ts +222 -0
  49. package/types/camera/index.d.ts +3 -0
  50. package/types/cons.d.ts +40 -0
  51. package/types/control/CompassButton.d.ts +17 -0
  52. package/types/control/Control.d.ts +101 -0
  53. package/types/control/DebugInfo.d.ts +16 -0
  54. package/types/control/EarthCoordinates.d.ts +47 -0
  55. package/types/control/GeoImageDragControl.d.ts +6 -0
  56. package/types/control/KeyboardNavigation.d.ts +22 -0
  57. package/types/control/LayerSwitcher.d.ts +23 -0
  58. package/types/control/Lighting.d.ts +16 -0
  59. package/types/control/ScaleControl.d.ts +22 -0
  60. package/types/control/ShowFps.d.ts +12 -0
  61. package/types/control/SimpleNavigation.d.ts +28 -0
  62. package/types/control/Sun.d.ts +52 -0
  63. package/types/control/ToggleWireframe.d.ts +12 -0
  64. package/types/control/ZoomControl.d.ts +28 -0
  65. package/types/control/index.d.ts +15 -0
  66. package/types/ellipsoid/Ellipsoid.d.ts +142 -0
  67. package/types/ellipsoid/index.d.ts +3 -0
  68. package/types/ellipsoid/wgs84.d.ts +5 -0
  69. package/types/entity/BaseBillboard.d.ts +208 -0
  70. package/types/entity/Billboard.d.ts +94 -0
  71. package/types/entity/BillboardHandler.d.ts +74 -0
  72. package/types/entity/Entity.d.ts +330 -0
  73. package/types/entity/EntityCollection.d.ts +303 -0
  74. package/types/entity/Geometry.d.ts +72 -0
  75. package/types/entity/GeometryHandler.d.ts +76 -0
  76. package/types/entity/Label.d.ts +194 -0
  77. package/types/entity/LabelHandler.d.ts +24 -0
  78. package/types/entity/PointCloud.d.ts +174 -0
  79. package/types/entity/PointCloudHandler.d.ts +38 -0
  80. package/types/entity/Polyline.d.ts +303 -0
  81. package/types/entity/PolylineHandler.d.ts +18 -0
  82. package/types/entity/Ray.d.ts +123 -0
  83. package/types/entity/RayHandler.d.ts +67 -0
  84. package/types/entity/ShapeHandler.d.ts +22 -0
  85. package/types/entity/Strip.d.ts +118 -0
  86. package/types/entity/StripHandler.d.ts +38 -0
  87. package/types/entity/index.d.ts +8 -0
  88. package/types/index.core.d.ts +65 -0
  89. package/types/index.d.ts +45 -0
  90. package/types/index.webgl.d.ts +7 -0
  91. package/types/inherits.d.ts +4 -0
  92. package/types/input/input.d.ts +34 -0
  93. package/types/layer/BaseGeoImage.d.ts +106 -0
  94. package/types/layer/CanvasTiles.d.ts +75 -0
  95. package/types/layer/GeoImage.d.ts +65 -0
  96. package/types/layer/GeoTexture2d.d.ts +8 -0
  97. package/types/layer/GeoVideo.d.ts +80 -0
  98. package/types/layer/KML.d.ts +58 -0
  99. package/types/layer/WMS.d.ts +66 -0
  100. package/types/layer/XYZ.d.ts +126 -0
  101. package/types/layer/index.d.ts +10 -0
  102. package/types/light/LightSource.d.ts +177 -0
  103. package/types/math/Mat3.d.ts +53 -0
  104. package/types/math/Mat4.d.ts +157 -0
  105. package/types/math/Plane.d.ts +17 -0
  106. package/types/math/Vec2.d.ts +308 -0
  107. package/types/math/Vec3.d.ts +459 -0
  108. package/types/math/Vec4.d.ts +161 -0
  109. package/types/math/coder.d.ts +42 -0
  110. package/types/math/index.d.ts +11 -0
  111. package/types/math.d.ts +261 -0
  112. package/types/mercator.d.ts +92 -0
  113. package/types/proj/EPSG3857.d.ts +5 -0
  114. package/types/proj/EPSG4326.d.ts +5 -0
  115. package/types/quadTree/quadTree.d.ts +40 -0
  116. package/types/renderer/RendererEvents.d.ts +230 -0
  117. package/types/res/images.d.ts +3 -0
  118. package/types/scene/Axes.d.ts +11 -0
  119. package/types/scene/BaseNode.d.ts +60 -0
  120. package/types/scene/Planet.d.ts +572 -0
  121. package/types/scene/RenderNode.d.ts +143 -0
  122. package/types/scene/SkyBox.d.ts +10 -0
  123. package/types/scene/index.d.ts +4 -0
  124. package/types/segment/segmentHelper.d.ts +13 -0
  125. package/types/shaders/billboard.d.ts +3 -0
  126. package/types/shaders/depth.d.ts +2 -0
  127. package/types/shaders/drawnode.d.ts +7 -0
  128. package/types/shaders/label.d.ts +4 -0
  129. package/types/shaders/pointCloud.d.ts +2 -0
  130. package/types/shaders/polyline.d.ts +3 -0
  131. package/types/shaders/ray.d.ts +2 -0
  132. package/types/shaders/screenFrame.d.ts +2 -0
  133. package/types/shaders/shape.d.ts +4 -0
  134. package/types/shaders/skybox.d.ts +2 -0
  135. package/types/shaders/toneMapping.d.ts +2 -0
  136. package/types/shapes/BaseShape.d.ts +247 -0
  137. package/types/shapes/Sphere.d.ts +41 -0
  138. package/types/terrain/BilTerrain.d.ts +8 -0
  139. package/types/terrain/EmptyTerrain.d.ts +72 -0
  140. package/types/terrain/Geoid.d.ts +26 -0
  141. package/types/terrain/GlobusTerrain.d.ts +153 -0
  142. package/types/terrain/MapboxTerrain.d.ts +8 -0
  143. package/types/terrain/index.d.ts +5 -0
  144. package/types/utils/FontAtlas.d.ts +14 -0
  145. package/types/utils/GeoImageCreator.d.ts +29 -0
  146. package/types/utils/ImagesCacheManager.d.ts +10 -0
  147. package/types/utils/Loader.d.ts +25 -0
  148. package/types/utils/NormalMapCreator.d.ts +39 -0
  149. package/types/utils/PlainSegmentWorker.d.ts +10 -0
  150. package/types/utils/TerrainWorker.d.ts +9 -0
  151. package/types/utils/TextureAtlas.d.ts +111 -0
  152. package/types/utils/VectorTileCreator.d.ts +16 -0
  153. package/types/utils/colorTable.d.ts +143 -0
  154. package/types/utils/earcut.d.ts +6 -0
  155. package/types/utils/shared.d.ts +230 -0
  156. package/types/webgl/Framebuffer.d.ts +135 -0
  157. package/types/webgl/Handler.d.ts +372 -0
  158. package/types/webgl/Multisample.d.ts +89 -0
  159. package/types/webgl/Program.d.ts +155 -0
  160. package/types/webgl/ProgramController.d.ts +84 -0
  161. package/types/webgl/callbacks.d.ts +1 -0
  162. package/types/webgl/index.d.ts +6 -0
  163. package/types/webgl/types.d.ts +2 -0
@@ -14,850 +14,852 @@ import { Quat } from './Quat.js';
14
14
  * @param {number} [y] - Second value.
15
15
  * @param {number} [z] - Third value.
16
16
  */
17
- const Vec3 = function (x, y, z) {
17
+ export class Vec3 {
18
+
19
+ constructor(x, y, z) {
20
+
21
+ /**
22
+ * @public
23
+ * @type {number}
24
+ */
25
+ this.x = x || 0.0;
26
+
27
+ /**
28
+ * @public
29
+ * @type {number}
30
+ */
31
+ this.y = y || 0.0;
32
+
33
+ /**
34
+ * @public
35
+ * @type {number}
36
+ */
37
+ this.z = z || 0.0;
38
+ };
39
+
40
+ /** @const */
41
+ static get UP() { return new Vec3(0, 1, 0) };
42
+ /** @const */
43
+ static get DOWN() { return new Vec3(0, -1, 0) };
44
+ /** @const */
45
+ static get RIGHT() { return new Vec3(1, 0, 0) };
46
+ /** @const */
47
+ static get LEFT() { return new Vec3(-1, 0, 0) };
48
+ /** @const */
49
+ static get FORWARD() { return new Vec3(0, 0, -1) };
50
+ /** @const */
51
+ static get BACKWARD() { return new Vec3(0, 0, 1) };
52
+ /** @const */
53
+ static get ZERO() { return new Vec3() };
54
+ /** @const */
55
+ static get UNIT_X() { return new Vec3(1, 0, 0) };
56
+ /** @const */
57
+ static get UNIT_Y() { return new Vec3(0, 1, 0) };
58
+ /** @const */
59
+ static get UNIT_Z() { return new Vec3(0, 0, 1) };
18
60
 
19
61
  /**
20
- * @public
21
- * @type {number}
62
+ * Separate 63 bit Vec3 to two Vec3 32 bit float values.
63
+ * @function
64
+ * @param {number} value - Double type value.
65
+ * @param {Vec3} high - Out vector high values.
66
+ * @param {Vec3} low - Out vector low values.
67
+ * @returns {Array.<number,number>} Encoded array.
22
68
  */
23
- this.x = x || 0.0;
69
+ static doubleToTwoFloats(v, high, low) {
24
70
 
25
- /**
26
- * @public
27
- * @type {number}
28
- */
29
- this.y = y || 0.0;
71
+ let x = v.x, y = v.y, z = v.z;
72
+
73
+ if (x >= 0.0) {
74
+ let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
75
+ high.x = Math.fround(doubleHigh);
76
+ low.x = Math.fround(x - doubleHigh);
77
+ } else {
78
+ let doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
79
+ high.x = Math.fround(-doubleHigh);
80
+ low.x = Math.fround(x + doubleHigh);
81
+ }
82
+
83
+ if (y >= 0.0) {
84
+ let doubleHigh = Math.floor(y / 65536.0) * 65536.0;
85
+ high.y = Math.fround(doubleHigh);
86
+ low.y = Math.fround(y - doubleHigh);
87
+ } else {
88
+ let doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
89
+ high.y = Math.fround(-doubleHigh);
90
+ low.y = Math.fround(y + doubleHigh);
91
+ }
92
+
93
+ if (z >= 0.0) {
94
+ let doubleHigh = Math.floor(z / 65536.0) * 65536.0;
95
+ high.z = Math.fround(doubleHigh);
96
+ low.z = Math.fround(z - doubleHigh);
97
+ } else {
98
+ let doubleHigh = Math.floor(-z / 65536.0) * 65536.0;
99
+ high.z = Math.fround(-doubleHigh);
100
+ low.z = Math.fround(z + doubleHigh);
101
+ }
102
+ };
30
103
 
31
104
  /**
32
- * @public
33
- * @type {number}
105
+ * Separate 63 bit Vec3 to two Vec3 32 bit float values.
106
+ * @function
107
+ * @param {number} value - Double type value.
108
+ * @param {Float32Array} high - Out vector high values.
109
+ * @param {Float32Array} low - Out vector low values.
110
+ * @returns {Array.<number,number>} Encoded array.
34
111
  */
35
- this.z = z || 0.0;
36
- };
112
+ static doubleToTwoFloat32Array(v, high, low) {
37
113
 
38
- /** @const */
39
- Vec3.UP = new Vec3(0, 1, 0);
40
- /** @const */
41
- Vec3.DOWN = new Vec3(0, -1, 0);
42
- /** @const */
43
- Vec3.RIGHT = new Vec3(1, 0, 0);
44
- /** @const */
45
- Vec3.LEFT = new Vec3(-1, 0, 0);
46
- /** @const */
47
- Vec3.FORWARD = new Vec3(0, 0, -1);
48
- /** @const */
49
- Vec3.BACKWARD = new Vec3(0, 0, 1);
50
- /** @const */
51
- Vec3.ZERO = new Vec3();
52
- /** @const */
53
- Vec3.UNIT_X = new Vec3(1, 0, 0);
54
- /** @const */
55
- Vec3.UNIT_Y = new Vec3(0, 1, 0);
56
- /** @const */
57
- Vec3.UNIT_Z = new Vec3(0, 0, 1);
114
+ let x = v.x, y = v.y, z = v.z;
58
115
 
59
- /**
60
- * Vector 3d object creator.
61
- * @function
62
- * @param {number} [x] - First cvalue.
63
- * @param {number} [y] - Second value.
64
- * @param {number} [z] - Third value.
65
- * @returns {og.Vec3} -
66
- */
67
- export function vec3(x, y, z) {
68
- return new Vec3(x, y, z);
69
- };
116
+ if (x >= 0.0) {
117
+ let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
118
+ high[0] = Math.fround(doubleHigh);
119
+ low[0] = Math.fround(x - doubleHigh);
120
+ } else {
121
+ let doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
122
+ high[0] = Math.fround(-doubleHigh);
123
+ low[0] = Math.fround(x + doubleHigh);
124
+ }
70
125
 
71
- /**
72
- * Separate 63 bit Vec3 to two Vec3 32 bit float values.
73
- * @function
74
- * @param {number} value - Double type value.
75
- * @param {Vec3} high - Out vector high values.
76
- * @param {Vec3} low - Out vector low values.
77
- * @returns {Array.<number,number>} Encoded array.
78
- */
79
- Vec3.doubleToTwoFloats = function (v, high, low) {
80
-
81
- let x = v.x, y = v.y, z = v.z;
82
-
83
- if (x >= 0.0) {
84
- let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
85
- high.x = Math.fround(doubleHigh);
86
- low.x = Math.fround(x - doubleHigh);
87
- } else {
88
- let doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
89
- high.x = Math.fround(-doubleHigh);
90
- low.x = Math.fround(x + doubleHigh);
91
- }
92
-
93
- if (y >= 0.0) {
94
- let doubleHigh = Math.floor(y / 65536.0) * 65536.0;
95
- high.y = Math.fround(doubleHigh);
96
- low.y = Math.fround(y - doubleHigh);
97
- } else {
98
- let doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
99
- high.y = Math.fround(-doubleHigh);
100
- low.y = Math.fround(y + doubleHigh);
101
- }
102
-
103
- if (z >= 0.0) {
104
- let doubleHigh = Math.floor(z / 65536.0) * 65536.0;
105
- high.z = Math.fround(doubleHigh);
106
- low.z = Math.fround(z - doubleHigh);
107
- } else {
108
- let doubleHigh = Math.floor(-z / 65536.0) * 65536.0;
109
- high.z = Math.fround(-doubleHigh);
110
- low.z = Math.fround(z + doubleHigh);
111
- }
112
- };
126
+ if (y >= 0.0) {
127
+ let doubleHigh = Math.floor(y / 65536.0) * 65536.0;
128
+ high[1] = Math.fround(doubleHigh);
129
+ low[1] = Math.fround(y - doubleHigh);
130
+ } else {
131
+ let doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
132
+ high[1] = Math.fround(-doubleHigh);
133
+ low[1] = Math.fround(y + doubleHigh);
134
+ }
113
135
 
114
- /**
115
- * Separate 63 bit Vec3 to two Vec3 32 bit float values.
116
- * @function
117
- * @param {number} value - Double type value.
118
- * @param {Float32Array} high - Out vector high values.
119
- * @param {Float32Array} low - Out vector low values.
120
- * @returns {Array.<number,number>} Encoded array.
121
- */
122
- Vec3.doubleToTwoFloat32Array = function (v, high, low) {
123
-
124
- let x = v.x, y = v.y, z = v.z;
125
-
126
- if (x >= 0.0) {
127
- let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
128
- high[0] = Math.fround(doubleHigh);
129
- low[0] = Math.fround(x - doubleHigh);
130
- } else {
131
- let doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
132
- high[0] = Math.fround(-doubleHigh);
133
- low[0] = Math.fround(x + doubleHigh);
134
- }
135
-
136
- if (y >= 0.0) {
137
- let doubleHigh = Math.floor(y / 65536.0) * 65536.0;
138
- high[1] = Math.fround(doubleHigh);
139
- low[1] = Math.fround(y - doubleHigh);
140
- } else {
141
- let doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
142
- high[1] = Math.fround(-doubleHigh);
143
- low[1] = Math.fround(y + doubleHigh);
144
- }
145
-
146
- if (z >= 0.0) {
147
- let doubleHigh = Math.floor(z / 65536.0) * 65536.0;
148
- high[2] = Math.fround(doubleHigh);
149
- low[2] = Math.fround(z - doubleHigh);
150
- } else {
151
- let doubleHigh = Math.floor(-z / 65536.0) * 65536.0;
152
- high[2] = Math.fround(-doubleHigh);
153
- low[2] = Math.fround(z + doubleHigh);
154
- }
155
- };
136
+ if (z >= 0.0) {
137
+ let doubleHigh = Math.floor(z / 65536.0) * 65536.0;
138
+ high[2] = Math.fround(doubleHigh);
139
+ low[2] = Math.fround(z - doubleHigh);
140
+ } else {
141
+ let doubleHigh = Math.floor(-z / 65536.0) * 65536.0;
142
+ high[2] = Math.fround(-doubleHigh);
143
+ low[2] = Math.fround(z + doubleHigh);
144
+ }
145
+ };
156
146
 
157
- /**
158
- * Creates 3d vector from array.
159
- * @function
160
- * @param {Array.<number,number,number>} arr - Input array
161
- * @returns {og.Vec3} -
162
- */
163
- Vec3.fromVec = function (arr) {
164
- return new Vec3(arr[0], arr[1], arr[2]);
165
- };
147
+ /**
148
+ * Creates 3d vector from array.
149
+ * @function
150
+ * @param {Array.<number,number,number>} arr - Input array
151
+ * @returns {og.Vec3} -
152
+ */
153
+ static fromVec(arr) {
154
+ return new Vec3(arr[0], arr[1], arr[2]);
155
+ };
166
156
 
167
- /**
168
- * Gets angle between two vectors.
169
- * @static
170
- * @param {og.Vec3} a - First vector.
171
- * @param {og.Vec3} b - Second vector.
172
- * @returns {number} -
173
- */
174
- Vec3.angle = function (a, b) {
175
- return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
176
- };
157
+ /**
158
+ * Gets angle between two vectors.
159
+ * @static
160
+ * @param {og.Vec3} a - First vector.
161
+ * @param {og.Vec3} b - Second vector.
162
+ * @returns {number} -
163
+ */
164
+ static angle(a, b) {
165
+ return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
166
+ };
177
167
 
178
- /**
179
- * Returns two vectors linear interpolation.
180
- * @static
181
- * @param {og.Vec3} v1 - Start vector.
182
- * @param {og.Vec3} v2 - End vector.
183
- * @param {number} l - Interpolate value.
184
- * @returns {og.Vec3} -
185
- */
186
- Vec3.lerp = function (v1, v2, l) {
187
- return Vec3(v1.x + (v2.x - v1.x) * l, v1.y + (v2.y - v1.y) * l, v1.z + (v2.z - v1.z) * l);
188
- };
168
+ /**
169
+ * Returns two vectors linear interpolation.
170
+ * @static
171
+ * @param {og.Vec3} v1 - Start vector.
172
+ * @param {og.Vec3} v2 - End vector.
173
+ * @param {number} l - Interpolate value.
174
+ * @returns {og.Vec3} -
175
+ */
176
+ static lerp(v1, v2, l) {
177
+ return Vec3(v1.x + (v2.x - v1.x) * l, v1.y + (v2.y - v1.y) * l, v1.z + (v2.z - v1.z) * l);
178
+ };
189
179
 
190
- /**
191
- * Returns summary vector.
192
- * @static
193
- * @param {og.Vec3} a - First vector.
194
- * @param {og.Vec3} b - Second vector.
195
- * @returns {og.Vec3} - Summary vector.
196
- */
197
- Vec3.add = function (a, b) {
198
- var res = new Vec3(a.x, a.y, a.z);
199
- res.addA(b);
200
- return res;
201
- };
180
+ /**
181
+ * Returns summary vector.
182
+ * @static
183
+ * @param {og.Vec3} a - First vector.
184
+ * @param {og.Vec3} b - Second vector.
185
+ * @returns {og.Vec3} - Summary vector.
186
+ */
187
+ static add(a, b) {
188
+ var res = new Vec3(a.x, a.y, a.z);
189
+ res.addA(b);
190
+ return res;
191
+ };
202
192
 
203
- /**
204
- * Returns two vectors subtraction.
205
- * @static
206
- * @param {og.Vec3} a - First vector.
207
- * @param {og.Vec3} b - Second vector.
208
- * @returns {og.Vec3} - Vectors subtraction.
209
- */
210
- Vec3.sub = function (a, b) {
211
- var res = new Vec3(a.x, a.y, a.z);
212
- res.subA(b);
213
- return res;
214
- };
193
+ /**
194
+ * Returns two vectors subtraction.
195
+ * @static
196
+ * @param {og.Vec3} a - First vector.
197
+ * @param {og.Vec3} b - Second vector.
198
+ * @returns {og.Vec3} - Vectors subtraction.
199
+ */
200
+ static sub(a, b) {
201
+ var res = new Vec3(a.x, a.y, a.z);
202
+ res.subA(b);
203
+ return res;
204
+ };
215
205
 
216
- /**
217
- * Returns scaled vector.
218
- * @static
219
- * @param {og.Vec3} a - Input vector.
220
- * @param {number} scale - Scale value.
221
- * @returns {og.Vec3} -
222
- */
223
- Vec3.scale = function (a, scale) {
224
- var res = new Vec3(a.x, a.y, a.z);
225
- res.scale(scale);
226
- return res;
227
- };
206
+ /**
207
+ * Returns scaled vector.
208
+ * @static
209
+ * @param {og.Vec3} a - Input vector.
210
+ * @param {number} scale - Scale value.
211
+ * @returns {og.Vec3} -
212
+ */
213
+ static scale(a, scale) {
214
+ var res = new Vec3(a.x, a.y, a.z);
215
+ res.scale(scale);
216
+ return res;
217
+ };
228
218
 
229
- /**
230
- * Returns two vectors production.
231
- * @static
232
- * @param {og.Vec3} a - First vector.
233
- * @param {og.Vec3} b - Second vector.
234
- * @returns {og.Vec3} -
235
- */
236
- Vec3.mul = function (a, b) {
237
- var res = new Vec3(a.x, a.y, a.z);
238
- res.mulA(b);
239
- return res;
240
- };
219
+ /**
220
+ * Returns two vectors production.
221
+ * @static
222
+ * @param {og.Vec3} a - First vector.
223
+ * @param {og.Vec3} b - Second vector.
224
+ * @returns {og.Vec3} -
225
+ */
226
+ static mul(a, b) {
227
+ var res = new Vec3(a.x, a.y, a.z);
228
+ res.mulA(b);
229
+ return res;
230
+ };
241
231
 
242
- /**
243
- * Returns true if two vectors are non collinear.
244
- * @public
245
- * @param {og.Vec3} a - First vector.
246
- * @param {og.Vec3} b - Second vector.
247
- * @returns {og.Vec3} -
248
- */
249
- Vec3.noncollinear = function (a, b) {
250
- return a.y * b.z - a.z * b.y || a.z * b.x - a.x * b.z || a.x * b.y - a.y * b.z;
251
- };
232
+ /**
233
+ * Returns true if two vectors are non collinear.
234
+ * @public
235
+ * @param {og.Vec3} a - First vector.
236
+ * @param {og.Vec3} b - Second vector.
237
+ * @returns {og.Vec3} -
238
+ */
239
+ static noncollinear(a, b) {
240
+ return a.y * b.z - a.z * b.y || a.z * b.x - a.x * b.z || a.x * b.y - a.y * b.z;
241
+ };
252
242
 
253
- /**
254
- * Get projection of the vector to plane where n - normal to the plane.
255
- * @static
256
- * @param {og.Vec3} b - Vector to project.
257
- * @param {og.Vec3} n - Plane normal.
258
- * @param {og.Vec3} [def] - Default value for non existed result.
259
- * @returns {og.Vec3} -
260
- */
261
- Vec3.proj_b_to_plane = function (b, n, def) {
262
- var res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
263
- if (def && res.isZero()) {
264
- return new Vec3(def.x, def.y, def.z);
265
- }
266
- return res;
267
- };
243
+ /**
244
+ * Get projection of the vector to plane where n - normal to the plane.
245
+ * @static
246
+ * @param {og.Vec3} b - Vector to project.
247
+ * @param {og.Vec3} n - Plane normal.
248
+ * @param {og.Vec3} [def] - Default value for non existed result.
249
+ * @returns {og.Vec3} -
250
+ */
251
+ static proj_b_to_plane(b, n, def) {
252
+ var res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
253
+ if (def && res.isZero()) {
254
+ return new Vec3(def.x, def.y, def.z);
255
+ }
256
+ return res;
257
+ };
268
258
 
269
- /**
270
- * Get projection of the first vector to the second.
271
- * @static
272
- * @param {og.Vec3} b - First vector.
273
- * @param {og.Vec3} a - Second vector.
274
- * @returns {og.Vec3} -
275
- */
276
- Vec3.proj_b_to_a = function (b, a) {
277
- return a.scaleTo(a.dot(b) / a.dot(a));
278
- };
259
+ /**
260
+ * Get projection of the first vector to the second.
261
+ * @static
262
+ * @param {og.Vec3} b - First vector.
263
+ * @param {og.Vec3} a - Second vector.
264
+ * @returns {og.Vec3} -
265
+ */
266
+ static proj_b_to_a(b, a) {
267
+ return a.scaleTo(a.dot(b) / a.dot(a));
268
+ };
279
269
 
280
- /**
281
- * Makes vectors normalized and orthogonal to each other.
282
- * Normalizes normal. Normalizes tangent and makes sure it is orthogonal to normal (that is, angle between them is 90 degrees).
283
- * @static
284
- * @param {og.Vec3} normal - Normal vector.
285
- * @param {og.Vec3} tangent - Tangent vector.
286
- * @returns {og.Vec3} -
287
- */
288
- Vec3.orthoNormalize = function (normal, tangent) {
289
- normal = normal.normal();
290
- normal.scale(tangent.dot(normal));
291
- return tangent.subA(normal).normalize();
292
- };
270
+ /**
271
+ * Makes vectors normalized and orthogonal to each other.
272
+ * Normalizes normal. Normalizes tangent and makes sure it is orthogonal to normal (that is, angle between them is 90 degrees).
273
+ * @static
274
+ * @param {og.Vec3} normal - Normal vector.
275
+ * @param {og.Vec3} tangent - Tangent vector.
276
+ * @returns {og.Vec3} -
277
+ */
278
+ static orthoNormalize(normal, tangent) {
279
+ normal = normal.normal();
280
+ normal.scale(tangent.dot(normal));
281
+ return tangent.subA(normal).normalize();
282
+ };
293
283
 
294
- /**
295
- * Returns vector components division product one to another.
296
- * @static
297
- * @param {og.Vec3} a - First vector.
298
- * @param {og.Vec3} b - Second vector.
299
- * @returns {og.Vec3} -
300
- */
301
- Vec3.div = function (a, b) {
302
- var res = new Vec3(a.x, a.y, a.z);
303
- res.divA(b);
304
- return res;
305
- };
284
+ /**
285
+ * Returns vector components division product one to another.
286
+ * @static
287
+ * @param {og.Vec3} a - First vector.
288
+ * @param {og.Vec3} b - Second vector.
289
+ * @returns {og.Vec3} -
290
+ */
291
+ static div(a, b) {
292
+ var res = new Vec3(a.x, a.y, a.z);
293
+ res.divA(b);
294
+ return res;
295
+ };
306
296
 
307
- /**
308
- * Converts to 4d vector, Fourth value is 1.0.
309
- * @public
310
- * @returns {og.Vec4} -
311
- */
312
- Vec3.prototype.toVec4 = function () {
313
- return new Vec4(this.x, this.y, this.z, 1.0);
314
- };
297
+ /**
298
+ * Converts to 4d vector, Fourth value is 1.0.
299
+ * @public
300
+ * @returns {og.Vec4} -
301
+ */
302
+ toVec4() {
303
+ return new Vec4(this.x, this.y, this.z, 1.0);
304
+ };
315
305
 
316
- /**
317
- * Returns clone vector.
318
- * @public
319
- * @returns {og.Vec3} -
320
- */
321
- Vec3.prototype.clone = function () {
322
- return new Vec3(this.x, this.y, this.z);
323
- };
306
+ /**
307
+ * Returns clone vector.
308
+ * @public
309
+ * @returns {og.Vec3} -
310
+ */
311
+ clone() {
312
+ return new Vec3(this.x, this.y, this.z);
313
+ };
324
314
 
325
- /**
326
- * Converts vector to text string.
327
- * @public
328
- * @returns {string} -
329
- */
330
- Vec3.prototype.toString = function () {
331
- return "(" + this.x + "," + this.y + "," + this.z + ")";
332
- };
315
+ /**
316
+ * Converts vector to text string.
317
+ * @public
318
+ * @returns {string} -
319
+ */
320
+ toString() {
321
+ return "(" + this.x + "," + this.y + "," + this.z + ")";
322
+ };
333
323
 
334
- /**
335
- * Returns true if vector's values are zero.
336
- * @public
337
- * @returns {boolean} -
338
- */
339
- Vec3.prototype.isZero = function () {
340
- return !(this.x || this.y || this.z);
341
- };
324
+ /**
325
+ * Returns true if vector's values are zero.
326
+ * @public
327
+ * @returns {boolean} -
328
+ */
329
+ isZero() {
330
+ return !(this.x || this.y || this.z);
331
+ };
342
332
 
343
- /**
344
- * Get projection of the first vector to the second.
345
- * @static
346
- * @param {og.Vec3} a - Project vector.
347
- * @returns {og.Vec3} -
348
- */
349
- Vec3.prototype.projToVec = function (a) {
350
- return a.scaleTo(a.dot(this) / a.dot(a));
351
- };
333
+ /**
334
+ * Get projection of the first vector to the second.
335
+ * @static
336
+ * @param {og.Vec3} a - Project vector.
337
+ * @returns {og.Vec3} -
338
+ */
339
+ projToVec(a) {
340
+ return a.scaleTo(a.dot(this) / a.dot(a));
341
+ };
352
342
 
353
- /**
354
- * Compares with vector. Returns true if it equals another.
355
- * @public
356
- * @param {og.Vec3} p - Vector to compare.
357
- * @returns {boolean} -
358
- */
359
- Vec3.prototype.equal = function (p) {
360
- return this.x === p.x && this.y === p.y && this.z === p.z;
361
- };
343
+ /**
344
+ * Compares with vector. Returns true if it equals another.
345
+ * @public
346
+ * @param {og.Vec3} p - Vector to compare.
347
+ * @returns {boolean} -
348
+ */
349
+ equal(p) {
350
+ return this.x === p.x && this.y === p.y && this.z === p.z;
351
+ };
362
352
 
363
- /**
364
- * Copy input vector's values.
365
- * @param {og.Vec3} point3 - Vector to copy.
366
- * @returns {og.Vec3} -
367
- */
368
- Vec3.prototype.copy = function (point3) {
369
- this.x = point3.x;
370
- this.y = point3.y;
371
- this.z = point3.z;
372
- return this;
373
- };
353
+ /**
354
+ * Copy input vector's values.
355
+ * @param {og.Vec3} point3 - Vector to copy.
356
+ * @returns {og.Vec3} -
357
+ */
358
+ copy(point3) {
359
+ this.x = point3.x;
360
+ this.y = point3.y;
361
+ this.z = point3.z;
362
+ return this;
363
+ };
374
364
 
375
- /**
376
- * Gets vector's length.
377
- * @public
378
- * @returns {number} -
379
- */
380
- Vec3.prototype.length = function () {
381
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
382
- };
365
+ /**
366
+ * Gets vector's length.
367
+ * @public
368
+ * @returns {number} -
369
+ */
370
+ length() {
371
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
372
+ };
383
373
 
384
- /**
385
- * Returns squared vector's length.
386
- * @public
387
- * @returns {number} -
388
- */
389
- Vec3.prototype.length2 = function () {
390
- return this.x * this.x + this.y * this.y + this.z * this.z;
391
- };
374
+ /**
375
+ * Returns squared vector's length.
376
+ * @public
377
+ * @returns {number} -
378
+ */
379
+ length2() {
380
+ return this.x * this.x + this.y * this.y + this.z * this.z;
381
+ };
392
382
 
393
- /**
394
- * Converts vector's values to a quaternion object.
395
- * @public
396
- * @returns {og.Quat} -
397
- */
398
- Vec3.prototype.getQuat = function () {
399
- return new Quat(this.x, this.y, this.z);
400
- };
383
+ /**
384
+ * Converts vector's values to a quaternion object.
385
+ * @public
386
+ * @returns {og.Quat} -
387
+ */
388
+ getQuat() {
389
+ return new Quat(this.x, this.y, this.z);
390
+ };
401
391
 
402
- /**
403
- * Adds vector to the current.
404
- * @public
405
- * @param {og.Vec3} point3 - Point to add.
406
- * @returns {og.Vec3} -
407
- */
408
- Vec3.prototype.addA = function (point3) {
409
- this.x += point3.x;
410
- this.y += point3.y;
411
- this.z += point3.z;
412
- return this;
413
- };
392
+ /**
393
+ * Adds vector to the current.
394
+ * @public
395
+ * @param {og.Vec3} point3 - Point to add.
396
+ * @returns {og.Vec3} -
397
+ */
398
+ addA(point3) {
399
+ this.x += point3.x;
400
+ this.y += point3.y;
401
+ this.z += point3.z;
402
+ return this;
403
+ };
414
404
 
415
- /**
416
- * Gets two vectors summarization.
417
- * @public
418
- * @param {og.Vec3} point3 - Vector to add.
419
- * @returns {og.Vec3} Returns a sum vector.
420
- */
421
- Vec3.prototype.add = function (point3) {
422
- return new Vec3(this.x + point3.x, this.y + point3.y, this.z + point3.z);
423
- };
405
+ /**
406
+ * Gets two vectors summarization.
407
+ * @public
408
+ * @param {og.Vec3} point3 - Vector to add.
409
+ * @returns {og.Vec3} Returns a sum vector.
410
+ */
411
+ add(point3) {
412
+ return new Vec3(this.x + point3.x, this.y + point3.y, this.z + point3.z);
413
+ };
424
414
 
425
- /**
426
- * Subtract vector from the current.
427
- * @public
428
- * @param {og.Vec3} point3 - Subtract vector.
429
- * @returns {og.Vec3} -
430
- */
431
- Vec3.prototype.subA = function (point3) {
432
- this.x -= point3.x;
433
- this.y -= point3.y;
434
- this.z -= point3.z;
435
- return this;
436
- };
415
+ /**
416
+ * Subtract vector from the current.
417
+ * @public
418
+ * @param {og.Vec3} point3 - Subtract vector.
419
+ * @returns {og.Vec3} -
420
+ */
421
+ subA(point3) {
422
+ this.x -= point3.x;
423
+ this.y -= point3.y;
424
+ this.z -= point3.z;
425
+ return this;
426
+ };
437
427
 
438
- /**
439
- * Gets vector subtraction.
440
- * @public
441
- * @param {og.Vec3} point3 - Subtract vector.
442
- * @return {og.Vec3} Returns new instance of a subtraction
443
- */
444
- Vec3.prototype.sub = function (point3) {
445
- return new Vec3(this.x - point3.x, this.y - point3.y, this.z - point3.z);
446
- };
428
+ /**
429
+ * Gets vector subtraction.
430
+ * @public
431
+ * @param {og.Vec3} point3 - Subtract vector.
432
+ * @return {og.Vec3} Returns new instance of a subtraction
433
+ */
434
+ sub(point3) {
435
+ return new Vec3(this.x - point3.x, this.y - point3.y, this.z - point3.z);
436
+ };
447
437
 
448
- /**
449
- * Scale current vector.
450
- * @public
451
- * @param {number} scale - Scale value.
452
- * @returns {og.Vec3} -
453
- */
454
- Vec3.prototype.scale = function (scale) {
455
- this.x *= scale;
456
- this.y *= scale;
457
- this.z *= scale;
458
- return this;
459
- };
438
+ /**
439
+ * Scale current vector.
440
+ * @public
441
+ * @param {number} scale - Scale value.
442
+ * @returns {og.Vec3} -
443
+ */
444
+ scale(scale) {
445
+ this.x *= scale;
446
+ this.y *= scale;
447
+ this.z *= scale;
448
+ return this;
449
+ };
460
450
 
461
- /**
462
- * Scale current vector to another instance.
463
- * @public
464
- * @param {number} scale - Scale value.
465
- * @returns {og.Vec3} -
466
- */
467
- Vec3.prototype.scaleTo = function (scale) {
468
- return new Vec3(this.x * scale, this.y * scale, this.z * scale);
469
- };
451
+ /**
452
+ * Scale current vector to another instance.
453
+ * @public
454
+ * @param {number} scale - Scale value.
455
+ * @returns {og.Vec3} -
456
+ */
457
+ scaleTo(scale) {
458
+ return new Vec3(this.x * scale, this.y * scale, this.z * scale);
459
+ };
470
460
 
471
- /**
472
- * Multiply current vector object to another and store result in the current instance.
473
- * @public
474
- * @param {og.Vec3} vec - Multiply vector.
475
- * @returns {og.Vec3} -
476
- */
477
- Vec3.prototype.mulA = function (vec) {
478
- this.x *= vec.x;
479
- this.y *= vec.y;
480
- this.z *= vec.z;
481
- return this;
482
- };
461
+ /**
462
+ * Multiply current vector object to another and store result in the current instance.
463
+ * @public
464
+ * @param {og.Vec3} vec - Multiply vector.
465
+ * @returns {og.Vec3} -
466
+ */
467
+ mulA(vec) {
468
+ this.x *= vec.x;
469
+ this.y *= vec.y;
470
+ this.z *= vec.z;
471
+ return this;
472
+ };
483
473
 
484
- /**
485
- * Multiply current vector object to another and returns new vector instance.
486
- * @public
487
- * @param {og.Vec3} vec - Multiply vector.
488
- * @returns {og.Vec3} -
489
- */
490
- Vec3.prototype.mul = function (vec) {
491
- return new Vec3(this.x * vec.x, this.y * vec.y, this.z * vec.z);
492
- };
474
+ /**
475
+ * Multiply current vector object to another and returns new vector instance.
476
+ * @public
477
+ * @param {og.Vec3} vec - Multiply vector.
478
+ * @returns {og.Vec3} -
479
+ */
480
+ mul(vec) {
481
+ return new Vec3(this.x * vec.x, this.y * vec.y, this.z * vec.z);
482
+ };
493
483
 
494
- /**
495
- * Divide current vector's components to another. Results stores in the current vector object.
496
- * @public
497
- * @param {og.Vec3} vec - Div vector.
498
- * @returns {og.Vec3} -
499
- */
500
- Vec3.prototype.divA = function (vec) {
501
- this.x /= vec.x;
502
- this.y /= vec.y;
503
- this.z /= vec.z;
504
- return this;
505
- };
484
+ /**
485
+ * Divide current vector's components to another. Results stores in the current vector object.
486
+ * @public
487
+ * @param {og.Vec3} vec - Div vector.
488
+ * @returns {og.Vec3} -
489
+ */
490
+ divA(vec) {
491
+ this.x /= vec.x;
492
+ this.y /= vec.y;
493
+ this.z /= vec.z;
494
+ return this;
495
+ };
506
496
 
507
- /**
508
- * Divide current vector's components to another and returns new vector instance.
509
- * @public
510
- * @param {og.Vec3} vec - Div vector.
511
- * @returns {og.Vec3} -
512
- */
513
- Vec3.prototype.div = function (vec) {
514
- return new Vec3(this.x / vec.x, this.y / vec.y, this.z / vec.z);
515
- };
497
+ /**
498
+ * Divide current vector's components to another and returns new vector instance.
499
+ * @public
500
+ * @param {og.Vec3} vec - Div vector.
501
+ * @returns {og.Vec3} -
502
+ */
503
+ div(vec) {
504
+ return new Vec3(this.x / vec.x, this.y / vec.y, this.z / vec.z);
505
+ };
516
506
 
517
- /**
518
- * Gets vectors dot production.
519
- * @public
520
- * @param {og.Vec3} point3 - Another vector.
521
- * @returns {number} -
522
- */
523
- Vec3.prototype.dot = function (point3) {
524
- return point3.x * this.x + point3.y * this.y + point3.z * this.z;
525
- };
507
+ /**
508
+ * Gets vectors dot production.
509
+ * @public
510
+ * @param {og.Vec3} point3 - Another vector.
511
+ * @returns {number} -
512
+ */
513
+ dot(point3) {
514
+ return point3.x * this.x + point3.y * this.y + point3.z * this.z;
515
+ };
526
516
 
527
- /**
528
- * Gets vectors dot production.
529
- * @public
530
- * @param {Array.<number,number,number>} arr - Array vector.
531
- * @returns {number} -
532
- */
533
- Vec3.prototype.dotArr = function (arr) {
534
- return arr[0] * this.x + arr[1] * this.y + arr[2] * this.z;
535
- };
517
+ /**
518
+ * Gets vectors dot production.
519
+ * @public
520
+ * @param {Array.<number,number,number>} arr - Array vector.
521
+ * @returns {number} -
522
+ */
523
+ dotArr(arr) {
524
+ return arr[0] * this.x + arr[1] * this.y + arr[2] * this.z;
525
+ };
536
526
 
537
- /**
538
- * Gets vectors cross production.
539
- * @public
540
- * @param {og.Vec3} point3 - Another vector.
541
- * @returns {og.Vec3} -
542
- */
543
- Vec3.prototype.cross = function (point3) {
544
- return new Vec3(
545
- this.y * point3.z - this.z * point3.y,
546
- this.z * point3.x - this.x * point3.z,
547
- this.x * point3.y - this.y * point3.x
548
- );
549
- };
527
+ /**
528
+ * Gets vectors cross production.
529
+ * @public
530
+ * @param {og.Vec3} point3 - Another vector.
531
+ * @returns {og.Vec3} -
532
+ */
533
+ cross(point3) {
534
+ return new Vec3(
535
+ this.y * point3.z - this.z * point3.y,
536
+ this.z * point3.x - this.x * point3.z,
537
+ this.x * point3.y - this.y * point3.x
538
+ );
539
+ };
550
540
 
551
- /**
552
- * Sets vector to zero.
553
- * @public
554
- * @returns {og.Vec3} -
555
- */
556
- Vec3.prototype.clear = function () {
557
- this.x = this.y = this.z = 0;
558
- return this;
559
- };
541
+ /**
542
+ * Sets vector to zero.
543
+ * @public
544
+ * @returns {og.Vec3} -
545
+ */
546
+ clear() {
547
+ this.x = this.y = this.z = 0;
548
+ return this;
549
+ };
560
550
 
561
- /**
562
- * Returns normalized vector.
563
- * @public
564
- * @returns {og.Vec3} -
565
- */
566
- Vec3.prototype.getNormal = function () {
567
- var res = new Vec3();
568
- res.copy(this);
551
+ /**
552
+ * Returns normalized vector.
553
+ * @public
554
+ * @returns {og.Vec3} -
555
+ */
556
+ getNormal() {
557
+ var res = new Vec3();
558
+ res.copy(this);
569
559
 
570
- var length = 1.0 / res.length();
560
+ var length = 1.0 / res.length();
571
561
 
572
- res.x *= length;
573
- res.y *= length;
574
- res.z *= length;
562
+ res.x *= length;
563
+ res.y *= length;
564
+ res.z *= length;
575
565
 
576
- return res;
577
- };
566
+ return res;
567
+ };
578
568
 
579
- /**
580
- * Returns normalized vector.
581
- * @deprecated
582
- * @public
583
- * @returns {og.Vec3} -
584
- */
585
- Vec3.prototype.normal = function () {
586
- var res = new Vec3();
587
- res.copy(this);
569
+ /**
570
+ * Returns normalized vector.
571
+ * @deprecated
572
+ * @public
573
+ * @returns {og.Vec3} -
574
+ */
575
+ normal() {
576
+ var res = new Vec3();
577
+ res.copy(this);
588
578
 
589
- var length = 1.0 / res.length();
579
+ var length = 1.0 / res.length();
590
580
 
591
- res.x *= length;
592
- res.y *= length;
593
- res.z *= length;
581
+ res.x *= length;
582
+ res.y *= length;
583
+ res.z *= length;
594
584
 
595
- return res;
596
- };
585
+ return res;
586
+ };
597
587
 
598
- /**
599
- * Returns normalized negate vector.
600
- * @public
601
- * @returns {og.Vec3} -
602
- */
603
- Vec3.prototype.normalNegate = function () {
604
- var res = new Vec3();
605
- res.copy(this);
588
+ /**
589
+ * Returns normalized negate vector.
590
+ * @public
591
+ * @returns {og.Vec3} -
592
+ */
593
+ normalNegate() {
594
+ var res = new Vec3();
595
+ res.copy(this);
606
596
 
607
- var length = -1.0 / res.length();
597
+ var length = -1.0 / res.length();
608
598
 
609
- res.x *= length;
610
- res.y *= length;
611
- res.z *= length;
599
+ res.x *= length;
600
+ res.y *= length;
601
+ res.z *= length;
612
602
 
613
- return res;
614
- };
603
+ return res;
604
+ };
615
605
 
616
- /**
617
- * Returns normalized negate scale vector.
618
- * @public
619
- * @returns {og.Vec3} -
620
- */
621
- Vec3.prototype.normalNegateScale = function (scale) {
622
- var res = new Vec3();
623
- res.copy(this);
606
+ /**
607
+ * Returns normalized negate scale vector.
608
+ * @public
609
+ * @returns {og.Vec3} -
610
+ */
611
+ normalNegateScale(scale) {
612
+ var res = new Vec3();
613
+ res.copy(this);
624
614
 
625
- var length = -scale / res.length();
615
+ var length = -scale / res.length();
626
616
 
627
- res.x *= length;
628
- res.y *= length;
629
- res.z *= length;
617
+ res.x *= length;
618
+ res.y *= length;
619
+ res.z *= length;
630
620
 
631
- return res;
632
- };
621
+ return res;
622
+ };
633
623
 
634
- /**
635
- * Returns normalized scale vector.
636
- * @public
637
- * @returns {og.Vec3} -
638
- */
639
- Vec3.prototype.normalScale = function (scale) {
640
- var res = new Vec3();
641
- res.copy(this);
624
+ /**
625
+ * Returns normalized scale vector.
626
+ * @public
627
+ * @returns {og.Vec3} -
628
+ */
629
+ normalScale(scale) {
630
+ var res = new Vec3();
631
+ res.copy(this);
642
632
 
643
- var length = scale / res.length();
633
+ var length = scale / res.length();
644
634
 
645
- res.x *= length;
646
- res.y *= length;
647
- res.z *= length;
635
+ res.x *= length;
636
+ res.y *= length;
637
+ res.z *= length;
648
638
 
649
- return res;
650
- };
639
+ return res;
640
+ };
651
641
 
652
- /**
653
- * Normalize current vector.
654
- * @public
655
- * @returns {og.Vec3} -
656
- */
657
- Vec3.prototype.normalize = function () {
658
- var length = 1.0 / this.length();
642
+ /**
643
+ * Normalize current vector.
644
+ * @public
645
+ * @returns {og.Vec3} -
646
+ */
647
+ normalize() {
648
+ var length = 1.0 / this.length();
659
649
 
660
- this.x *= length;
661
- this.y *= length;
662
- this.z *= length;
650
+ this.x *= length;
651
+ this.y *= length;
652
+ this.z *= length;
663
653
 
664
- return this;
665
- };
654
+ return this;
655
+ };
666
656
 
667
- /**
668
- * Converts vector to a number array.
669
- * @public
670
- * @returns {Array.<number,number,number>} -
671
- * @deprecated
672
- */
673
- Vec3.prototype.toVec = function () {
674
- return [this.x, this.y, this.z];
675
- };
657
+ /**
658
+ * Converts vector to a number array.
659
+ * @public
660
+ * @returns {Array.<number,number,number>} -
661
+ * @deprecated
662
+ */
663
+ toVec() {
664
+ return [this.x, this.y, this.z];
665
+ };
676
666
 
677
- /**
678
- * Converts vector to a number array.
679
- * @public
680
- * @returns {Array.<number,number,number>} -
681
- */
682
- Vec3.prototype.toArray = function () {
683
- return [this.x, this.y, this.z];
684
- };
667
+ /**
668
+ * Converts vector to a number array.
669
+ * @public
670
+ * @returns {Array.<number,number,number>} -
671
+ */
672
+ toArray() {
673
+ return [this.x, this.y, this.z];
674
+ };
685
675
 
686
- /**
687
- * Gets distance to point.
688
- * @public
689
- * @param {og.Vec3} point3 - Distant point.
690
- * @returns {number} -
691
- */
692
- Vec3.prototype.distance = function (point3) {
693
- return Vec3.sub(this, point3).length();
694
- };
676
+ /**
677
+ * Gets distance to point.
678
+ * @public
679
+ * @param {og.Vec3} point3 - Distant point.
680
+ * @returns {number} -
681
+ */
682
+ distance(point3) {
683
+ return Vec3.sub(this, point3).length();
684
+ };
695
685
 
696
- /**
697
- * Sets vector's values.
698
- * @public
699
- * @param {number} x - Value X.
700
- * @param {number} y - Value Y.
701
- * @param {number} z - Value Z.
702
- * @returns {og.Vec3} -
703
- */
704
- Vec3.prototype.set = function (x, y, z) {
705
- this.x = x;
706
- this.y = y;
707
- this.z = z;
708
- return this;
709
- };
686
+ /**
687
+ * Sets vector's values.
688
+ * @public
689
+ * @param {number} x - Value X.
690
+ * @param {number} y - Value Y.
691
+ * @param {number} z - Value Z.
692
+ * @returns {og.Vec3} -
693
+ */
694
+ set(x, y, z) {
695
+ this.x = x;
696
+ this.y = y;
697
+ this.z = z;
698
+ return this;
699
+ };
710
700
 
711
- /**
712
- * Negate current vector.
713
- * @public
714
- * @returns {og.Vec3} -
715
- */
716
- Vec3.prototype.negate = function () {
717
- this.x = -this.x;
718
- this.y = -this.y;
719
- this.z = -this.z;
720
- return this;
721
- };
701
+ /**
702
+ * Negate current vector.
703
+ * @public
704
+ * @returns {og.Vec3} -
705
+ */
706
+ negate() {
707
+ this.x = -this.x;
708
+ this.y = -this.y;
709
+ this.z = -this.z;
710
+ return this;
711
+ };
722
712
 
723
- /**
724
- * Negate current vector to another instance.
725
- * @public
726
- * @returns {og.Vec3} -
727
- */
728
- Vec3.prototype.negateTo = function () {
729
- return new Vec3(-this.x, -this.y, -this.z);
730
- };
713
+ /**
714
+ * Negate current vector to another instance.
715
+ * @public
716
+ * @returns {og.Vec3} -
717
+ */
718
+ negateTo() {
719
+ return new Vec3(-this.x, -this.y, -this.z);
720
+ };
731
721
 
732
- /**
733
- * Gets projected point coordinates of the current vector on the ray.
734
- * @public
735
- * @param {og.Vec3} pos - Ray position.
736
- * @param {og.Vec3} direction - Ray direction.
737
- * @returns {og.Vec3} -
738
- */
739
- Vec3.prototype.projToRay = function (pos, direction) {
740
- var v = Vec3.proj_b_to_a(Vec3.sub(this, pos), direction);
741
- v.addA(pos);
742
- return v;
743
- };
722
+ /**
723
+ * Gets projected point coordinates of the current vector on the ray.
724
+ * @public
725
+ * @param {og.Vec3} pos - Ray position.
726
+ * @param {og.Vec3} direction - Ray direction.
727
+ * @returns {og.Vec3} -
728
+ */
729
+ projToRay(pos, direction) {
730
+ var v = Vec3.proj_b_to_a(Vec3.sub(this, pos), direction);
731
+ v.addA(pos);
732
+ return v;
733
+ };
744
734
 
745
- /**
746
- * Gets angle between two vectors.
747
- * @public
748
- * @param {og.Vec3} a - Another vector.
749
- * @returns {number} -
750
- */
751
- Vec3.prototype.angle = function (a) {
752
- return Vec3.angle(this, a);
753
- };
735
+ /**
736
+ * Gets angle between two vectors.
737
+ * @public
738
+ * @param {og.Vec3} a - Another vector.
739
+ * @returns {number} -
740
+ */
741
+ angle(a) {
742
+ return Vec3.angle(this, a);
743
+ };
754
744
 
755
- /**
756
- * Returns two vectors linear interpolation.
757
- * @public
758
- * @param {og.Vec3} v2 - End vector.
759
- * @param {number} l - Interpolate value.
760
- * @returns {og.Vec3} -
761
- */
762
- Vec3.prototype.lerp = function (v2, l) {
763
- return new Vec3(this.x + (v2.x - this.x) * l, this.y + (v2.y - this.y) * l, this.z + (v2.z - this.z) * l);
764
- };
745
+ /**
746
+ * Returns two vectors linear interpolation.
747
+ * @public
748
+ * @param {og.Vec3} v2 - End vector.
749
+ * @param {number} l - Interpolate value.
750
+ * @returns {og.Vec3} -
751
+ */
752
+ lerp(v2, l) {
753
+ return new Vec3(this.x + (v2.x - this.x) * l, this.y + (v2.y - this.y) * l, this.z + (v2.z - this.z) * l);
754
+ };
765
755
 
766
- /**
767
- * Returns vector interpolation by v(t) = v1 * t + v2 * (1 - t)
768
- * @public
769
- * @param {og.Vec3} v2 - End vector.
770
- * @param {number} t - Interpolate value.
771
- * @returns {og.Vec3} -
772
- */
773
- Vec3.prototype.smerp = function (v2, t) {
774
- var one_d = 1 - t;
775
- return new Vec3(this.x * t + v2.x * one_d, this.y * t + v2.y * one_d, this.z * t + v2.z * one_d);
776
- };
756
+ /**
757
+ * Returns vector interpolation by v(t) = v1 * t + v2 * (1 - t)
758
+ * @public
759
+ * @param {og.Vec3} v2 - End vector.
760
+ * @param {number} t - Interpolate value.
761
+ * @returns {og.Vec3} -
762
+ */
763
+ smerp(v2, t) {
764
+ var one_d = 1 - t;
765
+ return new Vec3(this.x * t + v2.x * one_d, this.y * t + v2.y * one_d, this.z * t + v2.z * one_d);
766
+ };
777
767
 
778
- Vec3.LERP_DELTA = 1e-6;
768
+ static get LERP_DELTA() { return 1e-6 };
779
769
 
780
- /**
781
- * Spherically interpolates between two vectors.
782
- * Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
783
- * the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
784
- * by the angle and its magnitude is interpolated between the magnitudes of from and to.
785
- * @public
786
- * @param {og.Vec3} v2 -
787
- * @param {number} t - The parameter t is clamped to the range [0, 1].
788
- * @returns {og.Vec3} -
789
- */
790
- Vec3.prototype.slerp = function (v2, t) {
791
- var res = new Vec3();
770
+ /**
771
+ * Spherically interpolates between two vectors.
772
+ * Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
773
+ * the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
774
+ * by the angle and its magnitude is interpolated between the magnitudes of from and to.
775
+ * @public
776
+ * @param {og.Vec3} v2 -
777
+ * @param {number} t - The parameter t is clamped to the range [0, 1].
778
+ * @returns {og.Vec3} -
779
+ */
780
+ slerp(v2, t) {
781
+ var res = new Vec3();
782
+
783
+ if (t <= 0.0) {
784
+ res.copy(this);
785
+ return;
786
+ } else if (t >= 1.0) {
787
+ res.copy(v2);
788
+ return;
789
+ }
792
790
 
793
- if (t <= 0.0) {
794
- res.copy(this);
795
- return;
796
- } else if (t >= 1.0) {
797
- res.copy(v2);
798
- return;
799
- }
800
-
801
- var omega, sinom, scale0, scale1;
802
- var cosom = this.dot(v2);
803
-
804
- if ((1.0 - cosom) > Vec3.LERP_DELTA) {
805
- omega = Math.acos(cosom);
806
- sinom = Math.sin(omega);
807
- scale0 = Math.sin((1.0 - t) * omega) / sinom;
808
- scale1 = Math.sin(t * omega) / sinom;
809
- } else {
810
- scale0 = 1.0 - t;
811
- scale1 = t;
812
- }
813
-
814
- return Vec3.add(this.scaleTo(scale0), v2.scale(scale1));
815
- };
791
+ var omega, sinom, scale0, scale1;
792
+ var cosom = this.dot(v2);
816
793
 
817
- /**
818
- * Gets the shortest arc quaternion to rotate this vector to the destination vector.
819
- * @param {Vec3} dest -
820
- * @param {Vec3} fallbackAxis -
821
- * @returns {Quat} -
822
- * @todo: TEST IT!
823
- */
824
- Vec3.prototype.getRotationTo = function (dest, fallbackAxis) {
825
- // Based on Stan Melax's article in Game Programming Gems
826
- // Copy, since cannot modify local
827
- let v0 = this.clone();
828
- let v1 = dest.clone();
829
- v0.normalize();
830
- v1.normalize();
831
-
832
- let d = v0.dot(v1);
833
- // If dot == 1, vectors are the same
834
- if (d >= 1.0) {
835
- return Quat.IDENTITY.clone();
836
- }
837
-
838
- if (d < (1e-6 - 1.0)) {
839
- if (!fallbackAxis.isEqual(Vec3.ZERO)) {
840
- // rotate 180 degrees about the fallback axis
841
- return Quat.axisAngleToQuat(Math.PI, fallbackAxis);
794
+ if ((1.0 - cosom) > Vec3.LERP_DELTA) {
795
+ omega = Math.acos(cosom);
796
+ sinom = Math.sin(omega);
797
+ scale0 = Math.sin((1.0 - t) * omega) / sinom;
798
+ scale1 = Math.sin(t * omega) / sinom;
842
799
  } else {
843
- // Generate an axis
844
- let axis = Vec3.UNIT_X.cross(v0);
845
- if (axis.isZero()) { // pick another if colinear
846
- axis = Vec3.UNIT_Y.cross(v0);
847
- }
848
- axis.normalize();
849
- return Quat.axisAngleToQuat(Math.PI, axis);
800
+ scale0 = 1.0 - t;
801
+ scale1 = t;
850
802
  }
851
- } else {
852
- let s = Math.sqrt((1 + d) * 2);
853
- let invs = 1.0 / s;
854
803
 
855
- let c = v0.cross(v1);
804
+ return Vec3.add(this.scaleTo(scale0), v2.scale(scale1));
805
+ };
806
+
807
+ /**
808
+ * Gets the shortest arc quaternion to rotate this vector to the destination vector.
809
+ * @param {Vec3} dest -
810
+ * @param {Vec3} fallbackAxis -
811
+ * @returns {Quat} -
812
+ * @todo: TEST IT!
813
+ */
814
+ getRotationTo(dest, fallbackAxis) {
815
+ // Based on Stan Melax's article in Game Programming Gems
816
+ // Copy, since cannot modify local
817
+ let v0 = this.clone();
818
+ let v1 = dest.clone();
819
+ v0.normalize();
820
+ v1.normalize();
821
+
822
+ let d = v0.dot(v1);
823
+ // If dot == 1, vectors are the same
824
+ if (d >= 1.0) {
825
+ return Quat.IDENTITY.clone();
826
+ }
827
+
828
+ if (d < (1e-6 - 1.0)) {
829
+ if (!fallbackAxis.isEqual(Vec3.ZERO)) {
830
+ // rotate 180 degrees about the fallback axis
831
+ return Quat.axisAngleToQuat(Math.PI, fallbackAxis);
832
+ } else {
833
+ // Generate an axis
834
+ let axis = Vec3.UNIT_X.cross(v0);
835
+ if (axis.isZero()) { // pick another if colinear
836
+ axis = Vec3.UNIT_Y.cross(v0);
837
+ }
838
+ axis.normalize();
839
+ return Quat.axisAngleToQuat(Math.PI, axis);
840
+ }
841
+ } else {
842
+ let s = Math.sqrt((1 + d) * 2);
843
+ let invs = 1.0 / s;
844
+
845
+ let c = v0.cross(v1);
856
846
 
857
- let q = new Quat(c.x * invs, c.y * invs, c.z * invs, s * 0.5);
858
- q.normalise();
859
- return q;
860
- }
847
+ let q = new Quat(c.x * invs, c.y * invs, c.z * invs, s * 0.5);
848
+ q.normalise();
849
+ return q;
850
+ }
851
+ };
852
+ }
853
+
854
+ /**
855
+ * Vector 3d object creator.
856
+ * @function
857
+ * @param {number} [x] - First cvalue.
858
+ * @param {number} [y] - Second value.
859
+ * @param {number} [z] - Third value.
860
+ * @returns {og.Vec3} -
861
+ */
862
+ export function vec3(x, y, z) {
863
+ return new Vec3(x, y, z);
861
864
  };
862
865
 
863
- export { Vec3 };