@woosh/meep-engine 2.33.72 → 2.33.76

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.
@@ -8,10 +8,11 @@ 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 { v3_angle_between_atan2 } from "../../../../../core/geom/v3_angle_between.js";
11
+ import { eulerAnglesFromMatrix } from "../../../../../core/geom/3d/eulerAnglesFromMatrix.js";
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
 
@@ -27,9 +28,12 @@ export function rotate_from_view(displacement_x, displacement_y, input, output)
27
28
  // crop yaw and pitch to safe range of -PI to PI
28
29
  const i_pitch = normalize_angle_rad(input.pitch);
29
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 / 2 - 0.0001) || i_roll <= -(Math.PI / 2 - 0.0001)) ? -1 : 1;
30
34
 
31
35
  // flip rotation axis when pitch is over 90deg in either direction, that is UP vector is pointing down
32
- 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 < 0) ? -1 : 1) * displacement_x;
33
37
 
34
38
  output.yaw = i_yaw + d_yaw;
35
39
  output.pitch = i_pitch - displacement_y;
@@ -123,56 +127,6 @@ class TopDownCameraController {
123
127
  * @param {Vector3} [up]
124
128
  */
125
129
  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
130
 
177
131
  /*
178
132
  NOTE: I'm not sure why, but three.js camera points in the opposite direction to normal objects
@@ -180,17 +134,11 @@ class TopDownCameraController {
180
134
  */
181
135
  m4.lookAt(target, eye, up);
182
136
 
137
+ eulerAnglesFromMatrix(angles, m4.elements, 2, 1, 0)
183
138
 
184
- euler.setFromRotationMatrix(m4, 'ZYX');
185
-
186
-
187
- const _p0 = normalize_angle_rad(euler.x);
188
- const _y0 = normalize_angle_rad(euler.y);
189
- const _r0 = normalize_angle_rad(euler.z);
190
-
191
- this.pitch = _p3;
192
- this.yaw = _y3;
193
- this.roll = 0;
139
+ this.pitch = angles[2];
140
+ this.yaw = angles[1];
141
+ this.roll = angles[0];
194
142
 
195
143
  this.distance = eye.distanceTo(target);
196
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.72",
8
+ "version": "2.33.76",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",