1
0
forked from mirrors/0ad

Add camera pan inversion option

Fixes: #6539
This commit is contained in:
drh
2024-12-16 22:08:20 +00:00
committed by Ralph Sennhauser
parent 7d4a6c5d07
commit 03ceb27e90
5 changed files with 40 additions and 4 deletions
+1
View File
@@ -598,6 +598,7 @@ rotate.y.speed.wheel = 0.45
rotate.y.default = 0.0
rotate.speed.modifier = 1.05 ; Multiplier for changing rotation speed
drag.speed = 0.5
drag.inverted = false ; Pan in the opposite direction of drag movement
zoom.speed = 256.0
zoom.speed.wheel = 32.0
zoom.min = 50.0
@@ -83,6 +83,7 @@
{ "nick": "DigitalSeraphim", "name": "Nick Owens" },
{ "nick": "dp304" },
{ "nick": "dpiquet", "name": "Damien Piquet" },
{ "nick": "drh", "name": "David Haynes" },
{ "nick": "dumbo" },
{ "nick": "Dunedan", "name": "Daniel Roschka" },
{ "nick": "dvangennip", "name": "Doménique" },
@@ -149,6 +149,20 @@
"min": "1",
"max": "200"
},
{
"type": "boolean",
"label": "Mouse pan inverted",
"tooltip": "Invert middle-click drag pan direction.",
"config": "view.drag.inverted"
},
{
"type": "slider",
"label": "Mouse pan speed",
"tooltip": "Speed mouse pans the map when holding middle-click and dragging.",
"config": "view.drag.speed",
"min": 0.01,
"max": 0.6
},
{
"type": "boolean",
"label": "Mouse grab in fullscreen",
+18 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2024 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -68,6 +68,7 @@ CCameraController::CCameraController(CCamera& camera)
m_ViewRotateYDefault(0),
m_ViewRotateSpeedModifier(1),
m_ViewDragSpeed(0),
m_ViewDragInverted(false),
m_ViewZoomSpeed(0),
m_ViewZoomSpeedWheel(0),
m_ViewZoomMin(0),
@@ -87,6 +88,13 @@ CCameraController::CCameraController(CCamera& camera)
m_RotateX(0, 0, 0.001f),
m_RotateY(0, 0, 0.001f)
{
m_ViewDragInvertedConfigHook = std::make_unique<CConfigDBHook>(g_ConfigDB.RegisterHookAndCall("view.drag.inverted", [this]() {
CFG_GET_VAL("view.drag.inverted", m_ViewDragInverted);
}));
m_ViewDragSpeedConfigHook = std::make_unique<CConfigDBHook>(g_ConfigDB.RegisterHookAndCall("view.drag.speed", [this]() {
CFG_GET_VAL("view.drag.speed", m_ViewDragSpeed);
}));
SViewPort vp;
vp.m_X = 0;
vp.m_Y = 0;
@@ -115,6 +123,7 @@ void CCameraController::LoadConfig()
CFG_GET_VAL("view.rotate.y.default", m_ViewRotateYDefault);
CFG_GET_VAL("view.rotate.speed.modifier", m_ViewRotateSpeedModifier);
CFG_GET_VAL("view.drag.speed", m_ViewDragSpeed);
CFG_GET_VAL("view.drag.inverted", m_ViewDragInverted);
CFG_GET_VAL("view.zoom.speed", m_ViewZoomSpeed);
CFG_GET_VAL("view.zoom.speed.wheel", m_ViewZoomSpeedWheel);
CFG_GET_VAL("view.zoom.min", m_ViewZoomMin);
@@ -180,8 +189,14 @@ void CCameraController::Update(const float deltaRealTime)
if (HotkeyIsPressed("camera.pan"))
{
moveRightward += m_ViewDragSpeed * mouse_dx;
moveForward += m_ViewDragSpeed * -mouse_dy;
if (m_ViewDragInverted) {
moveRightward += m_ViewDragSpeed * -mouse_dx;
moveForward += m_ViewDragSpeed * mouse_dy;
}
else {
moveRightward += m_ViewDragSpeed * mouse_dx;
moveForward += m_ViewDragSpeed * -mouse_dy;
}
}
if (g_mouse_active && m_ViewScrollMouseDetectDistance > 0)
+6 -1
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -20,6 +20,7 @@
#include "graphics/ICameraController.h"
#include "graphics/SmoothedValue.h"
#include "ps/ConfigDB.h"
class CCameraController : public ICameraController
{
@@ -99,6 +100,7 @@ private:
float m_ViewRotateYDefault;
float m_ViewRotateSpeedModifier;
float m_ViewDragSpeed;
bool m_ViewDragInverted;
float m_ViewZoomSpeed;
float m_ViewZoomSpeedWheel;
float m_ViewZoomMin;
@@ -118,6 +120,9 @@ private:
CSmoothedValue m_Zoom;
CSmoothedValue m_RotateX; // inclination around x axis (relative to camera)
CSmoothedValue m_RotateY; // rotation around y (vertical) axis
std::unique_ptr<CConfigDBHook> m_ViewDragInvertedConfigHook;
std::unique_ptr<CConfigDBHook> m_ViewDragSpeedConfigHook;
};
#endif // INCLUDED_CAMERACONTROLLER