Skip to content

Commit

Permalink
Release commit created with Cranko.
Browse files Browse the repository at this point in the history
+++ cranko-release-info-v1
[[projects]]
qnames = ["@wwtelescope/research-app-messages", "npm"]
version = "0.18.0"
age = 1

[[projects]]
qnames = ["@wwtelescope/engine-types", "npm"]
version = "0.6.7"
age = 3

[[projects]]
qnames = ["@wwtelescope/engine", "npm"]
version = "7.30.1"
age = 0

[[projects]]
qnames = ["@wwtelescope/embed-common", "npm"]
version = "0.3.6"
age = 1

[[projects]]
qnames = ["@wwtelescope/embed-creator", "npm"]
version = "0.5.1"
age = 1

[[projects]]
qnames = ["@wwtelescope/astro", "npm"]
version = "0.2.5"
age = 3

[[projects]]
qnames = ["@wwtelescope/engine-helpers", "npm"]
version = "0.16.1"
age = 1

[[projects]]
qnames = ["@wwtelescope/engine-pinia", "npm"]
version = "0.10.0"
age = 1

[[projects]]
qnames = ["@wwtelescope/research-app", "npm"]
version = "0.17.0"
age = 1

[[projects]]
qnames = ["@wwtelescope/embed", "npm"]
version = "1.7.1"
age = 1

+++
  • Loading branch information
cranko committed Feb 8, 2024
2 parents c5d4a20 + ff44dc0 commit f83b1dd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
6 changes: 6 additions & 0 deletions engine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# @wwtelescope/engine 7.30.1 (2024-02-08)

- Further improvements to touch gesture handling (#288, @Carifio24). Hopefully
this nails it!


# @wwtelescope/engine 7.30.0 (2024-02-07)

- Add a `TileCache.clearCache()` method allowing the tile cache to be cleared
Expand Down
46 changes: 32 additions & 14 deletions engine/esm/wwt_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ export function WWTControl() {
this._moved = false;
this._zooming = false;
this._rotating = false;
this._dragThreshold = 4;
this._dragThreshold = 8;
this._twoTouchCenter = null;
this._lastTouchRect = new Array(2);
this._twoTouchEvents = 0;
this._twoTouchEventThreshold = 10;

this._foregroundCanvas = null;
this._fgDevice = null;
Expand Down Expand Up @@ -1145,6 +1149,11 @@ var WWTControl$ = {
this._lastY = ev.targetTouches[0].pageY;
if (ev.targetTouches.length === 2) {
this._hasTwoTouches = true;
var t0 = ev.touches[0];
var t1 = ev.touches[1];
this._twoTouchCenter = Vector2d.create(0.5 * (t0.pageX + t1.pageX), 0.5 * (t0.pageY + t1.pageY));
this._lastTouchRect[0] = Vector2d.create(t0.pageX, t0.pageY);
this._lastTouchRect[1] = Vector2d.create(t1.pageX, t1.pageY);
return;
}
if (this.uiController != null) {
Expand All @@ -1167,13 +1176,15 @@ var WWTControl$ = {
var newRect = new Array(2);
newRect[0] = Vector2d.create(t0.pageX, t0.pageY);
newRect[1] = Vector2d.create(t1.pageX, t1.pageY);
this._twoTouchEvents += 1;

if (!this._dragging && this._lastTouchRect[0] != null && this._lastTouchRect[1] != null &&
this._twoTouchCenter != null && this._twoTouchEvents > this._twoTouchEventThreshold) {

if (!this._dragging && this._pinchingZoomRect[0] != null && this._pinchingZoomRect[1] != null) {
var centerPoint = Vector2d.create(this.renderContext.width / 2, this.renderContext.height / 2);
var delta1 = Vector2d.subtract(newRect[0], this._pinchingZoomRect[0]);
var delta2 = Vector2d.subtract(newRect[1], this._pinchingZoomRect[1]);
var radialDirection1 = Vector2d.subtract(this._pinchingZoomRect[0], centerPoint);
var radialDirection2 = Vector2d.subtract(this._pinchingZoomRect[1], centerPoint);
var delta1 = Vector2d.subtract(newRect[0], this._lastTouchRect[0]);
var delta2 = Vector2d.subtract(newRect[1], this._lastTouchRect[1]);
var radialDirection1 = Vector2d.subtract(this._lastTouchRect[0], this._twoTouchCenter);
var radialDirection2 = Vector2d.subtract(this._lastTouchRect[1], this._twoTouchCenter);
radialDirection1.normalize();
radialDirection2.normalize();
var radialDot1 = delta1.x * radialDirection1.x + delta1.y * radialDirection1.y;
Expand All @@ -1185,17 +1196,17 @@ var WWTControl$ = {
var radialMagnitude = radialComponent1.get_length() + radialComponent2.get_length();
var angularMagnitude = angularComponent1.get_length() + angularComponent2.get_length();

if (radialMagnitude >= 0.5 * angularMagnitude && !this._rotating) {
var oldDist = this.getDistance(this._pinchingZoomRect[0], this._pinchingZoomRect[1]);
if (radialMagnitude > angularMagnitude && !this._rotating) {
var oldDist = this.getDistance(this._lastTouchRect[0], this._lastTouchRect[1]);
var newDist = this.getDistance(newRect[0], newRect[1]);
var ratio = oldDist / newDist;
this.zoom(ratio);
this._zooming = true;
} else if (!this._zooming) {
var oldCenterDelta1 = Vector2d.subtract(this._pinchingZoomRect[0], centerPoint);
var oldCenterDelta2 = Vector2d.subtract(this._pinchingZoomRect[1], centerPoint);
var newCenterDelta1 = Vector2d.subtract(newRect[0], centerPoint);
var newCenterDelta2 = Vector2d.subtract(newRect[1], centerPoint);
} else if (!this._zooming && radialMagnitude > 0) {
var oldCenterDelta1 = Vector2d.subtract(this._lastTouchRect[0], this._twoTouchCenter);
var oldCenterDelta2 = Vector2d.subtract(this._lastTouchRect[1], this._twoTouchCenter);
var newCenterDelta1 = Vector2d.subtract(newRect[0], this._twoTouchCenter);
var newCenterDelta2 = Vector2d.subtract(newRect[1], this._twoTouchCenter);
var cross1 = this.crossProductZ(oldCenterDelta1, newCenterDelta1);
var cross2 = this.crossProductZ(oldCenterDelta2, newCenterDelta2);
var angle1 = Math.asin(cross1 / (oldCenterDelta1.get_length() * newCenterDelta1.get_length()));
Expand All @@ -1210,6 +1221,9 @@ var WWTControl$ = {
this._rotating = true;
}
}
this._twoTouchCenter = Vector2d.create(0.5 * (t0.pageX + t1.pageX), 0.5 * (t0.pageY + t1.pageY));
this._lastTouchRect[0] = newRect[0];
this._lastTouchRect[1] = newRect[1];
}

this._pinchingZoomRect = newRect;
Expand Down Expand Up @@ -1249,6 +1263,10 @@ var WWTControl$ = {
if (this._hasTwoTouches) {
if (ev.touches.length < 2) {
this._hasTwoTouches = false;
this._lastTouchRect[0] = null;
this._lastTouchRect[1] = null;
this._twoTouchCenter = null;
this._twoTouchEvents = 0;
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
"tscheck": "tsc"
},
"types": "./src/index.d.ts",
"version": "7.30.0"
"version": "7.30.1"
}

0 comments on commit f83b1dd

Please sign in to comment.