diff --git a/CodeWalker.Core/World/Camera.cs b/CodeWalker.Core/World/Camera.cs index f25b34c..efa716d 100644 --- a/CodeWalker.Core/World/Camera.cs +++ b/CodeWalker.Core/World/Camera.cs @@ -249,12 +249,12 @@ namespace CodeWalker.World } } - public void ControllerRotate(float x, float y) + public void ControllerRotate(float x, float y, float elapsed) { lock (syncRoot) { - TargetRotation.X += x; - TargetRotation.Y += y; + TargetRotation.X += x*elapsed; + TargetRotation.Y += y*elapsed; } } diff --git a/Forms/ModelForm.cs b/Forms/ModelForm.cs index d8b7a24..55357c8 100644 --- a/Forms/ModelForm.cs +++ b/Forms/ModelForm.cs @@ -867,7 +867,7 @@ namespace CodeWalker.Forms float moveSpeed = 2.0f; - Input.Update(elapsed); + Input.Update(); if (Input.xbenable) { @@ -890,6 +890,17 @@ namespace CodeWalker.Forms Vector3 movevec = Input.KeyboardMoveVec(false); + if (Input.xbenable) + { + movevec.X += Input.xblx; + movevec.Z -= Input.xbly; + moveSpeed *= (1.0f + (Math.Min(Math.Max(Input.xblt, 0.0f), 1.0f) * 15.0f)); //boost with left trigger + if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder | GamepadButtonFlags.LeftShoulder)) + { + moveSpeed *= 5.0f; + } + } + //if (MapViewEnabled == true) //{ @@ -918,7 +929,7 @@ namespace CodeWalker.Forms if (Input.xbenable) { - camera.ControllerRotate(Input.xblx + Input.xbrx, Input.xbly + Input.xbry); + camera.ControllerRotate(Input.xbrx, Input.xbry, elapsed); float zoom = 0.0f; float zoomspd = s.XInputZoomSpeed; @@ -928,31 +939,6 @@ namespace CodeWalker.Forms camera.ControllerZoom(zoom); - float acc = 0.0f; - float accspd = s.XInputMoveSpeed;//actually accel speed... - acc += Input.xbrt * accspd; - acc -= Input.xblt * accspd; - - Vector3 newdir = camera.ViewDirection; //maybe use the "vehicle" direction...? - Input.xbcontrolvelocity += (acc * elapsed); - - if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder)) //handbrake... - { - Input.xbcontrolvelocity *= Math.Max(0.75f - elapsed, 0);//not ideal for low fps... - //xbcontrolvelocity = 0.0f; - if (Math.Abs(Input.xbcontrolvelocity) < 0.001f) Input.xbcontrolvelocity = 0.0f; - } - - camEntity.Velocity = newdir * Input.xbcontrolvelocity; - camEntity.Position += camEntity.Velocity * elapsed; - - - //fire! - //if (ControllerButtonJustPressed(GamepadButtonFlags.LeftShoulder)) - //{ - // SpawnTestEntity(true); - //} - } diff --git a/PedsForm.cs b/PedsForm.cs index f7f8b64..255adcf 100644 --- a/PedsForm.cs +++ b/PedsForm.cs @@ -910,7 +910,7 @@ namespace CodeWalker.Peds float moveSpeed = 2.0f; - Input.Update(elapsed); + Input.Update(); if (Input.xbenable) { @@ -933,6 +933,17 @@ namespace CodeWalker.Peds Vector3 movevec = Input.KeyboardMoveVec(false); + if (Input.xbenable) + { + movevec.X += Input.xblx; + movevec.Z -= Input.xbly; + moveSpeed *= (1.0f + (Math.Min(Math.Max(Input.xblt, 0.0f), 1.0f) * 15.0f)); //boost with left trigger + if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder | GamepadButtonFlags.LeftShoulder)) + { + moveSpeed *= 5.0f; + } + } + //if (MapViewEnabled == true) //{ @@ -961,7 +972,7 @@ namespace CodeWalker.Peds if (Input.xbenable) { - camera.ControllerRotate(Input.xblx + Input.xbrx, Input.xbly + Input.xbry); + camera.ControllerRotate(Input.xbrx, Input.xbry, elapsed); float zoom = 0.0f; float zoomspd = s.XInputZoomSpeed; @@ -971,31 +982,6 @@ namespace CodeWalker.Peds camera.ControllerZoom(zoom); - float acc = 0.0f; - float accspd = s.XInputMoveSpeed;//actually accel speed... - acc += Input.xbrt * accspd; - acc -= Input.xblt * accspd; - - Vector3 newdir = camera.ViewDirection; //maybe use the "vehicle" direction...? - Input.xbcontrolvelocity += (acc * elapsed); - - if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder)) //handbrake... - { - Input.xbcontrolvelocity *= Math.Max(0.75f - elapsed, 0);//not ideal for low fps... - //xbcontrolvelocity = 0.0f; - if (Math.Abs(Input.xbcontrolvelocity) < 0.001f) Input.xbcontrolvelocity = 0.0f; - } - - camEntity.Velocity = newdir * Input.xbcontrolvelocity; - camEntity.Position += camEntity.Velocity * elapsed; - - - //fire! - //if (ControllerButtonJustPressed(GamepadButtonFlags.LeftShoulder)) - //{ - // SpawnTestEntity(true); - //} - } diff --git a/Utils/InputUtils.cs b/Utils/InputUtils.cs index 118aa65..8b7b570 100644 --- a/Utils/InputUtils.cs +++ b/Utils/InputUtils.cs @@ -80,9 +80,8 @@ namespace CodeWalker - public void Update(float elapsed) + public void Update() { - if (elapsed > 0.1f) elapsed = 0.1f; var s = Settings.Default; @@ -103,8 +102,8 @@ namespace CodeWalker xbry = xbmainaxes.W; xblt = xbtrigs.X; xbrt = xbtrigs.Y; - float lamt = s.XInputLThumbSensitivity * elapsed; - float ramt = s.XInputRThumbSensitivity * elapsed; + float lamt = s.XInputLThumbSensitivity; + float ramt = s.XInputRThumbSensitivity; xbly = s.XInputLThumbInvert ? xbly : -xbly; xbry = s.XInputRThumbInvert ? xbry : -xbry; xblx *= lamt; diff --git a/VehicleForm.cs b/VehicleForm.cs index 66545d9..cf5e608 100644 --- a/VehicleForm.cs +++ b/VehicleForm.cs @@ -721,7 +721,7 @@ namespace CodeWalker.Vehicles float moveSpeed = 2.0f; - Input.Update(elapsed); + Input.Update(); if (Input.xbenable) { @@ -744,6 +744,17 @@ namespace CodeWalker.Vehicles Vector3 movevec = Input.KeyboardMoveVec(false); + if (Input.xbenable) + { + movevec.X += Input.xblx; + movevec.Z -= Input.xbly; + moveSpeed *= (1.0f + (Math.Min(Math.Max(Input.xblt, 0.0f), 1.0f) * 15.0f)); //boost with left trigger + if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder | GamepadButtonFlags.LeftShoulder)) + { + moveSpeed *= 5.0f; + } + } + //if (MapViewEnabled == true) //{ @@ -772,7 +783,7 @@ namespace CodeWalker.Vehicles if (Input.xbenable) { - camera.ControllerRotate(Input.xblx + Input.xbrx, Input.xbly + Input.xbry); + camera.ControllerRotate(Input.xbrx, Input.xbry, elapsed); float zoom = 0.0f; float zoomspd = s.XInputZoomSpeed; @@ -782,31 +793,6 @@ namespace CodeWalker.Vehicles camera.ControllerZoom(zoom); - float acc = 0.0f; - float accspd = s.XInputMoveSpeed;//actually accel speed... - acc += Input.xbrt * accspd; - acc -= Input.xblt * accspd; - - Vector3 newdir = camera.ViewDirection; //maybe use the "vehicle" direction...? - Input.xbcontrolvelocity += (acc * elapsed); - - if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder)) //handbrake... - { - Input.xbcontrolvelocity *= Math.Max(0.75f - elapsed, 0);//not ideal for low fps... - //xbcontrolvelocity = 0.0f; - if (Math.Abs(Input.xbcontrolvelocity) < 0.001f) Input.xbcontrolvelocity = 0.0f; - } - - camEntity.Velocity = newdir * Input.xbcontrolvelocity; - camEntity.Position += camEntity.Velocity * elapsed; - - - //fire! - //if (ControllerButtonJustPressed(GamepadButtonFlags.LeftShoulder)) - //{ - // SpawnTestEntity(true); - //} - } diff --git a/WorldForm.cs b/WorldForm.cs index d85039c..dcce853 100644 --- a/WorldForm.cs +++ b/WorldForm.cs @@ -487,7 +487,7 @@ namespace CodeWalker float moveSpeed = 50.0f; - Input.Update(elapsed); + Input.Update(); if (Input.xbenable) { @@ -511,6 +511,19 @@ namespace CodeWalker Vector3 movevec = Input.KeyboardMoveVec(MapViewEnabled); + if (Input.xbenable) + { + movevec.X += Input.xblx; + if (MapViewEnabled) movevec.Y += Input.xbly; + else movevec.Z -= Input.xbly; + moveSpeed *= (1.0f + (Math.Min(Math.Max(Input.xblt, 0.0f), 1.0f) * 15.0f)); //boost with left trigger + if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder | GamepadButtonFlags.LeftShoulder)) + { + moveSpeed *= 5.0f; + } + } + + if (MapViewEnabled) { movevec *= elapsed * moveSpeed * Math.Min(camera.OrthographicTargetSize * 0.01f, 50.0f); @@ -540,40 +553,23 @@ namespace CodeWalker if (Input.xbenable) { - camera.ControllerRotate(Input.xblx + Input.xbrx, Input.xbly + Input.xbry); + camera.ControllerRotate(Input.xbrx, Input.xbry, elapsed); float zoom = 0.0f; float zoomspd = s.XInputZoomSpeed; float zoomamt = zoomspd * elapsed; if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadUp)) zoom += zoomamt; if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadDown)) zoom -= zoomamt; + if (MapViewEnabled) zoom -= zoomamt * Input.xbry; camera.ControllerZoom(zoom); - float acc = 0.0f; - float accspd = s.XInputMoveSpeed;//actually accel speed... - acc += Input.xbrt * accspd; - acc -= Input.xblt * accspd; - - Vector3 newdir = camera.ViewDirection; //maybe use the "vehicle" direction...? - Input.xbcontrolvelocity += (acc * elapsed); - - if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder)) //handbrake... - { - Input.xbcontrolvelocity *= Math.Max(0.75f - elapsed, 0);//not ideal for low fps... - //Input.xbcontrolvelocity = 0.0f; - if (Math.Abs(Input.xbcontrolvelocity) < 0.001f) Input.xbcontrolvelocity = 0.0f; - } - - camEntity.Velocity = newdir * Input.xbcontrolvelocity; - camEntity.Position += camEntity.Velocity * elapsed; - - - //fire! - if (Input.ControllerButtonJustPressed(GamepadButtonFlags.LeftShoulder)) + bool fire = (Input.xbtrigs.Y > 0); + if (fire && !ControlFireToggle) { SpawnTestEntity(true); } + ControlFireToggle = fire; } @@ -609,7 +605,7 @@ namespace CodeWalker if (Input.xbenable) { - camera.ControllerRotate(Input.xbrx, Input.xbry); + camera.ControllerRotate(Input.xbrx, Input.xbry, elapsed); }