clamp arcball pitch

pull/1/head
cosmonaut 2020-08-06 16:37:24 -07:00
parent 2e3a331d13
commit 8798fe3b48
3 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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);
}
}
}