@antv/g-webgpu 0.5.6 → 1.1.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.
- package/LICENSE +21 -0
- package/README.md +0 -53
- package/dist/index.umd.min.js +16 -0
- package/es/ContextRegisterPlugin.d.ts +7 -0
- package/es/ContextRegisterPlugin.js +28 -0
- package/es/WebGLContextService.d.ts +18 -0
- package/es/WebGLContextService.js +99 -0
- package/es/index.d.ts +10 -7
- package/es/index.js +34 -8
- package/lib/ContextRegisterPlugin.d.ts +7 -0
- package/lib/ContextRegisterPlugin.js +37 -0
- package/lib/WebGLContextService.d.ts +18 -0
- package/lib/WebGLContextService.js +107 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +47 -43
- package/package.json +37 -31
- package/CHANGELOG.md +0 -89
- package/es/Kernel.d.ts +0 -21
- package/es/Kernel.js +0 -331
- package/es/Kernel.js.map +0 -1
- package/es/Renderer.d.ts +0 -24
- package/es/Renderer.js +0 -341
- package/es/Renderer.js.map +0 -1
- package/es/Scene.d.ts +0 -11
- package/es/Scene.js +0 -54
- package/es/Scene.js.map +0 -1
- package/es/View.d.ts +0 -20
- package/es/View.js +0 -86
- package/es/View.js.map +0 -1
- package/es/World.d.ts +0 -49
- package/es/World.js +0 -283
- package/es/World.js.map +0 -1
- package/es/camera/Camera.d.ts +0 -252
- package/es/camera/Camera.js +0 -831
- package/es/camera/Camera.js.map +0 -1
- package/es/camera/Landmark.d.ts +0 -28
- package/es/camera/Landmark.js +0 -86
- package/es/camera/Landmark.js.map +0 -1
- package/es/geometry/Box.d.ts +0 -11
- package/es/geometry/Box.js +0 -180
- package/es/geometry/Box.js.map +0 -1
- package/es/geometry/Merged.d.ts +0 -8
- package/es/geometry/Merged.js +0 -91
- package/es/geometry/Merged.js.map +0 -1
- package/es/geometry/Plane.d.ts +0 -10
- package/es/geometry/Plane.js +0 -112
- package/es/geometry/Plane.js.map +0 -1
- package/es/geometry/Sphere.d.ts +0 -9
- package/es/geometry/Sphere.js +0 -121
- package/es/geometry/Sphere.js.map +0 -1
- package/es/geometry/index.d.ts +0 -19
- package/es/geometry/index.js +0 -59
- package/es/geometry/index.js.map +0 -1
- package/es/glsl.d.js +0 -2
- package/es/glsl.d.js.map +0 -1
- package/es/index.js.map +0 -1
- package/es/material/basic/index.d.ts +0 -10
- package/es/material/basic/index.js +0 -108
- package/es/material/basic/index.js.map +0 -1
- package/es/material/index.d.ts +0 -16
- package/es/material/index.js +0 -60
- package/es/material/index.js.map +0 -1
- package/es/renderable/Renderable.d.ts +0 -41
- package/es/renderable/Renderable.js +0 -169
- package/es/renderable/Renderable.js.map +0 -1
- package/es/renderable/grid/index.d.ts +0 -17
- package/es/renderable/grid/index.js +0 -133
- package/es/renderable/grid/index.js.map +0 -1
- package/es/renderable/line/index.d.ts +0 -23
- package/es/renderable/line/index.js +0 -231
- package/es/renderable/line/index.js.map +0 -1
- package/es/renderable/point/index.d.ts +0 -29
- package/es/renderable/point/index.js +0 -241
- package/es/renderable/point/index.js.map +0 -1
- package/es/texture/Cache.d.ts +0 -6
- package/es/texture/Cache.js +0 -28
- package/es/texture/Cache.js.map +0 -1
- package/es/texture/Texture2D.d.ts +0 -13
- package/es/texture/Texture2D.js +0 -126
- package/es/texture/Texture2D.js.map +0 -1
- package/es/utils/canvas.d.ts +0 -1
- package/es/utils/canvas.js +0 -8
- package/es/utils/canvas.js.map +0 -1
- package/es/utils/is-array.d.ts +0 -2
- package/es/utils/is-array.js +0 -5
- package/es/utils/is-array.js.map +0 -1
- package/es/utils/is-number.d.ts +0 -1
- package/es/utils/is-number.js +0 -4
- package/es/utils/is-number.js.map +0 -1
- package/es/utils/is-type.d.ts +0 -2
- package/es/utils/is-type.js +0 -8
- package/es/utils/is-type.js.map +0 -1
- package/es/utils/is-typedarray.d.ts +0 -27
- package/es/utils/is-typedarray.js +0 -99
- package/es/utils/is-typedarray.js.map +0 -1
- package/es/utils/math.d.ts +0 -3
- package/es/utils/math.js +0 -24
- package/es/utils/math.js.map +0 -1
- package/es/utils/picking.d.ts +0 -1
- package/es/utils/picking.js +0 -4
- package/es/utils/picking.js.map +0 -1
- package/es/utils/polyline-normals.d.ts +0 -6
- package/es/utils/polyline-normals.js +0 -129
- package/es/utils/polyline-normals.js.map +0 -1
- package/es/utils/typedarray.d.ts +0 -1
- package/es/utils/typedarray.js +0 -29
- package/es/utils/typedarray.js.map +0 -1
- package/lib/Kernel.js +0 -352
- package/lib/Kernel.js.map +0 -1
- package/lib/Renderer.js +0 -354
- package/lib/Renderer.js.map +0 -1
- package/lib/Scene.js +0 -64
- package/lib/Scene.js.map +0 -1
- package/lib/View.js +0 -99
- package/lib/View.js.map +0 -1
- package/lib/World.js +0 -313
- package/lib/World.js.map +0 -1
- package/lib/camera/Camera.js +0 -900
- package/lib/camera/Camera.js.map +0 -1
- package/lib/camera/Landmark.js +0 -95
- package/lib/camera/Landmark.js.map +0 -1
- package/lib/geometry/Box.js +0 -205
- package/lib/geometry/Box.js.map +0 -1
- package/lib/geometry/Merged.js +0 -110
- package/lib/geometry/Merged.js.map +0 -1
- package/lib/geometry/Plane.js +0 -127
- package/lib/geometry/Plane.js.map +0 -1
- package/lib/geometry/Sphere.js +0 -136
- package/lib/geometry/Sphere.js.map +0 -1
- package/lib/geometry/index.js +0 -71
- package/lib/geometry/index.js.map +0 -1
- package/lib/glsl.d.js +0 -2
- package/lib/glsl.d.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/material/basic/index.js +0 -125
- package/lib/material/basic/index.js.map +0 -1
- package/lib/material/index.js +0 -72
- package/lib/material/index.js.map +0 -1
- package/lib/renderable/Renderable.js +0 -178
- package/lib/renderable/Renderable.js.map +0 -1
- package/lib/renderable/grid/index.js +0 -148
- package/lib/renderable/grid/index.js.map +0 -1
- package/lib/renderable/line/index.js +0 -248
- package/lib/renderable/line/index.js.map +0 -1
- package/lib/renderable/point/index.js +0 -259
- package/lib/renderable/point/index.js.map +0 -1
- package/lib/texture/Cache.js +0 -38
- package/lib/texture/Cache.js.map +0 -1
- package/lib/texture/Texture2D.js +0 -142
- package/lib/texture/Texture2D.js.map +0 -1
- package/lib/utils/canvas.js +0 -15
- package/lib/utils/canvas.js.map +0 -1
- package/lib/utils/is-array.js +0 -17
- package/lib/utils/is-array.js.map +0 -1
- package/lib/utils/is-number.js +0 -11
- package/lib/utils/is-number.js.map +0 -1
- package/lib/utils/is-type.js +0 -15
- package/lib/utils/is-type.js.map +0 -1
- package/lib/utils/is-typedarray.js +0 -109
- package/lib/utils/is-typedarray.js.map +0 -1
- package/lib/utils/math.js +0 -35
- package/lib/utils/math.js.map +0 -1
- package/lib/utils/picking.js +0 -11
- package/lib/utils/picking.js.map +0 -1
- package/lib/utils/polyline-normals.js +0 -137
- package/lib/utils/polyline-normals.js.map +0 -1
- package/lib/utils/typedarray.js +0 -36
- package/lib/utils/typedarray.js.map +0 -1
package/es/camera/Camera.js
DELETED
|
@@ -1,831 +0,0 @@
|
|
|
1
|
-
import _initializerDefineProperty from "@babel/runtime/helpers/initializerDefineProperty";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _applyDecoratedDescriptor from "@babel/runtime/helpers/applyDecoratedDescriptor";
|
|
5
|
-
import _initializerWarningHelper from "@babel/runtime/helpers/initializerWarningHelper";
|
|
6
|
-
|
|
7
|
-
var _dec, _dec2, _class, _class2, _descriptor, _class3, _temp;
|
|
8
|
-
|
|
9
|
-
import { Frustum, IDENTIFIER } from '@antv/g-webgpu-core';
|
|
10
|
-
import { mat3, mat4, quat, vec3, vec4 } from 'gl-matrix';
|
|
11
|
-
import { inject, injectable } from 'inversify';
|
|
12
|
-
import { createVec3, getAngle } from '../utils/math';
|
|
13
|
-
import Landmark from './Landmark';
|
|
14
|
-
export var CAMERA_TYPE;
|
|
15
|
-
|
|
16
|
-
(function (CAMERA_TYPE) {
|
|
17
|
-
CAMERA_TYPE["ORBITING"] = "ORBITING";
|
|
18
|
-
CAMERA_TYPE["EXPLORING"] = "EXPLORING";
|
|
19
|
-
CAMERA_TYPE["TRACKING"] = "TRACKING";
|
|
20
|
-
})(CAMERA_TYPE || (CAMERA_TYPE = {}));
|
|
21
|
-
|
|
22
|
-
export var CAMERA_TRACKING_MODE;
|
|
23
|
-
|
|
24
|
-
(function (CAMERA_TRACKING_MODE) {
|
|
25
|
-
CAMERA_TRACKING_MODE["DEFAULT"] = "DEFAULT";
|
|
26
|
-
CAMERA_TRACKING_MODE["ROTATIONAL"] = "ROTATIONAL";
|
|
27
|
-
CAMERA_TRACKING_MODE["TRANSLATIONAL"] = "TRANSLATIONAL";
|
|
28
|
-
CAMERA_TRACKING_MODE["CINEMATIC"] = "CINEMATIC";
|
|
29
|
-
})(CAMERA_TRACKING_MODE || (CAMERA_TRACKING_MODE = {}));
|
|
30
|
-
|
|
31
|
-
export var CAMERA_PROJECTION_MODE;
|
|
32
|
-
|
|
33
|
-
(function (CAMERA_PROJECTION_MODE) {
|
|
34
|
-
CAMERA_PROJECTION_MODE["ORTHOGRAPHIC"] = "ORTHOGRAPHIC";
|
|
35
|
-
CAMERA_PROJECTION_MODE["PERSPECTIVE"] = "PERSPECTIVE";
|
|
36
|
-
})(CAMERA_PROJECTION_MODE || (CAMERA_PROJECTION_MODE = {}));
|
|
37
|
-
|
|
38
|
-
var DEG_2_RAD = Math.PI / 180;
|
|
39
|
-
var RAD_2_DEG = 180 / Math.PI;
|
|
40
|
-
/**
|
|
41
|
-
* 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
|
|
42
|
-
* 保存相机参数,定义相机动作:
|
|
43
|
-
* 1. dolly 沿 n 轴移动
|
|
44
|
-
* 2. pan 沿 u v 轴移动
|
|
45
|
-
* 3. rotate 以方位角旋转
|
|
46
|
-
* 4. 移动到 Landmark,具有平滑的动画效果,其间禁止其他用户交互
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
export var Camera = (_dec = injectable(), _dec2 = inject(IDENTIFIER.InteractorService), _dec(_class = (_class2 = (_temp = _class3 = /*#__PURE__*/function () {
|
|
50
|
-
function Camera() {
|
|
51
|
-
_classCallCheck(this, Camera);
|
|
52
|
-
|
|
53
|
-
this.matrix = mat4.create();
|
|
54
|
-
this.right = vec3.fromValues(1, 0, 0);
|
|
55
|
-
this.up = vec3.fromValues(0, 1, 0);
|
|
56
|
-
this.forward = vec3.fromValues(0, 0, 1);
|
|
57
|
-
this.position = vec3.fromValues(0, 0, 1);
|
|
58
|
-
this.focalPoint = vec3.fromValues(0, 0, 0);
|
|
59
|
-
this.distanceVector = vec3.fromValues(0, 0, 0);
|
|
60
|
-
this.distance = 1;
|
|
61
|
-
this.azimuth = 0;
|
|
62
|
-
this.elevation = 0;
|
|
63
|
-
this.roll = 0;
|
|
64
|
-
this.relAzimuth = 0;
|
|
65
|
-
this.relElevation = 0;
|
|
66
|
-
this.relRoll = 0;
|
|
67
|
-
this.dollyingStep = 0;
|
|
68
|
-
this.maxDistance = Infinity;
|
|
69
|
-
this.minDistance = -Infinity;
|
|
70
|
-
this.rotateWorld = false;
|
|
71
|
-
|
|
72
|
-
_initializerDefineProperty(this, "interactor", _descriptor, this);
|
|
73
|
-
|
|
74
|
-
this.fov = 30;
|
|
75
|
-
this.near = 0.1;
|
|
76
|
-
this.far = 10000;
|
|
77
|
-
this.aspect = 1;
|
|
78
|
-
this.left = void 0;
|
|
79
|
-
this.rright = void 0;
|
|
80
|
-
this.top = void 0;
|
|
81
|
-
this.bottom = void 0;
|
|
82
|
-
this.zoom = 1;
|
|
83
|
-
this.perspective = mat4.create();
|
|
84
|
-
this.view = void 0;
|
|
85
|
-
this.following = undefined;
|
|
86
|
-
this.type = CAMERA_TYPE.EXPLORING;
|
|
87
|
-
this.trackingMode = CAMERA_TRACKING_MODE.DEFAULT;
|
|
88
|
-
this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
|
|
89
|
-
this.frustum = new Frustum();
|
|
90
|
-
this.landmarks = [];
|
|
91
|
-
this.landmarkAnimationID = void 0;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
_createClass(Camera, [{
|
|
95
|
-
key: "clone",
|
|
96
|
-
value: function clone() {
|
|
97
|
-
var camera = new Camera();
|
|
98
|
-
camera.setType(this.type, undefined);
|
|
99
|
-
camera.interactor = this.interactor;
|
|
100
|
-
return camera;
|
|
101
|
-
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "getProjectionMode",
|
|
104
|
-
value: function getProjectionMode() {
|
|
105
|
-
return this.projectionMode;
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
key: "getPerspective",
|
|
109
|
-
value: function getPerspective() {
|
|
110
|
-
return this.perspective;
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "getFrustum",
|
|
114
|
-
value: function getFrustum() {
|
|
115
|
-
return this.frustum;
|
|
116
|
-
}
|
|
117
|
-
}, {
|
|
118
|
-
key: "getPosition",
|
|
119
|
-
value: function getPosition() {
|
|
120
|
-
return this.position;
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
key: "setType",
|
|
124
|
-
value: function setType(type, trackingMode) {
|
|
125
|
-
this.type = type;
|
|
126
|
-
|
|
127
|
-
if (this.type === CAMERA_TYPE.EXPLORING) {
|
|
128
|
-
this.setWorldRotation(true);
|
|
129
|
-
} else {
|
|
130
|
-
this.setWorldRotation(false);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
this._getAngles();
|
|
134
|
-
|
|
135
|
-
if (this.type === CAMERA_TYPE.TRACKING && trackingMode !== undefined) {
|
|
136
|
-
this.setTrackingMode(trackingMode);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "setProjectionMode",
|
|
143
|
-
value: function setProjectionMode(projectionMode) {
|
|
144
|
-
this.projectionMode = projectionMode;
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
}, {
|
|
148
|
-
key: "setTrackingMode",
|
|
149
|
-
value: function setTrackingMode(trackingMode) {
|
|
150
|
-
if (this.type !== CAMERA_TYPE.TRACKING) {
|
|
151
|
-
throw new Error('Impossible to set a tracking mode if the camera is not of tracking type');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
this.trackingMode = trackingMode;
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* If flag is true, it reverses the azimuth and elevation angles.
|
|
159
|
-
* Subsequent calls to rotate, setAzimuth, setElevation,
|
|
160
|
-
* changeAzimuth or changeElevation will cause the inverted effect.
|
|
161
|
-
* setRoll or changeRoll is not affected by this method.
|
|
162
|
-
*
|
|
163
|
-
* This inversion is useful when one wants to simulate that the world
|
|
164
|
-
* is moving, instead of the camera.
|
|
165
|
-
*
|
|
166
|
-
* By default the camera angles are not reversed.
|
|
167
|
-
* @param {Boolean} flag the boolean flag to reverse the angles.
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
}, {
|
|
171
|
-
key: "setWorldRotation",
|
|
172
|
-
value: function setWorldRotation(flag) {
|
|
173
|
-
this.rotateWorld = flag;
|
|
174
|
-
|
|
175
|
-
this._getAngles();
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* 计算 MV 矩阵,为相机矩阵的逆矩阵
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
|
-
}, {
|
|
182
|
-
key: "getViewTransform",
|
|
183
|
-
value: function getViewTransform() {
|
|
184
|
-
return mat4.invert(mat4.create(), this.matrix);
|
|
185
|
-
}
|
|
186
|
-
}, {
|
|
187
|
-
key: "getWorldTransform",
|
|
188
|
-
value: function getWorldTransform() {
|
|
189
|
-
return this.matrix;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* 设置相机矩阵
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
|
-
}, {
|
|
196
|
-
key: "setMatrix",
|
|
197
|
-
value: function setMatrix(matrix) {
|
|
198
|
-
this.matrix = matrix;
|
|
199
|
-
|
|
200
|
-
this._update();
|
|
201
|
-
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
}, {
|
|
205
|
-
key: "setAspect",
|
|
206
|
-
value: function setAspect(aspect) {
|
|
207
|
-
this.setPerspective(this.near, this.far, this.fov, aspect);
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Sets an offset in a larger frustum, used in PixelPicking
|
|
212
|
-
*/
|
|
213
|
-
|
|
214
|
-
}, {
|
|
215
|
-
key: "setViewOffset",
|
|
216
|
-
value: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
|
|
217
|
-
this.aspect = fullWidth / fullHeight;
|
|
218
|
-
|
|
219
|
-
if (this.view === undefined) {
|
|
220
|
-
this.view = {
|
|
221
|
-
enabled: true,
|
|
222
|
-
fullWidth: 1,
|
|
223
|
-
fullHeight: 1,
|
|
224
|
-
offsetX: 0,
|
|
225
|
-
offsetY: 0,
|
|
226
|
-
width: 1,
|
|
227
|
-
height: 1
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
this.view.enabled = true;
|
|
232
|
-
this.view.fullWidth = fullWidth;
|
|
233
|
-
this.view.fullHeight = fullHeight;
|
|
234
|
-
this.view.offsetX = x;
|
|
235
|
-
this.view.offsetY = y;
|
|
236
|
-
this.view.width = width;
|
|
237
|
-
this.view.height = height;
|
|
238
|
-
|
|
239
|
-
if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
|
|
240
|
-
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
241
|
-
} else {
|
|
242
|
-
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return this;
|
|
246
|
-
}
|
|
247
|
-
}, {
|
|
248
|
-
key: "clearViewOffset",
|
|
249
|
-
value: function clearViewOffset() {
|
|
250
|
-
if (this.view !== undefined) {
|
|
251
|
-
this.view.enabled = false;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
|
|
255
|
-
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
256
|
-
} else {
|
|
257
|
-
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return this;
|
|
261
|
-
}
|
|
262
|
-
}, {
|
|
263
|
-
key: "setPerspective",
|
|
264
|
-
value: function setPerspective(near, far, fov, aspect) {
|
|
265
|
-
this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
|
|
266
|
-
this.fov = fov;
|
|
267
|
-
this.near = near;
|
|
268
|
-
this.far = far;
|
|
269
|
-
this.aspect = aspect;
|
|
270
|
-
mat4.perspective(this.perspective, this.fov * DEG_2_RAD, this.aspect, this.near, this.far);
|
|
271
|
-
return this;
|
|
272
|
-
}
|
|
273
|
-
}, {
|
|
274
|
-
key: "setOrthographic",
|
|
275
|
-
value: function setOrthographic(l, r, t, b, near, far) {
|
|
276
|
-
this.projectionMode = CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
|
|
277
|
-
this.rright = r;
|
|
278
|
-
this.left = l;
|
|
279
|
-
this.top = t;
|
|
280
|
-
this.bottom = b;
|
|
281
|
-
this.near = near;
|
|
282
|
-
this.far = far;
|
|
283
|
-
var dx = (this.rright - this.left) / (2 * this.zoom);
|
|
284
|
-
var dy = (this.top - this.bottom) / (2 * this.zoom);
|
|
285
|
-
var cx = (this.rright + this.left) / 2;
|
|
286
|
-
var cy = (this.top + this.bottom) / 2;
|
|
287
|
-
var left = cx - dx;
|
|
288
|
-
var right = cx + dx;
|
|
289
|
-
var top = cy + dy;
|
|
290
|
-
var bottom = cy - dy;
|
|
291
|
-
|
|
292
|
-
if (this.view !== undefined && this.view.enabled) {
|
|
293
|
-
var scaleW = (this.rright - this.left) / this.view.fullWidth / this.zoom;
|
|
294
|
-
var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
|
|
295
|
-
left += scaleW * this.view.offsetX;
|
|
296
|
-
right = left + scaleW * this.view.width;
|
|
297
|
-
top -= scaleH * this.view.offsetY;
|
|
298
|
-
bottom = top - scaleH * this.view.height;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
mat4.ortho(this.perspective, left, right, top, bottom, near, far);
|
|
302
|
-
return this;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* 设置相机位置
|
|
306
|
-
*/
|
|
307
|
-
|
|
308
|
-
}, {
|
|
309
|
-
key: "setPosition",
|
|
310
|
-
value: function setPosition(x, y, z) {
|
|
311
|
-
this._setPosition(x, y, z);
|
|
312
|
-
|
|
313
|
-
this.setFocalPoint(this.focalPoint);
|
|
314
|
-
return this;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* 设置视点位置
|
|
318
|
-
*/
|
|
319
|
-
|
|
320
|
-
}, {
|
|
321
|
-
key: "setFocalPoint",
|
|
322
|
-
value: function setFocalPoint(x, y, z) {
|
|
323
|
-
var up = vec3.fromValues(0, 1, 0);
|
|
324
|
-
this.focalPoint = createVec3(x, y, z);
|
|
325
|
-
|
|
326
|
-
if (this.trackingMode === CAMERA_TRACKING_MODE.CINEMATIC) {
|
|
327
|
-
var d = vec3.subtract(vec3.create(), this.focalPoint, this.position);
|
|
328
|
-
x = d[0];
|
|
329
|
-
y = d[1];
|
|
330
|
-
z = d[2];
|
|
331
|
-
var r = vec3.length(d);
|
|
332
|
-
var el = Math.asin(y / r) * RAD_2_DEG;
|
|
333
|
-
var az = 90 + Math.atan2(z, x) * RAD_2_DEG;
|
|
334
|
-
var m = mat4.create();
|
|
335
|
-
mat4.rotateY(m, m, az * DEG_2_RAD);
|
|
336
|
-
mat4.rotateX(m, m, el * DEG_2_RAD);
|
|
337
|
-
up = vec3.transformMat4(vec3.create(), [0, 1, 0], m);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
mat4.invert(this.matrix, mat4.lookAt(mat4.create(), this.position, this.focalPoint, up));
|
|
341
|
-
|
|
342
|
-
this._getAxes();
|
|
343
|
-
|
|
344
|
-
this._getDistance();
|
|
345
|
-
|
|
346
|
-
this._getAngles();
|
|
347
|
-
|
|
348
|
-
return this;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* 固定当前视点,按指定距离放置相机
|
|
352
|
-
*/
|
|
353
|
-
|
|
354
|
-
}, {
|
|
355
|
-
key: "setDistance",
|
|
356
|
-
value: function setDistance(d) {
|
|
357
|
-
if (this.distance === d || d < 0) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
this.distance = d;
|
|
362
|
-
|
|
363
|
-
if (this.distance < 0.0002) {
|
|
364
|
-
this.distance = 0.0002;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
this.dollyingStep = this.distance / 100;
|
|
368
|
-
var pos = vec3.create();
|
|
369
|
-
d = this.distance;
|
|
370
|
-
var n = this.forward;
|
|
371
|
-
var f = this.focalPoint;
|
|
372
|
-
pos[0] = d * n[0] + f[0];
|
|
373
|
-
pos[1] = d * n[1] + f[1];
|
|
374
|
-
pos[2] = d * n[2] + f[2];
|
|
375
|
-
|
|
376
|
-
this._setPosition(pos);
|
|
377
|
-
|
|
378
|
-
return this;
|
|
379
|
-
}
|
|
380
|
-
}, {
|
|
381
|
-
key: "setMaxDistance",
|
|
382
|
-
value: function setMaxDistance(d) {
|
|
383
|
-
this.maxDistance = d;
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
}, {
|
|
387
|
-
key: "setMinDistance",
|
|
388
|
-
value: function setMinDistance(d) {
|
|
389
|
-
this.minDistance = d;
|
|
390
|
-
return this;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Changes the initial azimuth of the camera
|
|
394
|
-
*/
|
|
395
|
-
|
|
396
|
-
}, {
|
|
397
|
-
key: "changeAzimuth",
|
|
398
|
-
value: function changeAzimuth(az) {
|
|
399
|
-
this.setAzimuth(this.azimuth + az);
|
|
400
|
-
return this;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Changes the initial elevation of the camera
|
|
404
|
-
*/
|
|
405
|
-
|
|
406
|
-
}, {
|
|
407
|
-
key: "changeElevation",
|
|
408
|
-
value: function changeElevation(el) {
|
|
409
|
-
this.setElevation(this.elevation + el);
|
|
410
|
-
return this;
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Changes the initial roll of the camera
|
|
414
|
-
*/
|
|
415
|
-
|
|
416
|
-
}, {
|
|
417
|
-
key: "changeRoll",
|
|
418
|
-
value: function changeRoll(rl) {
|
|
419
|
-
this.setRoll(this.roll + rl);
|
|
420
|
-
return this;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
424
|
-
* @param {Number} el the azimuth in degrees
|
|
425
|
-
*/
|
|
426
|
-
|
|
427
|
-
}, {
|
|
428
|
-
key: "setAzimuth",
|
|
429
|
-
value: function setAzimuth(az) {
|
|
430
|
-
this.azimuth = getAngle(az);
|
|
431
|
-
this.computeMatrix();
|
|
432
|
-
|
|
433
|
-
this._getAxes();
|
|
434
|
-
|
|
435
|
-
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
436
|
-
this._getPosition();
|
|
437
|
-
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
438
|
-
this._getFocalPoint();
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
return this;
|
|
442
|
-
}
|
|
443
|
-
}, {
|
|
444
|
-
key: "getAzimuth",
|
|
445
|
-
value: function getAzimuth() {
|
|
446
|
-
return this.azimuth;
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
450
|
-
* @param {Number} el the elevation in degrees
|
|
451
|
-
*/
|
|
452
|
-
|
|
453
|
-
}, {
|
|
454
|
-
key: "setElevation",
|
|
455
|
-
value: function setElevation(el) {
|
|
456
|
-
this.elevation = getAngle(el);
|
|
457
|
-
this.computeMatrix();
|
|
458
|
-
|
|
459
|
-
this._getAxes();
|
|
460
|
-
|
|
461
|
-
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
462
|
-
this._getPosition();
|
|
463
|
-
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
464
|
-
this._getFocalPoint();
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return this;
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
471
|
-
* @param {Number} angle the roll angle
|
|
472
|
-
*/
|
|
473
|
-
|
|
474
|
-
}, {
|
|
475
|
-
key: "setRoll",
|
|
476
|
-
value: function setRoll(angle) {
|
|
477
|
-
this.roll = getAngle(angle);
|
|
478
|
-
this.computeMatrix();
|
|
479
|
-
|
|
480
|
-
this._getAxes();
|
|
481
|
-
|
|
482
|
-
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
483
|
-
this._getPosition();
|
|
484
|
-
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
485
|
-
this._getFocalPoint();
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
return this;
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Changes the azimuth and elevation with respect to the current camera axes
|
|
492
|
-
* @param {Number} azimuth the relative azimuth
|
|
493
|
-
* @param {Number} elevation the relative elevation
|
|
494
|
-
* @param {Number} roll the relative roll
|
|
495
|
-
*/
|
|
496
|
-
|
|
497
|
-
}, {
|
|
498
|
-
key: "rotate",
|
|
499
|
-
value: function rotate(azimuth, elevation, roll) {
|
|
500
|
-
if (this.type === CAMERA_TYPE.EXPLORING) {
|
|
501
|
-
azimuth = getAngle(azimuth);
|
|
502
|
-
elevation = getAngle(elevation);
|
|
503
|
-
roll = getAngle(roll);
|
|
504
|
-
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld ? 1 : -1) * elevation * DEG_2_RAD);
|
|
505
|
-
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld ? 1 : -1) * azimuth * DEG_2_RAD);
|
|
506
|
-
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], roll * DEG_2_RAD);
|
|
507
|
-
var rotQ = quat.multiply(quat.create(), rotY, rotX);
|
|
508
|
-
rotQ = quat.multiply(quat.create(), rotQ, rotZ);
|
|
509
|
-
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
|
|
510
|
-
mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]);
|
|
511
|
-
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
512
|
-
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
|
|
513
|
-
} else {
|
|
514
|
-
if (Math.abs(this.elevation + elevation) > 90) {
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
this.relElevation = getAngle(elevation);
|
|
519
|
-
this.relAzimuth = getAngle(azimuth);
|
|
520
|
-
this.relRoll = getAngle(roll);
|
|
521
|
-
this.elevation += this.relElevation;
|
|
522
|
-
this.azimuth += this.relAzimuth;
|
|
523
|
-
this.roll += this.relRoll;
|
|
524
|
-
this.computeMatrix();
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
this._getAxes();
|
|
528
|
-
|
|
529
|
-
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
530
|
-
this._getPosition();
|
|
531
|
-
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
532
|
-
this._getFocalPoint();
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
this._update();
|
|
536
|
-
|
|
537
|
-
return this;
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* 沿水平(right) & 垂直(up)平移相机
|
|
541
|
-
*/
|
|
542
|
-
|
|
543
|
-
}, {
|
|
544
|
-
key: "pan",
|
|
545
|
-
value: function pan(tx, ty) {
|
|
546
|
-
var coords = createVec3(tx, ty, 0);
|
|
547
|
-
var pos = vec3.clone(this.position);
|
|
548
|
-
vec3.add(pos, pos, vec3.scale(vec3.create(), this.right, coords[0]));
|
|
549
|
-
vec3.add(pos, pos, vec3.scale(vec3.create(), this.up, coords[1]));
|
|
550
|
-
|
|
551
|
-
this._setPosition(pos);
|
|
552
|
-
|
|
553
|
-
return this;
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢
|
|
557
|
-
*/
|
|
558
|
-
|
|
559
|
-
}, {
|
|
560
|
-
key: "dolly",
|
|
561
|
-
value: function dolly(value) {
|
|
562
|
-
var n = this.forward;
|
|
563
|
-
var pos = vec3.clone(this.position);
|
|
564
|
-
var step = value * this.dollyingStep;
|
|
565
|
-
var updatedDistance = this.distance + value * this.dollyingStep; // 限制视点距离范围
|
|
566
|
-
|
|
567
|
-
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance;
|
|
568
|
-
pos[0] += step * n[0];
|
|
569
|
-
pos[1] += step * n[1];
|
|
570
|
-
pos[2] += step * n[2];
|
|
571
|
-
|
|
572
|
-
this._setPosition(pos);
|
|
573
|
-
|
|
574
|
-
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
575
|
-
// 重新计算视点距离
|
|
576
|
-
this._getDistance();
|
|
577
|
-
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
578
|
-
// 保持视距,移动视点位置
|
|
579
|
-
vec3.add(this.focalPoint, pos, this.distanceVector);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
return this;
|
|
583
|
-
}
|
|
584
|
-
}, {
|
|
585
|
-
key: "createLandmark",
|
|
586
|
-
value: function createLandmark(name, params) {
|
|
587
|
-
var camera = this.clone();
|
|
588
|
-
camera.setPosition(params.position);
|
|
589
|
-
camera.setFocalPoint(params.focalPoint);
|
|
590
|
-
|
|
591
|
-
if (params.roll !== undefined) {
|
|
592
|
-
camera.setRoll(params.roll);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
var landmark = new Landmark(name, camera);
|
|
596
|
-
this.landmarks.push(landmark);
|
|
597
|
-
return landmark;
|
|
598
|
-
}
|
|
599
|
-
}, {
|
|
600
|
-
key: "setLandmark",
|
|
601
|
-
value: function setLandmark(name) {
|
|
602
|
-
var landmark = new Landmark(name, this);
|
|
603
|
-
this.landmarks.push(landmark);
|
|
604
|
-
return this;
|
|
605
|
-
}
|
|
606
|
-
}, {
|
|
607
|
-
key: "gotoLandmark",
|
|
608
|
-
value: function gotoLandmark(name) {
|
|
609
|
-
var _this = this;
|
|
610
|
-
|
|
611
|
-
var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
612
|
-
var landmark = this.landmarks.find(function (l) {
|
|
613
|
-
return l.name === name;
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
if (landmark) {
|
|
617
|
-
if (duration === 0) {
|
|
618
|
-
landmark.retrieve(this);
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (this.landmarkAnimationID !== undefined) {
|
|
623
|
-
window.cancelAnimationFrame(this.landmarkAnimationID);
|
|
624
|
-
} // TODO: do not process events during animation
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
this.interactor.disconnect();
|
|
628
|
-
var destPosition = landmark.getPosition();
|
|
629
|
-
var destFocalPoint = landmark.getFocalPoint();
|
|
630
|
-
var destRoll = landmark.getRoll();
|
|
631
|
-
var timeStart;
|
|
632
|
-
|
|
633
|
-
var animate = function animate(timestamp) {
|
|
634
|
-
if (timeStart === undefined) {
|
|
635
|
-
timeStart = timestamp;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
var elapsed = timestamp - timeStart; // TODO: use better ease function
|
|
639
|
-
|
|
640
|
-
var t = (1 - Math.cos(elapsed / duration * Math.PI)) / 2;
|
|
641
|
-
var interFocalPoint = vec3.create();
|
|
642
|
-
var interPosition = vec3.create();
|
|
643
|
-
var interRoll = 0;
|
|
644
|
-
vec3.lerp(interFocalPoint, _this.focalPoint, destFocalPoint, t);
|
|
645
|
-
vec3.lerp(interPosition, _this.position, destPosition, t);
|
|
646
|
-
interRoll = _this.roll * (1 - t) + destRoll * t;
|
|
647
|
-
|
|
648
|
-
_this.setFocalPoint(interFocalPoint);
|
|
649
|
-
|
|
650
|
-
_this.setPosition(interPosition);
|
|
651
|
-
|
|
652
|
-
_this.setRoll(interRoll);
|
|
653
|
-
|
|
654
|
-
_this.computeMatrix();
|
|
655
|
-
|
|
656
|
-
var dist = vec3.dist(interFocalPoint, destFocalPoint) + vec3.dist(interPosition, destPosition);
|
|
657
|
-
|
|
658
|
-
if (dist > 0.01) {//
|
|
659
|
-
} else {
|
|
660
|
-
_this.setFocalPoint(interFocalPoint);
|
|
661
|
-
|
|
662
|
-
_this.setPosition(interPosition);
|
|
663
|
-
|
|
664
|
-
_this.setRoll(interRoll);
|
|
665
|
-
|
|
666
|
-
_this.computeMatrix();
|
|
667
|
-
|
|
668
|
-
_this.interactor.connect();
|
|
669
|
-
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
if (elapsed < duration) {
|
|
674
|
-
_this.landmarkAnimationID = window.requestAnimationFrame(animate);
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
window.requestAnimationFrame(animate);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* 根据相机矩阵重新计算各种相机参数
|
|
683
|
-
*/
|
|
684
|
-
|
|
685
|
-
}, {
|
|
686
|
-
key: "_update",
|
|
687
|
-
value: function _update() {
|
|
688
|
-
this._getAxes();
|
|
689
|
-
|
|
690
|
-
this._getPosition();
|
|
691
|
-
|
|
692
|
-
this._getDistance();
|
|
693
|
-
|
|
694
|
-
this._getAngles();
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* 计算相机矩阵
|
|
698
|
-
*/
|
|
699
|
-
|
|
700
|
-
}, {
|
|
701
|
-
key: "computeMatrix",
|
|
702
|
-
value: function computeMatrix() {
|
|
703
|
-
var rotX;
|
|
704
|
-
var rotY; // 使用四元数描述 3D 旋转
|
|
705
|
-
// @see https://xiaoiver.github.io/coding/2018/12/28/Camera-%E8%AE%BE%E8%AE%A1-%E4%B8%80.html
|
|
706
|
-
|
|
707
|
-
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], this.roll * DEG_2_RAD);
|
|
708
|
-
mat4.identity(this.matrix); // only consider HCS for EXPLORING and ORBITING cameras
|
|
709
|
-
|
|
710
|
-
rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.elevation * DEG_2_RAD);
|
|
711
|
-
rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.azimuth * DEG_2_RAD);
|
|
712
|
-
var rotQ = quat.multiply(quat.create(), rotY, rotX);
|
|
713
|
-
rotQ = quat.multiply(quat.create(), rotQ, rotZ);
|
|
714
|
-
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
|
|
715
|
-
|
|
716
|
-
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
717
|
-
mat4.translate(this.matrix, this.matrix, this.focalPoint);
|
|
718
|
-
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
719
|
-
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
|
|
720
|
-
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
721
|
-
mat4.translate(this.matrix, this.matrix, this.position);
|
|
722
|
-
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Sets the camera position in the camera matrix
|
|
727
|
-
*/
|
|
728
|
-
|
|
729
|
-
}, {
|
|
730
|
-
key: "_setPosition",
|
|
731
|
-
value: function _setPosition(x, y, z) {
|
|
732
|
-
this.position = createVec3(x, y, z);
|
|
733
|
-
var m = this.matrix;
|
|
734
|
-
m[12] = this.position[0];
|
|
735
|
-
m[13] = this.position[1];
|
|
736
|
-
m[14] = this.position[2];
|
|
737
|
-
m[15] = 1;
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Recalculates axes based on the current matrix
|
|
741
|
-
*/
|
|
742
|
-
|
|
743
|
-
}, {
|
|
744
|
-
key: "_getAxes",
|
|
745
|
-
value: function _getAxes() {
|
|
746
|
-
vec3.copy(this.right, createVec3(vec4.transformMat4(vec4.create(), [1, 0, 0, 0], this.matrix)));
|
|
747
|
-
vec3.copy(this.up, createVec3(vec4.transformMat4(vec4.create(), [0, 1, 0, 0], this.matrix)));
|
|
748
|
-
vec3.copy(this.forward, createVec3(vec4.transformMat4(vec4.create(), [0, 0, 1, 0], this.matrix)));
|
|
749
|
-
vec3.normalize(this.right, this.right);
|
|
750
|
-
vec3.normalize(this.up, this.up);
|
|
751
|
-
vec3.normalize(this.forward, this.forward);
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Recalculates euler angles based on the current state
|
|
755
|
-
*/
|
|
756
|
-
|
|
757
|
-
}, {
|
|
758
|
-
key: "_getAngles",
|
|
759
|
-
value: function _getAngles() {
|
|
760
|
-
// Recalculates angles
|
|
761
|
-
var x = this.distanceVector[0];
|
|
762
|
-
var y = this.distanceVector[1];
|
|
763
|
-
var z = this.distanceVector[2];
|
|
764
|
-
var r = vec3.length(this.distanceVector); // FAST FAIL: If there is no distance we cannot compute angles
|
|
765
|
-
|
|
766
|
-
if (r === 0) {
|
|
767
|
-
this.elevation = 0;
|
|
768
|
-
this.azimuth = 0;
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
if (this.type === CAMERA_TYPE.TRACKING) {
|
|
773
|
-
this.elevation = Math.asin(y / r) * RAD_2_DEG;
|
|
774
|
-
this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
|
|
775
|
-
} else {
|
|
776
|
-
if (this.rotateWorld) {
|
|
777
|
-
this.elevation = Math.asin(y / r) * RAD_2_DEG;
|
|
778
|
-
this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
|
|
779
|
-
} else {
|
|
780
|
-
this.elevation = -Math.asin(y / r) * RAD_2_DEG;
|
|
781
|
-
this.azimuth = -Math.atan2(-x, -z) * RAD_2_DEG;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* 重新计算相机位置,只有 ORBITING 模式相机位置才会发生变化
|
|
787
|
-
*/
|
|
788
|
-
|
|
789
|
-
}, {
|
|
790
|
-
key: "_getPosition",
|
|
791
|
-
value: function _getPosition() {
|
|
792
|
-
vec3.copy(this.position, createVec3(vec4.transformMat4(vec4.create(), [0, 0, 0, 1], this.matrix))); // 相机位置变化,需要重新计算视距
|
|
793
|
-
|
|
794
|
-
this._getDistance();
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* 重新计算视点,只有 TRACKING 模式视点才会发生变化
|
|
798
|
-
*/
|
|
799
|
-
|
|
800
|
-
}, {
|
|
801
|
-
key: "_getFocalPoint",
|
|
802
|
-
value: function _getFocalPoint() {
|
|
803
|
-
vec3.transformMat3(this.distanceVector, [0, 0, -this.distance], mat3.fromMat4(mat3.create(), this.matrix));
|
|
804
|
-
vec3.add(this.focalPoint, this.position, this.distanceVector); // 视点变化,需要重新计算视距
|
|
805
|
-
|
|
806
|
-
this._getDistance();
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* 重新计算视距
|
|
810
|
-
*/
|
|
811
|
-
|
|
812
|
-
}, {
|
|
813
|
-
key: "_getDistance",
|
|
814
|
-
value: function _getDistance() {
|
|
815
|
-
this.distanceVector = vec3.subtract(vec3.create(), this.focalPoint, this.position);
|
|
816
|
-
this.distance = vec3.length(this.distanceVector);
|
|
817
|
-
this.dollyingStep = this.distance / 100;
|
|
818
|
-
}
|
|
819
|
-
}]);
|
|
820
|
-
|
|
821
|
-
return Camera;
|
|
822
|
-
}(), _class3.ProjectionMode = {
|
|
823
|
-
ORTHOGRAPHIC: 'ORTHOGRAPHIC',
|
|
824
|
-
PERSPECTIVE: 'PERSPECTIVE'
|
|
825
|
-
}, _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "interactor", [_dec2], {
|
|
826
|
-
configurable: true,
|
|
827
|
-
enumerable: true,
|
|
828
|
-
writable: true,
|
|
829
|
-
initializer: null
|
|
830
|
-
})), _class2)) || _class);
|
|
831
|
-
//# sourceMappingURL=Camera.js.map
|