mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2025-01-09 23:28:03 +08:00
Improved XInput controls
This commit is contained in:
parent
567218d5c7
commit
5672ea6dc3
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
40
PedsForm.cs
40
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);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
44
WorldForm.cs
44
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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user