@woosh/meep-engine 2.33.71 → 2.33.75
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/core/geom/Vector3.js
CHANGED
|
@@ -11,7 +11,7 @@ import { sign } from "../math/sign.js";
|
|
|
11
11
|
import { v3_dot } from "./v3_dot.js";
|
|
12
12
|
import { v3_length_sqr } from "./v3_length_sqr.js";
|
|
13
13
|
import { v3_length } from "./v3_length.js";
|
|
14
|
-
import { v3_angle_between } from "./v3_angle_between.js";
|
|
14
|
+
import { v3_angle_between, v3_angle_between_atan2 } from "./v3_angle_between.js";
|
|
15
15
|
import { v3_lerp } from "./v3_lerp.js";
|
|
16
16
|
import { v3_slerp } from "./v3_slerp.js";
|
|
17
17
|
import { computeHashFloat } from "../math/hash/computeHashFloat.js";
|
|
@@ -448,7 +448,7 @@ class Vector3 {
|
|
|
448
448
|
* @returns {number}
|
|
449
449
|
*/
|
|
450
450
|
angleTo(other) {
|
|
451
|
-
return
|
|
451
|
+
return v3_angle_between_atan2(this.x, this.y, this.z, other.x, other.y, other.z);
|
|
452
452
|
}
|
|
453
453
|
|
|
454
454
|
/**
|
|
@@ -29,3 +29,25 @@ export function v3_angle_between(x0, y0, z0, x1, y1, z1) {
|
|
|
29
29
|
|
|
30
30
|
return Math.acos(theta);
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {number} x0
|
|
36
|
+
* @param {number} y0
|
|
37
|
+
* @param {number} z0
|
|
38
|
+
* @param {number} x1
|
|
39
|
+
* @param {number} y1
|
|
40
|
+
* @param {number} z1
|
|
41
|
+
* @returns {number}
|
|
42
|
+
*/
|
|
43
|
+
export function v3_angle_between_atan2(x0, y0, z0, x1, y1, z1) {
|
|
44
|
+
const cx = y0 * z1 - z0 * y1;
|
|
45
|
+
const cy = z0 * x1 - x0 * z1;
|
|
46
|
+
const cz = x0 * y1 - y0 * x1;
|
|
47
|
+
|
|
48
|
+
const cross_length = v3_length(cx, cy, cz);
|
|
49
|
+
|
|
50
|
+
const d = v3_dot(x0, y0, z0, x1, y1, z1);
|
|
51
|
+
|
|
52
|
+
return Math.atan2(cross_length, d);
|
|
53
|
+
}
|
|
@@ -12,9 +12,11 @@ import { eulerAnglesFromMatrix } from "../../../../../core/geom/3d/eulerAnglesFr
|
|
|
12
12
|
|
|
13
13
|
const m4 = new Matrix4();
|
|
14
14
|
const euler = new Euler();
|
|
15
|
+
const angles = [];
|
|
15
16
|
|
|
16
17
|
const panOffset = new Vector3();
|
|
17
18
|
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
*
|
|
20
22
|
* @param {number} displacement_x
|
|
@@ -26,9 +28,12 @@ export function rotate_from_view(displacement_x, displacement_y, input, output)
|
|
|
26
28
|
// crop yaw and pitch to safe range of -PI to PI
|
|
27
29
|
const i_pitch = normalize_angle_rad(input.pitch);
|
|
28
30
|
const i_yaw = normalize_angle_rad(input.yaw);
|
|
31
|
+
const i_roll = normalize_angle_rad(input.roll);
|
|
32
|
+
|
|
33
|
+
const d_roll = (i_roll >= (Math.PI - 0.0001) || i_roll <= -(Math.PI - 0.0001)) ? -1 : 1;
|
|
29
34
|
|
|
30
35
|
// flip rotation axis when pitch is over 90deg in either direction, that is UP vector is pointing down
|
|
31
|
-
const d_yaw = ((i_pitch > Math.PI || i_pitch < -Math.PI) ? -1 : 1) * displacement_x;
|
|
36
|
+
const d_yaw = d_roll * ((i_pitch > Math.PI || i_pitch < -Math.PI) ? -1 : 1) * displacement_x;
|
|
32
37
|
|
|
33
38
|
output.yaw = i_yaw + d_yaw;
|
|
34
39
|
output.pitch = i_pitch - displacement_y;
|
|
@@ -122,37 +127,18 @@ class TopDownCameraController {
|
|
|
122
127
|
* @param {Vector3} [up]
|
|
123
128
|
*/
|
|
124
129
|
setFromEyeAndTarget(eye, target, up = Vector3.up) {
|
|
130
|
+
|
|
125
131
|
/*
|
|
126
132
|
NOTE: I'm not sure why, but three.js camera points in the opposite direction to normal objects
|
|
127
133
|
See: https://github.com/mrdoob/three.js/blob/412b99a7f26e117ea97f40eb53d010ab81aa3279/src/core/Object3D.js#L282
|
|
128
134
|
*/
|
|
129
135
|
m4.lookAt(target, eye, up);
|
|
130
136
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const angles = [];
|
|
134
|
-
eulerAnglesFromMatrix(angles, m4.elements, 2, 1, 0);
|
|
135
|
-
|
|
136
|
-
const _p0 = normalize_angle_rad(euler.x);
|
|
137
|
-
const _y0 = normalize_angle_rad(euler.y);
|
|
138
|
-
const _r0 = normalize_angle_rad(euler.z);
|
|
139
|
-
|
|
140
|
-
this.pitch = _p0;
|
|
141
|
-
this.yaw = _y0;
|
|
142
|
-
this.roll = _r0;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const _p1 = angles[2];
|
|
146
|
-
const _y1 = angles[1];
|
|
147
|
-
const _r1 = angles[0];
|
|
148
|
-
|
|
149
|
-
if (_p0 !== _p0 || _y0 !== _y1 || _r0 !== _r1) {
|
|
150
|
-
console.warn('Angular discrepancy');
|
|
151
|
-
}
|
|
137
|
+
eulerAnglesFromMatrix(angles, m4.elements, 2, 1, 0)
|
|
152
138
|
|
|
153
|
-
this.pitch =
|
|
154
|
-
this.yaw =
|
|
155
|
-
this.roll =
|
|
139
|
+
this.pitch = angles[2];
|
|
140
|
+
this.yaw = angles[1];
|
|
141
|
+
this.roll = angles[0];
|
|
156
142
|
|
|
157
143
|
this.distance = eye.distanceTo(target);
|
|
158
144
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.33.
|
|
8
|
+
"version": "2.33.75",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|