From: rubenwardy <rubenwardy@gmail.com>
Date: Sun, 11 Dec 2016 21:57:43 +0000 (+0000)
Subject: Fix camera jumping on Android when panning past 0/360 mark
X-Git-Tag: 0.4.15~73
X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=refs%2Fpull%2F4893%2Fhead;p=oweals%2Fminetest.git

Fix camera jumping on Android when panning past 0/360 mark
---

diff --git a/src/game.cpp b/src/game.cpp
index ea07accf8..966c23073 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1205,7 +1205,7 @@ static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec,
 		(*cur_formspec)->setFormSource(fs_src);
 		(*cur_formspec)->setTextDest(txt_dest);
 	}
-	
+
 }
 
 #ifdef __ANDROID__
@@ -3362,8 +3362,8 @@ void Game::updateCameraOrientation(CameraOrientation *cam,
 {
 #ifdef HAVE_TOUCHSCREENGUI
 	if (g_touchscreengui) {
-		cam->camera_yaw   = g_touchscreengui->getYaw();
-		cam->camera_pitch = g_touchscreengui->getPitch();
+		cam->camera_yaw   += g_touchscreengui->getYawChange();
+		cam->camera_pitch  = g_touchscreengui->getPitch();
 	} else {
 #endif
 
diff --git a/src/touchscreengui.cpp b/src/touchscreengui.cpp
index f51b2d5fa..e3c6a39a9 100644
--- a/src/touchscreengui.cpp
+++ b/src/touchscreengui.cpp
@@ -414,7 +414,7 @@ void AutoHideButtonBar::show()
 TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver* receiver):
 	m_device(device),
 	m_guienv(device->getGUIEnvironment()),
-	m_camera_yaw(0.0),
+	m_camera_yaw_change(0.0),
 	m_camera_pitch(0.0),
 	m_visible(false),
 	m_move_id(-1),
@@ -835,17 +835,11 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
 
 					/* adapt to similar behaviour as pc screen */
 					double d         = g_settings->getFloat("mouse_sensitivity") *4;
-					double old_yaw   = m_camera_yaw;
+					double old_yaw   = m_camera_yaw_change;
 					double old_pitch = m_camera_pitch;
 
-					m_camera_yaw   -= dx * d;
-					m_camera_pitch  = MYMIN(MYMAX( m_camera_pitch + (dy * d),-180),180);
-
-					while (m_camera_yaw < 0)
-						m_camera_yaw += 360;
-
-					while (m_camera_yaw > 360)
-						m_camera_yaw -= 360;
+					m_camera_yaw_change -= dx * d;
+					m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180);
 
 					// update shootline
 					m_shootline = m_device
diff --git a/src/touchscreengui.h b/src/touchscreengui.h
index d8106a260..b4de1b032 100644
--- a/src/touchscreengui.h
+++ b/src/touchscreengui.h
@@ -147,8 +147,14 @@ public:
 
 	void init(ISimpleTextureSource* tsrc);
 
-	double getYaw() { return m_camera_yaw; }
+	double getYawChange() {
+		double res = m_camera_yaw_change;
+		m_camera_yaw_change = 0;
+		return res;
+	}
+
 	double getPitch() { return m_camera_pitch; }
+
 	line3d<f32> getShootline() { return m_shootline; }
 
 	void step(float dtime);
@@ -170,7 +176,7 @@ private:
 	bool                    m_visible; // is the gui visible
 
 	/* value in degree */
-	double                  m_camera_yaw;
+	double                  m_camera_yaw_change;
 	double                  m_camera_pitch;
 
 	line3d<f32>             m_shootline;