commit 9e97fa4971e1332e10e03cbca1ef04a29f562611
parent c7d00eea804c56c3599714fe7323e5af3ee375af
Author: anon <anon@example.com>
Date: Tue, 20 Oct 2026 04:31:49 +0000
Add mobile pinch zoom while preserving camera orbit
Diffstat:
5 files changed, 203 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
@@ -34,7 +34,8 @@ Retina uses the screen's pixel density, making the original interface smaller
and sharper as well as increasing rendering resolution.
The menu also provides fullscreen and, on mobile, touch controls and a 1P/3P toggle.
On mobile, Move controls forward/backward and strafing; swipe the world to steer
-and drag with two fingers to orbit. Autorun keeps moving after releasing Move.
+and drag with two fingers to orbit. Spread or pinch those fingers to zoom in or out.
+Autorun keeps moving after releasing Move.
Jump, Attack and Use buttons provide the common keyboard actions; inventory uses
the game's native INV button.
Tap the game to left-click, drag to move windows or items, and hold briefly for
diff --git a/src/browser/index.html b/src/browser/index.html
@@ -82,7 +82,7 @@
<div id="mobile-options" hidden>
<button id="view-button">Toggle 1P / 3P</button>
<label><input id="touch-enabled" type="checkbox"> Touch controls</label>
- <p>Left pad: move. Swipe: steer. Two fingers: orbit. Hold: right click.</p>
+ <p>Left pad: move. Swipe: steer. Two fingers: orbit and pinch to zoom. Hold: right click.</p>
</div>
</dialog>
<script>
@@ -469,7 +469,7 @@ show();
const points = new Map([[canvasTouch.id, first], [event.pointerId, {x: event.clientX, y: event.clientY}]]);
finishCanvasTouch();
canvas.setPointerCapture(event.pointerId);
- orbitTouch = {points};
+ orbitTouch = {points, distance: Math.hypot(first.x - event.clientX, first.y - event.clientY)};
Module._browser_orbit(0, 0, 1);
return;
}
@@ -495,6 +495,15 @@ show();
Math.round((event.clientY - point.y) / bounds.height * 32768 * .35), 1);
point.x = event.clientX;
point.y = event.clientY;
+
+ // Finger separation controls zoom while their midpoint controls orbit.
+ const [first, second] = orbitTouch.points.values();
+ const distance = Math.hypot(first.x - second.x, first.y - second.y);
+ if (orbitTouch.distance > 0 && distance > 0) {
+ const zoom = Math.round(Math.log(orbitTouch.distance / distance) * 65536);
+ if (zoom) Module._browser_zoom(zoom);
+ }
+ orbitTouch.distance = distance;
return;
}
if (!canvasTouch || event.pointerId !== canvasTouch.id) return;
diff --git a/src/runtime/browser_resolution.c b/src/runtime/browser_resolution.c
@@ -12,6 +12,7 @@
static _Atomic uint32_t requested_size;
static _Atomic unsigned chat_viewport_bottom;
static _Atomic int orbit_x, orbit_y, orbit_active;
+static _Atomic int orbit_zoom;
static _Atomic int cursor_hidden;
static _Atomic uint32_t hud_insets;
static _Atomic int chat_scroll_pixels;
@@ -123,10 +124,16 @@ EMSCRIPTEN_KEEPALIVE void browser_orbit(int x, int y, int active)
} else {
atomic_store(&orbit_x, 0);
atomic_store(&orbit_y, 0);
+ atomic_store(&orbit_zoom, 0);
}
atomic_store(&orbit_active, active);
}
+EMSCRIPTEN_KEEPALIVE void browser_zoom(int amount)
+{
+ atomic_fetch_add(&orbit_zoom, amount);
+}
+
static void call_method(uint32_t address, uint32_t object, unsigned count,
const uint32_t *arguments)
{
@@ -143,6 +150,7 @@ static void orbit_frame(void)
int active = atomic_load(&orbit_active);
if (!active && !orbit_running) return;
int x = atomic_exchange(&orbit_x, 0), y = atomic_exchange(&orbit_y, 0);
+ int zoom = atomic_exchange(&orbit_zoom, 0);
uint32_t engine = MEM32(0x2d01752c);
if (!engine) { orbit_running = 0; return; }
@@ -152,6 +160,29 @@ static void orbit_frame(void)
uint32_t arguments[2];
memcpy(arguments, movement, sizeof(arguments));
call_method(0x36020440, engine, 2, arguments);
+
+ /* Scale the current camera offset without rebuilding its orbit direction.
+ * src/game/llr.dll/lifted-0000.c:sub_38002720 limits zoom to 0.7..150. */
+ uint32_t camera = MEM32(engine + 0x80);
+ if (zoom && camera && MEM32(camera + 0x19c)) {
+ uint32_t vehicle = MEM32(camera + 0x60);
+ g_esp -= 12;
+ call_method(0x38001f50, vehicle, 1, (uint32_t[]){g_esp});
+ float offset[3], squared_distance = 0;
+ for (unsigned i = 0; i < 3; ++i) {
+ offset[i] = *(float *)ADDR(vehicle + 0x54 + i * 4) - *(float *)ADDR(g_esp + i * 4);
+ squared_distance += offset[i] * offset[i];
+ }
+ float distance = sqrtf(squared_distance);
+ if (distance > 0) {
+ float scale = fminf(150, fmaxf(0.7f, distance * expf(zoom / 65536.0f))) / distance;
+ for (unsigned i = 0; i < 3; ++i)
+ *(float *)ADDR(g_esp + i * 4) += offset[i] * scale;
+ call_method(MEM32(0x3804e6f4), vehicle, 1, (uint32_t[]){g_esp});
+ call_method(MEM32(MEM32(vehicle) + 0x88), vehicle, 1, (uint32_t[]){1});
+ }
+ g_esp += 12;
+ }
} else {
call_method(0x36020470, engine, 0, NULL);
}
diff --git a/src/tests/browser_controls.mjs b/src/tests/browser_controls.mjs
@@ -6,7 +6,7 @@ import test from 'node:test';
function page({navigator = {userAgent: 'Mozilla/5.0 (Android) Gecko Firefox/149.0'}, saved = null, ready = true} = {}) {
const elements = new Map();
const keys = [], characters = [], mouse = [], orbits = [], sizes = [], chatViewports = [], cursorHidden = [], hudInsets = [];
- const scrolls = [];
+ const scrolls = [], zooms = [];
const timers = new Map();
const storage = new Map(saved === null ? [] : [['ao-touch-controls', saved]]);
const reloads = [];
@@ -76,6 +76,7 @@ function page({navigator = {userAgent: 'Mozilla/5.0 (Android) Gecko Firefox/149.
context.Module._browser_input_motion = (x, y) => mouse.push(['mousemove', x, y, 0]);
context.Module._browser_input_button = (button, down, x, y) => mouse.push([down ? 'mousedown' : 'mouseup', x, y, button === 3 ? 2 : 0]);
context.Module._browser_orbit = (x, y, active) => orbits.push([x, y, active]);
+ context.Module._browser_zoom = amount => zooms.push(amount);
context.Module._browser_hide_cursor = hidden => cursorHidden.push(hidden);
context.Module._browser_hud_insets = (right, top) => hudInsets.push([right, top]);
context.Module._browser_request_resize = (width, height) => sizes.push([width, height]);
@@ -99,7 +100,7 @@ function page({navigator = {userAgent: 'Mozilla/5.0 (Android) Gecko Firefox/149.
document.querySelector(selector).dispatchEvent(event);
return event;
}
- return {document, window, navigator, canvas, audio, keys, characters, mouse, orbits, sizes, chatViewports, cursorHidden, hudInsets, scrolls, storage, actions, fire, reloads,
+ return {document, window, navigator, canvas, audio, keys, characters, mouse, orbits, sizes, chatViewports, cursorHidden, hudInsets, scrolls, zooms, storage, actions, fire, reloads,
firstFrame: () => context.Module.onFirstFrame(),
closed: () => context.Module.onGameClosed(),
graphics: lost => context.Module.onGraphicsStatus(lost),
@@ -443,6 +444,46 @@ test('two world fingers orbit while a third finger keeps moving', () => {
assert.deepEqual(game.keys.at(-1), [119, false]);
});
+test('two world fingers pinch in and out while orbiting, then stop on release', () => {
+ const game = page();
+ game.fire('#canvas', 'pointerdown', {clientX: 300, clientY: 200});
+ game.fire('#canvas', 'pointerdown', {pointerId: 2, clientX: 400, clientY: 200});
+
+ game.fire('#canvas', 'pointermove', {pointerId: 2, clientX: 500, clientY: 200});
+ game.fire('#canvas', 'pointermove', {pointerId: 2, clientX: 400, clientY: 200});
+ game.fire('#canvas', 'pointerup', {pointerId: 2});
+ game.fire('#canvas', 'pointermove', {clientX: 200, clientY: 200});
+ game.fire('#canvas', 'pointerup');
+ game.hold();
+
+ assert.deepEqual(game.zooms, [-45426, 45426]);
+ assert.deepEqual(game.orbits, [[0, 0, 1], [1359, 0, 1], [-1359, 0, 1], [0, 0, 0]]);
+ assert.deepEqual(game.mouse, [['mousemove', 300, 200, 0]]);
+});
+
+test('pinching after cancellation cannot zoom until a new two-finger gesture', () => {
+ const game = page();
+ game.fire('#canvas', 'pointerdown', {clientX: 300, clientY: 200});
+ game.fire('#canvas', 'pointerdown', {pointerId: 2, clientX: 400, clientY: 200});
+
+ game.fire('#canvas', 'pointercancel');
+ game.fire('#canvas', 'pointermove', {pointerId: 2, clientX: 500, clientY: 200});
+
+ assert.deepEqual(game.zooms, []);
+ assert.deepEqual(game.orbits, [[0, 0, 1], [0, 0, 0]]);
+});
+
+test('a two-finger rotation with unchanged separation does not zoom', () => {
+ const game = page();
+ game.fire('#canvas', 'pointerdown', {clientX: 300, clientY: 200});
+ game.fire('#canvas', 'pointerdown', {pointerId: 2, clientX: 400, clientY: 200});
+
+ game.fire('#canvas', 'pointermove', {pointerId: 2, clientX: 300, clientY: 300});
+
+ assert.deepEqual(game.zooms, []);
+ assert.deepEqual(game.orbits, [[0, 0, 1], [-1359, 2941, 1]]);
+});
+
test('adding a second world finger releases steering before starting orbit', () => {
const game = page();
const first = game.fire('#canvas', 'pointerdown');
@@ -556,11 +597,11 @@ test('opening chat or options and losing focus stop autorun', () => {
}
});
-test('desktop browsers cannot activate orbit or autorun', () => {
+test('desktop browsers cannot activate orbit, pinch zoom or autorun', () => {
const game = page({navigator: {userAgent: 'Mozilla/5.0 (X11; Linux x86_64)', maxTouchPoints: 5}});
game.fire('#canvas', 'pointerdown');
- game.fire('#canvas', 'pointerdown', {pointerId: 2});
+ game.fire('#canvas', 'pointerdown', {pointerId: 2, clientX: 300});
game.fire('#canvas', 'pointermove', {clientX: 200});
game.fire('#autorun-button', 'pointerdown');
game.fire('#autorun-button', 'click', {detail: 0});
@@ -568,6 +609,7 @@ test('desktop browsers cannot activate orbit or autorun', () => {
assert.deepEqual(game.keys, []);
assert.deepEqual(game.mouse, []);
assert.deepEqual(game.orbits, []);
+ assert.deepEqual(game.zooms, []);
});
test('blur releases movement and subsequent finger motion cannot restart it', () => {
diff --git a/src/tests/browser_resolution.c b/src/tests/browser_resolution.c
@@ -4,6 +4,7 @@
void browser_request_resize(unsigned width, unsigned height);
void browser_chat_viewport(unsigned bottom);
void browser_orbit(int x, int y, int active);
+void browser_zoom(int amount);
void browser_hud_insets(unsigned right, unsigned top);
void browser_chat_scroll(int pixels);
void browser_resize_frame(void);
@@ -26,6 +27,7 @@ static unsigned touch_count, touch_updates;
static int touch_width, touch_height;
static unsigned orbit_updates, orbit_stops;
static float orbit_x, orbit_y;
+static unsigned camera_repositions, camera_syncs;
static int chat_scrolled;
static unsigned chat_background_width, chat_background_height;
@@ -72,6 +74,33 @@ static void stop_camera(void)
g_esp += 4;
}
+static void get_camera_target(void)
+{
+ assert(g_ecx == 0x50005200);
+ uint32_t target = MEM32(g_esp + 4);
+ memcpy((void *)ADDR(target), (float[]){10, 20, 30}, 12);
+ g_esp += 8;
+}
+
+static void set_camera_position(void)
+{
+ assert(g_ecx == 0x50005200);
+ memcpy((void *)ADDR(g_ecx + 0x54), (void *)ADDR(MEM32(g_esp + 4)), 12);
+ ++camera_repositions;
+ g_esp += 8;
+}
+
+static void synchronize_camera(void)
+{
+ assert(g_ecx == 0x50005200 && MEM32(g_esp + 4) == 1);
+ float x = *(float *)ADDR(g_ecx + 0x54) - 10;
+ float y = *(float *)ADDR(g_ecx + 0x58) - 20;
+ float z = *(float *)ADDR(g_ecx + 0x5c) - 30;
+ *(float *)ADDR(g_ecx + 0x174) = sqrtf(x * x + y * y + z * z);
+ ++camera_syncs;
+ g_esp += 8;
+}
+
static void invalidate_ui(void)
{
assert(g_ecx == 0 && MEM32(0x27048be4) == 0x50003800);
@@ -307,6 +336,9 @@ recomp_func_t recomp_lookup(uint32_t address)
case 0x2b0775b0: return toggle_toolbar;
case 0x36020440: return move_camera;
case 0x36020470: return stop_camera;
+ case 0x38001f50: return get_camera_target;
+ case 8: return set_camera_position;
+ case 0x38004290: return synchronize_camera;
default: abort();
}
}
@@ -748,6 +780,86 @@ int main(void)
browser_resize_frame();
assert(chat_scrolled == -1);
- puts("Browser resize, guest state, mobile chat, and camera orbit checks passed");
+
+ MEM32(0x50003f80) = 0x50005000;
+ MEM32(0x5000519c) = 1;
+ MEM32(0x50005060) = 0x50005200;
+ MEM32(0x50005200) = 0x50005400;
+ MEM32(0x50005488) = 0x38004290;
+ assert(guest_map("camera imports", 0x38040000, 0x10000));
+ MEM32(0x3804e6f4) = 8;
+ *(float *)ADDR(0x50005374) = 10;
+ memcpy((void *)ADDR(0x50005254), (float[]){4, 12, 30}, 12);
+
+ browser_orbit(0, 0, 1);
+ browser_zoom(-32768);
+ browser_zoom(-32768);
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 3.6787944f) < 0.00001f);
+ assert(fabsf(*(float *)ADDR(0x50005254) - 7.792723f) < 0.00001f);
+ assert(fabsf(*(float *)ADDR(0x50005258) - 17.056965f) < 0.00001f);
+ assert(*(float *)ADDR(0x5000525c) == 30);
+ assert(camera_repositions == 1 && camera_syncs == 1);
+ assert(g_esp == stack && g_eax == 101 && g_st[0] == 123.5 && g_flag_cf == 112);
+
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 3.6787944f) < 0.00001f);
+ assert(camera_repositions == 1 && camera_syncs == 1);
+
+ browser_zoom(65536);
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 10) < 0.00001f);
+ assert(fabsf(*(float *)ADDR(0x50005254) - 4) < 0.00001f);
+ assert(fabsf(*(float *)ADDR(0x50005258) - 12) < 0.00001f);
+ assert(*(float *)ADDR(0x5000525c) == 30);
+
+ browser_zoom(655360);
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 150) < 0.0001f);
+ assert(fabsf(*(float *)ADDR(0x50005254) + 80) < 0.0001f);
+ assert(fabsf(*(float *)ADDR(0x50005258) + 100) < 0.0001f);
+
+ browser_zoom(-655360);
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 0.7f) < 0.00001f);
+ assert(fabsf(*(float *)ADDR(0x50005254) - 9.58f) < 0.00001f);
+ assert(fabsf(*(float *)ADDR(0x50005258) - 19.44f) < 0.00001f);
+
+ MEM32(0x5000519c) = 0;
+
+ browser_zoom(65536);
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 0.7f) < 0.00001f);
+
+ MEM32(0x5000519c) = 1;
+
+ browser_zoom(65536);
+ browser_orbit(0, 0, 0);
+ browser_orbit(0, 0, 1);
+ browser_resize_frame();
+ browser_orbit(0, 0, 0);
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 0.7f) < 0.00001f);
+ assert(camera_repositions == 4 && camera_syncs == 4);
+
+ browser_orbit(0, 0, 1);
+ for (unsigned i = 0; i < 8; ++i) {
+ browser_zoom(i % 2 ? -256 : 256);
+ browser_resize_frame();
+ assert(*(float *)ADDR(0x50005254) < 10 && *(float *)ADDR(0x50005258) < 20);
+ }
+ browser_orbit(0, 0, 0);
+ browser_resize_frame();
+
+ assert(fabsf(*(float *)ADDR(0x50005374) - 0.7f) < 0.00001f);
+ assert(*(float *)ADDR(0x5000525c) == 30);
+ puts("Browser resize, guest state, mobile chat, camera orbit and pinch zoom checks passed");
return 0;
}