Improved XInput controls

This commit is contained in:
dexy 2019-12-11 18:46:36 +11:00
parent 567218d5c7
commit 5672ea6dc3
6 changed files with 65 additions and 112 deletions

View File

@ -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) lock (syncRoot)
{ {
TargetRotation.X += x; TargetRotation.X += x*elapsed;
TargetRotation.Y += y; TargetRotation.Y += y*elapsed;
} }
} }

View File

@ -867,7 +867,7 @@ namespace CodeWalker.Forms
float moveSpeed = 2.0f; float moveSpeed = 2.0f;
Input.Update(elapsed); Input.Update();
if (Input.xbenable) if (Input.xbenable)
{ {
@ -890,6 +890,17 @@ namespace CodeWalker.Forms
Vector3 movevec = Input.KeyboardMoveVec(false); 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) //if (MapViewEnabled == true)
//{ //{
@ -918,7 +929,7 @@ namespace CodeWalker.Forms
if (Input.xbenable) 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 zoom = 0.0f;
float zoomspd = s.XInputZoomSpeed; float zoomspd = s.XInputZoomSpeed;
@ -928,31 +939,6 @@ namespace CodeWalker.Forms
camera.ControllerZoom(zoom); 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);
//}
} }

View File

@ -910,7 +910,7 @@ namespace CodeWalker.Peds
float moveSpeed = 2.0f; float moveSpeed = 2.0f;
Input.Update(elapsed); Input.Update();
if (Input.xbenable) if (Input.xbenable)
{ {
@ -933,6 +933,17 @@ namespace CodeWalker.Peds
Vector3 movevec = Input.KeyboardMoveVec(false); 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) //if (MapViewEnabled == true)
//{ //{
@ -961,7 +972,7 @@ namespace CodeWalker.Peds
if (Input.xbenable) 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 zoom = 0.0f;
float zoomspd = s.XInputZoomSpeed; float zoomspd = s.XInputZoomSpeed;
@ -971,31 +982,6 @@ namespace CodeWalker.Peds
camera.ControllerZoom(zoom); 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);
//}
} }

View File

@ -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; var s = Settings.Default;
@ -103,8 +102,8 @@ namespace CodeWalker
xbry = xbmainaxes.W; xbry = xbmainaxes.W;
xblt = xbtrigs.X; xblt = xbtrigs.X;
xbrt = xbtrigs.Y; xbrt = xbtrigs.Y;
float lamt = s.XInputLThumbSensitivity * elapsed; float lamt = s.XInputLThumbSensitivity;
float ramt = s.XInputRThumbSensitivity * elapsed; float ramt = s.XInputRThumbSensitivity;
xbly = s.XInputLThumbInvert ? xbly : -xbly; xbly = s.XInputLThumbInvert ? xbly : -xbly;
xbry = s.XInputRThumbInvert ? xbry : -xbry; xbry = s.XInputRThumbInvert ? xbry : -xbry;
xblx *= lamt; xblx *= lamt;

View File

@ -721,7 +721,7 @@ namespace CodeWalker.Vehicles
float moveSpeed = 2.0f; float moveSpeed = 2.0f;
Input.Update(elapsed); Input.Update();
if (Input.xbenable) if (Input.xbenable)
{ {
@ -744,6 +744,17 @@ namespace CodeWalker.Vehicles
Vector3 movevec = Input.KeyboardMoveVec(false); 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) //if (MapViewEnabled == true)
//{ //{
@ -772,7 +783,7 @@ namespace CodeWalker.Vehicles
if (Input.xbenable) 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 zoom = 0.0f;
float zoomspd = s.XInputZoomSpeed; float zoomspd = s.XInputZoomSpeed;
@ -782,31 +793,6 @@ namespace CodeWalker.Vehicles
camera.ControllerZoom(zoom); 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);
//}
} }

View File

@ -487,7 +487,7 @@ namespace CodeWalker
float moveSpeed = 50.0f; float moveSpeed = 50.0f;
Input.Update(elapsed); Input.Update();
if (Input.xbenable) if (Input.xbenable)
{ {
@ -511,6 +511,19 @@ namespace CodeWalker
Vector3 movevec = Input.KeyboardMoveVec(MapViewEnabled); 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) if (MapViewEnabled)
{ {
movevec *= elapsed * moveSpeed * Math.Min(camera.OrthographicTargetSize * 0.01f, 50.0f); movevec *= elapsed * moveSpeed * Math.Min(camera.OrthographicTargetSize * 0.01f, 50.0f);
@ -540,40 +553,23 @@ namespace CodeWalker
if (Input.xbenable) 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 zoom = 0.0f;
float zoomspd = s.XInputZoomSpeed; float zoomspd = s.XInputZoomSpeed;
float zoomamt = zoomspd * elapsed; float zoomamt = zoomspd * elapsed;
if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadUp)) zoom += zoomamt; if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadUp)) zoom += zoomamt;
if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadDown)) zoom -= zoomamt; if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadDown)) zoom -= zoomamt;
if (MapViewEnabled) zoom -= zoomamt * Input.xbry;
camera.ControllerZoom(zoom); camera.ControllerZoom(zoom);
float acc = 0.0f; bool fire = (Input.xbtrigs.Y > 0);
float accspd = s.XInputMoveSpeed;//actually accel speed... if (fire && !ControlFireToggle)
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))
{ {
SpawnTestEntity(true); SpawnTestEntity(true);
} }
ControlFireToggle = fire;
} }
@ -609,7 +605,7 @@ namespace CodeWalker
if (Input.xbenable) if (Input.xbenable)
{ {
camera.ControllerRotate(Input.xbrx, Input.xbry); camera.ControllerRotate(Input.xbrx, Input.xbry, elapsed);
} }