From 8798fe3b48cf0ce707262165c3ccf58ea3264dab Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 6 Aug 2020 16:37:24 -0700 Subject: [PATCH] clamp arcball pitch --- KavTest/KavTestGame.cs | 4 ++-- KavTest/Utility/ArcballTransform.cs | 3 ++- KavTest/Utility/MathHelper.cs | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 KavTest/Utility/MathHelper.cs diff --git a/KavTest/KavTestGame.cs b/KavTest/KavTestGame.cs index d6fbb55..a7b8bac 100644 --- a/KavTest/KavTestGame.cs +++ b/KavTest/KavTestGame.cs @@ -83,13 +83,13 @@ namespace KavTest WorldBuilder.SetComponent(cameraEntity, new ArcballTransformComponent( new ArcballTransform( new Vector3(0, 0, -10), - MathHelper.Pi, + Microsoft.Xna.Framework.MathHelper.Pi, 0 ) )); WorldBuilder.SetComponent(cameraEntity, new CameraComponent( Matrix.CreatePerspectiveFieldOfView( - MathHelper.PiOver4, + Microsoft.Xna.Framework.MathHelper.PiOver4, 16f / 9f, 0.1f, 200f diff --git a/KavTest/Utility/ArcballTransform.cs b/KavTest/Utility/ArcballTransform.cs index 866c89a..7979788 100644 --- a/KavTest/Utility/ArcballTransform.cs +++ b/KavTest/Utility/ArcballTransform.cs @@ -25,7 +25,8 @@ namespace KavTest public ArcballTransform RotateLocal(float deltaYaw, float deltaPitch) { - return new ArcballTransform(Position, Yaw + deltaYaw, Pitch + deltaPitch); + var newPitch = MathHelper.Clamp(Pitch + deltaPitch, -Microsoft.Xna.Framework.MathHelper.PiOver2, Microsoft.Xna.Framework.MathHelper.PiOver2); + return new ArcballTransform(Position, Yaw + deltaYaw, newPitch); } public ArcballTransform TranslateLocal(Vector3 localTranslation) diff --git a/KavTest/Utility/MathHelper.cs b/KavTest/Utility/MathHelper.cs new file mode 100644 index 0000000..06b772a --- /dev/null +++ b/KavTest/Utility/MathHelper.cs @@ -0,0 +1,10 @@ +namespace KavTest +{ + public static class MathHelper + { + public static float Clamp(float value, float min, float max) + { + return System.Math.Min(System.Math.Max(value, min), max); + } + } +}