Saturn - virtualpad support for 3d controller, however, analog stick needs some fixes to support the large analog range of the stick

This commit is contained in:
adelikat 2017-06-11 14:44:15 -05:00
parent edbe83bc13
commit d18a512db8
3 changed files with 116 additions and 3 deletions

View File

@ -84,6 +84,7 @@ namespace BizHawk.Client.EmuHawk
PadBox.Controls.Add(new VirtualPadAnalogStick
{
Name = button.Name,
SecondaryName = button.SecondaryNames.Any() ? button.SecondaryNames[0] : "",
Location = UIHelper.Scale(button.Location),
Size = UIHelper.Scale(new Size(180 + 79, 200 + 9)),
RangeX = new float[] { button.MinValue, button.MidValue, button.MaxValue },

View File

@ -40,12 +40,16 @@ namespace BizHawk.Client.EmuHawk
public float[] RangeX = new float[] { -128f, 0.0f, 127f };
public float[] RangeY = new float[] { -128f, 0.0f, 127f };
public string SecondaryName { get; set; }
private void VirtualPadAnalogStick_Load(object sender, EventArgs e)
{
AnalogStick.Name = Name;
AnalogStick.XName = Name;
AnalogStick.YName = Name.Replace("X", "Y"); // TODO: allow schema to dictate this but this is a convenient default
AnalogStick.YName = !string.IsNullOrEmpty(SecondaryName)
? SecondaryName
: Name.Replace("X", "Y"); // Fallback
AnalogStick.SetRangeX(RangeX);
AnalogStick.SetRangeY(RangeY);
@ -228,7 +232,7 @@ namespace BizHawk.Client.EmuHawk
manualR.ValueChanged -= polarNumericChangedEventHandler;
manualTheta.ValueChanged -= polarNumericChangedEventHandler;
manualR.Value = (decimal)Math.Sqrt(Math.Pow(AnalogStick.X - rangeAverageX, 2) + Math.Pow(AnalogStick.Y - rangeAverageY, 2));
manualR.Value = Math.Min(manualR.Value, (decimal)Math.Sqrt(Math.Pow(AnalogStick.X - rangeAverageX, 2) + Math.Pow(AnalogStick.Y - rangeAverageY, 2)));
manualTheta.Value = (decimal)(Math.Atan2(AnalogStick.Y - rangeAverageY, AnalogStick.X - rangeAverageX) * (180 / Math.PI));
manualR.ValueChanged += polarNumericChangedEventHandler;

View File

@ -49,6 +49,7 @@ namespace BizHawk.Client.EmuHawk
case SaturnusControllerDeck.Device.Gamepad:
return StandardController(controllerNum);
case SaturnusControllerDeck.Device.ThreeDeePad:
return ThreeDeeController(controllerNum);
case SaturnusControllerDeck.Device.Mission:
case SaturnusControllerDeck.Device.DualMission:
case SaturnusControllerDeck.Device.Wheel:
@ -64,7 +65,7 @@ namespace BizHawk.Client.EmuHawk
return new PadSchema
{
IsConsole = false,
DefaultSize = new Size(212, 90),
DefaultSize = new Size(500, 500),
Buttons = new[]
{
new PadSchema.ButtonSchema
@ -166,6 +167,113 @@ namespace BizHawk.Client.EmuHawk
};
}
private static PadSchema ThreeDeeController(int controller)
{
return new PadSchema
{
IsConsole = false,
DefaultSize = new Size(500, 300),
Buttons = new[]
{
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Up",
DisplayName = "",
Icon = Properties.Resources.BlueUp,
Location = new Point(290, 17),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Down",
DisplayName = "",
Icon = Properties.Resources.BlueDown,
Location = new Point(290, 61),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Left",
DisplayName = "",
Icon = Properties.Resources.Back,
Location = new Point(278, 39),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Right",
DisplayName = "",
Icon = Properties.Resources.Forward,
Location = new Point(300, 39),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Start",
DisplayName = "S",
Location = new Point(334, 52),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " A",
DisplayName = "A",
Location = new Point(366, 63),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " B",
DisplayName = "B",
Location = new Point(390, 53),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " C",
DisplayName = "C",
Location = new Point(414, 43),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " X",
DisplayName = "X",
Location = new Point(366, 40),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Y",
DisplayName = "Y",
Location = new Point(390, 30),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = "P" + controller + " Z",
DisplayName = "Z",
Location = new Point(414, 20),
Type = PadSchema.PadInputType.Boolean
},
new PadSchema.ButtonSchema
{
Name = $"P{controller} Stick Horizontal",
SecondaryNames = new[] { $"P{controller} StickVertical" },
MinValue = -32767,
MidValue = 0,
MaxValue = 32767,
MinValueSec = -32767,
MidValueSec = 0,
MaxValueSec = 32767,
DisplayName = "",
Location = new Point(6, 14),
Type = PadSchema.PadInputType.AnalogStick
}
}
};
}
private static PadSchema ConsoleButtons()
{
return new PadSchema