[gpu] Pinch-rotate around pinch center, not screen center

Adds demo_view_rotate_z_around() which compensates translation
so the point between the two fingers stays fixed during rotation,
like maps apps.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.6 committed 2026-03-30 09:40:56 -06:00
1 parent 16c30ac052
commit c1550337db
5 files changed
+38 -5

No files matched your search

+5 -1
View File
@@ -557,7 +557,11 @@ on_touchmove (int type, const EmscriptenTouchEvent *e, void *ud)
if (dAngle > M_PI) dAngle -= 2 * M_PI;
if (dAngle < -M_PI) dAngle += 2 * M_PI;
if (fabs (dAngle) > 0.01)
demo_view_rotate_z (vu, dAngle);
{
double mx = (e->touches[0].targetX + e->touches[1].targetX) / 2.0;
double my = (e->touches[0].targetY + e->touches[1].targetY) / 2.0;
demo_view_rotate_z_around (vu, dAngle, mx, my, css_w, css_h);
}
pinch_dist = dist;
pinch_angle = angle;
}
+2 -2
View File
@@ -121,9 +121,9 @@ web_get_text ()
}
EMSCRIPTEN_KEEPALIVE void
web_rotate_z (float angle)
web_rotate_z (float angle, float cx, float cy, int w, int h)
{
demo_view_rotate_z (vu, angle);
demo_view_rotate_z_around (vu, angle, cx, cy, w, h);
}
} /* extern "C" */
+5 -2
View File
@@ -241,8 +241,11 @@ space: animate · b: dark mode · g: gamma · s: stem · d: debug · r: reset ·
if (dAngle < -Math.PI) dAngle += 2 * Math.PI;
if (Math.abs(dAngle) > 0.01) {
pinchAngle = angle;
if (typeof _web_rotate_z === 'function')
_web_rotate_z(dAngle);
if (typeof _web_rotate_z === 'function') {
var mx = (t[0].clientX + t[1].clientX) / 2;
var my = (t[0].clientY + t[1].clientY) / 2;
_web_rotate_z(dAngle, mx, my, canvas.clientWidth, canvas.clientHeight);
}
}
}
}, {passive: false});