Rotate camera around mouse position#4898
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the “mouse-position oriented camera controls” work (follow-up to #4891) by adding optional camera rotation around the current mouse map position, controlled via a new config setting and exposed through a new packet control flag. It also refactors/cleans up several camera movement/clamping code paths.
Changes:
- Add
ROTATE_AROUND_MOUSEconfig option and propagate it through input → packet flags → camera processing. - Introduce
PCtr_ViewRotatePosand use it to rotate isometric cameras around the packet’s map position. - Refactor camera movement/clamping code in
engine_camera.cand add rotation-pivot state.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/packets.h | Adds PCtr_ViewRotatePos control flag. |
| src/packets.c | Uses PCtr_ViewRotatePos to rotate around packet map coordinates via new camera helper. |
| src/front_input.h | Adds RotateAroundMouseOptions enum + exported setting variable. |
| src/front_input.c | Defaults/bindings update; sets PCtr_ViewRotatePos depending on config + key context. |
| src/engine_camera.h | Extends struct Camera and declares new rotation helper API. |
| src/engine_camera.c | Implements pivot-rotation behavior and refactors camera movement/clamping. |
| src/config_keeperfx.c | Adds ROTATE_AROUND_MOUSE parsing and option recognition table. |
| config/keeperfx.cfg | Documents and sets default for ROTATE_AROUND_MOUSE. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (cam->use_rotation_pivot) | ||
| { | ||
| const MapCoordDelta x0 = cam->mappos.x.val - cam->rotation_pivot.x.val; | ||
| const MapCoordDelta y0 = cam->mappos.y.val - cam->rotation_pivot.y.val; |
There was a problem hiding this comment.
Now I'm just wondering, why Coord3d is signed and Coord2d isn't?
| void view_set_camera_rotation_inertia_around(struct Camera *cam, int32_t delta, int32_t ilimit, MapCoord x, MapCoord y) | ||
| { | ||
| view_set_camera_rotation_inertia(cam, delta, ilimit); | ||
| if ((x | y) < 0) | ||
| return; |
There was a problem hiding this comment.
use_pivot_rotation is disabled when the rotation stops. I think it would be more jarring if the pivot position suddenly were to change while it's still moving.
| long inertia_x; | ||
| TbBool in_active_movement_x; | ||
| long inertia_y; | ||
| TbBool in_active_movement_y; | ||
| TbBool use_rotation_pivot; | ||
| struct Coord2d rotation_pivot; | ||
| }; |
There was a problem hiding this comment.
I hear save files break often here, so that's probably not a concern.
|
Personal verdict: I like this feature, and would like to see it merged. For sensible defaults, I would suggest enabling zoom-to-mouse on the scroll wheel, rotate-around-mouse on dedicated rotate keybinds ( |
|
I added an option to stop the rotation pivot from following the mouse. This is now set by default, as I think it is the least surprising/jarring, especially with tall walls enabled (also default). |
Follow-up to #4891.
I'm posting this here as an experiment. The idea is, this makes the Ctrl+WASD keys all mouse-oriented, and so this should feel more consistent. If that is the case in practice, I'm not yet sure. Most players likely don't rotate the viewport all that often (maybe tall-wall users? I'm not one of them). Anyway, I invite anyone reading this to, uh, "give it a spin".
A new config option is added that enables this feature either for the Ctrl+movement keys, the dedicated rotate keys, both, or neither. For the rotate keys, I propose binding them to the mouse side buttons by default. From some brief testing, I think this feels pretty natural. But, maybe some more important function can be found for these buttons.
I also found some messy-looking code in engine_camera.c. I cleaned it up a bit.