Skip to content

Commit

Permalink
Motion input (#212)
Browse files Browse the repository at this point in the history
* Remove duplicate ratio usage from joystickcamarea.

* Auto roll yaw swap addition

* Fix activation and QuickTools glyph.
  • Loading branch information
CasperH2O authored Jul 31, 2022
1 parent f3bac9a commit e864312
Show file tree
Hide file tree
Showing 11 changed files with 794 additions and 715 deletions.
3 changes: 2 additions & 1 deletion ControllerCommon/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class Profile
{
{ Input.JoystickCamera, Properties.Resources.JoystickCameraDesc },
{ Input.JoystickSteering, Properties.Resources.JoystickSteeringDesc },
{ Input.PlayerSpace, Properties.Resources.PlayerSpaceDesc }
{ Input.PlayerSpace, Properties.Resources.PlayerSpaceDesc },
{ Input.AutoRollYawSwap, Properties.Resources.AutoRollYawSwapDesc }
};

public string name { get; set; }
Expand Down
478 changes: 242 additions & 236 deletions ControllerCommon/Properties/Resource.zh-CN.resx

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions ControllerCommon/Properties/Resource.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AutoRollYawSwapDesc" xml:space="preserve">
<value>This input will operate as a simple joystick. Ideal for laptop and clamshell type handhelds, automatic yaw roll swap based on how device is being held (90 or 180 degree open).</value>
</data>
<data name="Enum.GamepadButtonFlagsExt.A" xml:space="preserve">
<value>A</value>
</data>
Expand Down Expand Up @@ -183,6 +186,9 @@
<data name="Enum.HIDstatus.Disconnected" xml:space="preserve">
<value>未連接</value>
</data>
<data name="Enum.Input.AutoRollYawSwap" xml:space="preserve">
<value>Auto Roll Yaw Swap</value>
</data>
<data name="Enum.Input.JoystickCamera" xml:space="preserve">
<value>體感視角</value>
</data>
Expand Down
18 changes: 18 additions & 0 deletions ControllerCommon/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

480 changes: 243 additions & 237 deletions ControllerCommon/Properties/Resources.fr.resx

Large diffs are not rendered by default.

478 changes: 242 additions & 236 deletions ControllerCommon/Properties/Resources.resx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ControllerCommon/SensorFusion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ControllerCommon
public class SensorFusion
{
// Gravity Simple
private Vector3 GravityVectorSimple;
public Vector3 GravityVectorSimple;

// Gravity Fancy
private float Shakiness;
Expand Down
30 changes: 28 additions & 2 deletions ControllerCommon/Utils/InputUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public struct SensorSpec
public enum Input
{
PlayerSpace = 0,
JoystickCamera = 1,
JoystickSteering = 2
JoystickCamera = 1,
AutoRollYawSwap = 2,
JoystickSteering = 3,
}

public enum Output
Expand Down Expand Up @@ -248,5 +249,30 @@ public static float ApplyCustomSensitivity(float AngularValue, float MaxValue, L
// Apply direction
return JoystickPosAdjusted;
}

public static Vector2 AutoRollYawSwap(Vector3 Gravity, Vector3 AngularVelocityDeg)
{
// Auto roll yaw swap function allows for clampshell, laptop and controller type devices to
// automatically change the roll and yaw axis depending on how the device is being held. No need for changing settings.

// Depending on how a device is being held, one of the gravity vector values will be near 1 and the others near 0
// multiplying this with the respective desired rotational angle speed vector (roll or yaw) will result in a motion input
// for the horizontal plane.

// Normalize gravity to:
// - Prevent multiplying with values > 1 ie additional user shaking
// - When rolling device and maintaining the roll angle, accelY and accelZare less than horizon angle.
Vector3 GravityNormalized = Vector3.Normalize(new Vector3(Gravity.X, Gravity.Y, Gravity.Z));

// Handle NaN, check for empty inputs, prevent NaN computes
Vector3 EmptyVector = new(0f, 0f, 0f);

if (Gravity.Equals(EmptyVector))
return new Vector2(EmptyVector.X, EmptyVector.Y);

// -acc[1] * gyro[1] + -acc[2] * gyro[2]
return new Vector2(-GravityNormalized.Z * -AngularVelocityDeg.Z + -GravityNormalized.Y * -AngularVelocityDeg.Y,
AngularVelocityDeg.X);
}
}
}
7 changes: 5 additions & 2 deletions ControllerService/Targets/ViGEmTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public virtual unsafe void UpdateReport(Gamepad Gamepad)
{
case Input.PlayerSpace:
case Input.JoystickCamera:
case Input.AutoRollYawSwap:
{
Vector2 Angular;

Expand All @@ -133,10 +134,12 @@ public virtual unsafe void UpdateReport(Gamepad Gamepad)
case Input.PlayerSpace:
Angular = new Vector2((float)xinputController.sensorFusion.CameraYawDelta, (float)xinputController.sensorFusion.CameraPitchDelta);
break;

case Input.AutoRollYawSwap:
Angular = InputUtils.AutoRollYawSwap(xinputController.sensorFusion.GravityVectorSimple, xinputController.AngularVelocities[XInputSensorFlags.Centered]);
break;
default:
case Input.JoystickCamera:
Angular = new Vector2(-xinputController.AngularVelocities[XInputSensorFlags.CenteredRatio].Z, xinputController.AngularVelocities[XInputSensorFlags.CenteredRatio].X);
Angular = new Vector2(-xinputController.AngularVelocities[XInputSensorFlags.Centered].Z, xinputController.AngularVelocities[XInputSensorFlags.Centered].X);
break;
}

Expand Down
4 changes: 4 additions & 0 deletions HandheldCompanion/Views/Pages/ProfilesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public ProfilesPage(string Tag) : this()
case Input.JoystickCamera:
icon.Glyph = "\uE714";
break;
case Input.AutoRollYawSwap:
icon.Glyph = "\uE7F8";
break;
case Input.JoystickSteering:
icon.Glyph = "\uEC47";
break;
Expand Down Expand Up @@ -535,6 +538,7 @@ private void cB_Input_SelectionChanged(object sender, SelectionChangedEventArgs
{
case Input.PlayerSpace:
case Input.JoystickCamera:
case Input.AutoRollYawSwap:
cB_Output.SelectedIndex = (int)Output.RightStick;
break;
case Input.JoystickSteering:
Expand Down
3 changes: 3 additions & 0 deletions HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public QuickProfilesPage()
break;
case Input.JoystickCamera:
icon.Glyph = "\uE714";
break;
case Input.AutoRollYawSwap:
icon.Glyph = "\uE7F8";
break;
case Input.JoystickSteering:
icon.Glyph = "\uEC47";
Expand Down

0 comments on commit e864312

Please sign in to comment.