[Patch] Invert mouse in FPS mode

[Patch] Invert mouse in FPS mode

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
TheBlasphemer
Posts: 20
Joined: 31 Jul 2006, 13:13

[Patch] Invert mouse in FPS mode

Post by TheBlasphemer »

Since I'm used to not having my mouse y-axis inverted in an FPS game, I got quite annoyed by Spring doing it. I do understand that some people prefer it that way, but I don't think it's justified forcing it on everyone ;)
That's why I set out to make it an option in the engine :)
This patch creates a new default-on option FPSInvertMouse. If enabled (default), the y-axis will be inverted, like it has always been, when it's disabled, the y-axis will behave like god intended it to!
It also adds the new option to the settings tool...

Anyway, here's the patch:

Code: Select all

Index: rts/Game/CameraController.cpp
===================================================================
--- rts/Game/CameraController.cpp	(revision 1727)
+++ rts/Game/CameraController.cpp	(working copy)
@@ -38,6 +38,7 @@
 {
 	scrollSpeed=configHandler.GetInt("FPSScrollSpeed",10)*0.1;
 	enabled=!!configHandler.GetInt("FPSEnabled",1);
+	m_bMouseInverted=!!configHandler.GetInt("FPSInvertMouse",1);
 }
 
 void CFPSController::KeyMove(float3 move)
@@ -49,7 +50,10 @@
 void CFPSController::MouseMove(float3 move)
 {
 	camera->rot.y -= mouseScale*move.x;
-	camera->rot.x -= mouseScale*move.y*move.z;
+	if (m_bMouseInverted)
+		camera->rot.x += mouseScale*move.y*move.z;
+	else
+		camera->rot.x -= mouseScale*move.y*move.z;
 
 	if(camera->rot.x>PI*0.4999)
 		camera->rot.x=PI*0.4999;
Index: rts/Game/CameraController.h
===================================================================
--- rts/Game/CameraController.h	(revision 1727)
+++ rts/Game/CameraController.h	(working copy)
@@ -45,6 +45,8 @@
 	float oldHeight;
 
 	float3 dir;
+
+	bool m_bMouseInverted;
 };
 
 class COverheadController : public CCameraController
Index: tools/RtsSettings/RtsSettings.rc
===================================================================
--- tools/RtsSettings/RtsSettings.rc	(revision 1727)
+++ tools/RtsSettings/RtsSettings.rc	(working copy)
@@ -146,6 +146,7 @@
                     62,22
     LTEXT           "1",IDC_STATIC,205,159,11,16
     LTEXT           "20",IDC_STATIC,273,159,13,12
+    CONTROL         "Invert mouse in FPS-mode",IDC_InvertMouse,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,296,152,126,16
 END
 
 
Index: tools/RtsSettings/RtsSettingsDlg.cpp
===================================================================
--- tools/RtsSettings/RtsSettingsDlg.cpp	(revision 1727)
+++ tools/RtsSettings/RtsSettingsDlg.cpp	(working copy)
@@ -60,6 +60,7 @@
 	DDX_Control(pDX, IDC_24BITZBUF, zbits24);
 	DDX_Control(pDX, IDC_UnitIconDist, UnitIconDist);
 	DDX_Control(pDX, IDC_MaxTextureStages, Sm3MaxTextureStages);
+	DDX_Control(pDX, IDC_InvertMouse, InvertMouse);
 }
 
 BEGIN_MESSAGE_MAP(CRtsSettingsDlg, CDialog)
@@ -174,6 +175,8 @@
 	else
 		Water0.SetCheck(true);
 
+	InvertMouse.SetCheck(regHandler.GetInt("FPSInvertMouse",1));
+
 	return TRUE;  // return TRUE  unless you set the focus to a control
 }
 
@@ -275,6 +278,9 @@
 	if(Water0.GetCheck())
 		regHandler.SetInt("ReflectiveWater",0);
 
+
+	regHandler.SetInt("FPSInvertMouse",InvertMouse.GetCheck());
+
 	CString s;
 	PlayerName.GetWindowText(s);
 	regHandler.SetString("name",s.GetString());
Index: tools/RtsSettings/RtsSettingsDlg.h
===================================================================
--- tools/RtsSettings/RtsSettingsDlg.h	(revision 1727)
+++ tools/RtsSettings/RtsSettingsDlg.h	(working copy)
@@ -67,6 +67,7 @@
 	CButton Water1;
 	CButton Water2;
 	CSliderCtrl UnitIconDist;
+	CButton InvertMouse;
 
 	CButton zbits16, zbits24;
 
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Post by SinbadEV »

wait a minute... can't you already invert the FPS mouse with the check box in the settings program... I suppose this ONLY inverts the FPS camera mouse and not the rest?
TheBlasphemer
Posts: 20
Joined: 31 Jul 2006, 13:13

Post by TheBlasphemer »

SinbadEV wrote:wait a minute... can't you already invert the FPS mouse with the check box in the settings program... I suppose this ONLY inverts the FPS camera mouse and not the rest?
I couldn't find an invert checkbox in the settings program in the current revision :S
And looking over the FPS-Camera code, it didn't seem like it was there either...

EDIT:
And are you sure the invert mouse checkbox in the settings dialog is there before applying the patch ;)? because the patch also adds it to the settings dialog thingie...
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Post by SinbadEV »

Well... I havn't payed attention to the settings dialog for like 10 versions... I had assumed it was there... I will have to check again.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

It's already there, in the Mouse Input settings dialog box.
TheBlasphemer
Posts: 20
Joined: 31 Jul 2006, 13:13

Post by TheBlasphemer »

jcnossen wrote:It's already there, in the Mouse Input settings dialog box.
Woops!
Completely missed that button!
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Post by SinbadEV »

@TheBlasphemer

I know advice from non-coders is sometimes ill received by coders but... I had a friend who has tried a number of times to create a patch or fix code in the engine and has become frustrated by the "process".

Basically, you want to start by making sure that you are working on something that is wanted, either an accepted bug report or post in the forum to make sure people want the changes made.

When you have made sure it's something that is perceived as needed by the project make sure you put a not onto the forum, mailing list and into the mantis saying that you plan on working on it, that way if anyone is working on it already, or has started and given up, you can work with them to find out what they have learned.

Find the Developers IRC channel, I forget the link but I'll find it when I get home... my wife is away for 2 weeks so I will have a lot of free time to surf the internet for the next little while.
TheBlasphemer
Posts: 20
Joined: 31 Jul 2006, 13:13

Post by TheBlasphemer »

To be honest, at the moment I don't really care about what happens to the code I write ;)
It's a shame if it's already there, or already being worked on, but it's a good exercise to get to know the engine before working on bigger patches :)
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Post by SinbadEV »

TheBlasphemer wrote:To be honest, at the moment I don't really care about what happens to the code I write ;)
It's a shame if it's already there, or already being worked on, but it's a good exercise to get to know the engine before working on bigger patches :)
That is a good point.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Quakenet #SY
Post Reply

Return to “Engine”