From b3da695832342a0bb813f4f379572b11f89fbd00 Mon Sep 17 00:00:00 2001
From: Matthias Betz <matthias.betz@hft-stuttgart.de>
Date: Wed, 18 May 2022 12:39:43 +0200
Subject: [PATCH] fix scrolling invert y rotation

---
 .../de/hft/stuttgart/citygml/viewer/Camera.java    |  6 +++---
 .../stuttgart/citygml/viewer/CityGMLViewer.java    | 14 ++++----------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/main/java/de/hft/stuttgart/citygml/viewer/Camera.java b/src/main/java/de/hft/stuttgart/citygml/viewer/Camera.java
index c8715ec..258d986 100644
--- a/src/main/java/de/hft/stuttgart/citygml/viewer/Camera.java
+++ b/src/main/java/de/hft/stuttgart/citygml/viewer/Camera.java
@@ -71,7 +71,7 @@ public class Camera {
 
 	public void rotate(double dragDiffX, double dragDiffY) {
 		float rotationX = (float) (-dragDiffX / 500f);
-		float rotationZ = (float) (dragDiffY / 500f);
+		float rotationZ = (float) (-dragDiffY / 500f);
 		float tempRotationValue = rotateAroundZ + rotationZ;
 		if (tempRotationValue < -Math.PI / 2 + 0.0001 || tempRotationValue > Math.PI / 2 - 0.0001) {
 			// to close to 90 degree, stop rotation
@@ -94,8 +94,8 @@ public class Camera {
 	public void setDistance(float distance) {
 		this.distance = distance;
 		Vector3f res = new Vector3f();
-		eyePos.sub(centerPos, res);
-		res.normalize().mul(distance);
+		centerPos.sub(eyePos, res);
+		res.normalize().mul(this.distance);
 		centerPos.add(res, eyePos);
 		updateMatrix();
 	}
diff --git a/src/main/java/de/hft/stuttgart/citygml/viewer/CityGMLViewer.java b/src/main/java/de/hft/stuttgart/citygml/viewer/CityGMLViewer.java
index d261c76..5cf6693 100644
--- a/src/main/java/de/hft/stuttgart/citygml/viewer/CityGMLViewer.java
+++ b/src/main/java/de/hft/stuttgart/citygml/viewer/CityGMLViewer.java
@@ -403,7 +403,7 @@ public class CityGMLViewer {
 			double translateZ = -d;
 			camera.setDistance((float) translateZ);
 			cameraViewDistance = (float) longestSide * 20f;
-			camera.rotate(0, -300);
+			camera.rotate(0, 300);
 
 			clearColor = MemoryUtil.memAllocFloat(4);
 			clearColor.put(0, 0.9411765f).put(1, 1f).put(2, 1f).put(3, 1f);
@@ -428,16 +428,10 @@ public class CityGMLViewer {
 		} catch (InterruptedException e) {
 			e.printStackTrace();
 			Thread.currentThread().interrupt();
-		} catch (CityGMLContextException e) {
-			e.printStackTrace();
-		} catch (CityGMLReadException e) {
-			e.printStackTrace();
-		} catch (IOException e) {
-			e.printStackTrace();
-		} catch (ParserConfigurationException e) {
-			e.printStackTrace();
-		} catch (SAXException e) {
+			showErrorDialog(e.getClass().getSimpleName() + ": " + e.getMessage());
+		} catch (CityGMLContextException | CityGMLReadException | IOException | ParserConfigurationException | SAXException e) {
 			e.printStackTrace();
+			showErrorDialog(e.getClass().getSimpleName() + ": " + e.getMessage());
 		} finally {
 			MemoryUtil.memFree(clearColor);
 			MemoryUtil.memFree(clearDepth);
-- 
GitLab