@woosh/meep-engine 2.33.71 → 2.33.72
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
|
+
}
|
|
@@ -8,13 +8,14 @@ import { assert } from "../../../../../core/assert.js";
|
|
|
8
8
|
import { lerp } from "../../../../../core/math/lerp.js";
|
|
9
9
|
import { Euler, Matrix4 } from "three";
|
|
10
10
|
import { normalize_angle_rad } from "../../../../../core/geom/normalize_angle_rad.js";
|
|
11
|
-
import {
|
|
11
|
+
import { v3_angle_between_atan2 } from "../../../../../core/geom/v3_angle_between.js";
|
|
12
12
|
|
|
13
13
|
const m4 = new Matrix4();
|
|
14
14
|
const euler = new Euler();
|
|
15
15
|
|
|
16
16
|
const panOffset = new Vector3();
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
*
|
|
20
21
|
* @param {number} displacement_x
|
|
@@ -122,37 +123,74 @@ class TopDownCameraController {
|
|
|
122
123
|
* @param {Vector3} [up]
|
|
123
124
|
*/
|
|
124
125
|
setFromEyeAndTarget(eye, target, up = Vector3.up) {
|
|
126
|
+
/**
|
|
127
|
+
* ----
|
|
128
|
+
* float projectOnPlane(Vector3 a, Vector3 b) {
|
|
129
|
+
* Vector3 bProjection = (Vector3.Dot(a, b) / b.Length) * (b / b.Length);
|
|
130
|
+
* return a - bProjection;
|
|
131
|
+
* }
|
|
132
|
+
* ----
|
|
133
|
+
* @see https://gamedev.stackexchange.com/questions/134354/gravity-vector-and-forward-vector-to-local-heading-yaw-pitch-and-roll
|
|
134
|
+
* @param {Vector3} a
|
|
135
|
+
* @param {Vector3} b
|
|
136
|
+
*/
|
|
137
|
+
function projectOnPlane(a, b) {
|
|
138
|
+
const i = a.dot(b) / b.length();
|
|
139
|
+
const j = new Vector3();
|
|
140
|
+
j.copy(b);
|
|
141
|
+
j.normalize();
|
|
142
|
+
|
|
143
|
+
j.multiplyScalar(i);
|
|
144
|
+
|
|
145
|
+
j.subVectors(a, j);
|
|
146
|
+
|
|
147
|
+
return j;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function pitch(direction, gravity) {
|
|
151
|
+
const heading = projectOnPlane(direction, gravity);
|
|
152
|
+
|
|
153
|
+
return v3_angle_between_atan2(
|
|
154
|
+
direction.x, direction.y, direction.z,
|
|
155
|
+
heading.x, heading.y, heading.z
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function yaw(direction, gravity, north) {
|
|
160
|
+
const heading = projectOnPlane(direction, gravity);
|
|
161
|
+
|
|
162
|
+
return v3_angle_between_atan2(
|
|
163
|
+
heading.x, heading.y, heading.z,
|
|
164
|
+
north.x, north.y, north.z,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
// extract pitch and yaw only
|
|
170
|
+
const view_vector = new Vector3();
|
|
171
|
+
view_vector.subVectors(eye, target);
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
const _p3 = pitch(view_vector, up);
|
|
175
|
+
const _y3 = yaw(view_vector, up, Vector3.back);
|
|
176
|
+
|
|
125
177
|
/*
|
|
126
178
|
NOTE: I'm not sure why, but three.js camera points in the opposite direction to normal objects
|
|
127
179
|
See: https://github.com/mrdoob/three.js/blob/412b99a7f26e117ea97f40eb53d010ab81aa3279/src/core/Object3D.js#L282
|
|
128
180
|
*/
|
|
129
181
|
m4.lookAt(target, eye, up);
|
|
130
182
|
|
|
183
|
+
|
|
131
184
|
euler.setFromRotationMatrix(m4, 'ZYX');
|
|
132
185
|
|
|
133
|
-
const angles = [];
|
|
134
|
-
eulerAnglesFromMatrix(angles, m4.elements, 2, 1, 0);
|
|
135
186
|
|
|
136
187
|
const _p0 = normalize_angle_rad(euler.x);
|
|
137
188
|
const _y0 = normalize_angle_rad(euler.y);
|
|
138
189
|
const _r0 = normalize_angle_rad(euler.z);
|
|
139
190
|
|
|
140
|
-
this.pitch =
|
|
141
|
-
this.yaw =
|
|
142
|
-
this.roll =
|
|
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
|
-
}
|
|
152
|
-
|
|
153
|
-
this.pitch = _p1;
|
|
154
|
-
this.yaw = _y1;
|
|
155
|
-
this.roll = _r1;
|
|
191
|
+
this.pitch = _p3;
|
|
192
|
+
this.yaw = _y3;
|
|
193
|
+
this.roll = 0;
|
|
156
194
|
|
|
157
195
|
this.distance = eye.distanceTo(target);
|
|
158
196
|
|
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.72",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|