Skip to content

Rotate camera around mouse position#4898

Open
jwt27 wants to merge 10 commits into
dkfans:masterfrom
jwt27:rotate-around-mouse
Open

Rotate camera around mouse position#4898
jwt27 wants to merge 10 commits into
dkfans:masterfrom
jwt27:rotate-around-mouse

Conversation

@jwt27

@jwt27 jwt27 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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.

Comment thread src/engine_camera.c Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_MOUSE config option and propagate it through input → packet flags → camera processing.
  • Introduce PCtr_ViewRotatePos and use it to rotate isometric cameras around the packet’s map position.
  • Refactor camera movement/clamping code in engine_camera.c and 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.

Comment thread src/engine_camera.c
Comment on lines +668 to +671
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;

@jwt27 jwt27 Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm just wondering, why Coord3d is signed and Coord2d isn't?

Comment thread src/engine_camera.c
Comment on lines +354 to +358
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;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/engine_camera.h
Comment on lines 82 to 88
long inertia_x;
TbBool in_active_movement_x;
long inertia_y;
TbBool in_active_movement_y;
TbBool use_rotation_pivot;
struct Coord2d rotation_pivot;
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hear save files break often here, so that's probably not a concern.

@jwt27 jwt27 marked this pull request as draft June 17, 2026 16:33
@jwt27 jwt27 marked this pull request as ready for review June 17, 2026 16:33
@jwt27

jwt27 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

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 (NOT_CTRL), and binding those to the mouse side buttons. That way, mouse controls are mouse-oriented, and keyboard controls (Ctrl+WASD) remain screen-oriented. That seems intuitive to me.

@jwt27 jwt27 marked this pull request as draft June 20, 2026 17:03
@jwt27 jwt27 marked this pull request as ready for review June 20, 2026 17:04
@jwt27

jwt27 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants