Merge AccX/AccY in GBHawk controller deck

This commit is contained in:
YoshiRulz 2021-08-18 06:18:55 +10:00 committed by James Groom
parent c09370ab44
commit 9f2e426454
3 changed files with 17 additions and 41 deletions

View File

@ -358,9 +358,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
InputCallbacks.Call();
controller_state = _controllerDeck.ReadPort1(controller);
Acc_X_state = _controllerDeck.ReadAccX1(controller);
Acc_Y_state = _controllerDeck.ReadAccY1(controller);
(Acc_X_state, Acc_Y_state) = _controllerDeck.ReadAcc1(controller);
}
public byte GetButtons(ushort r)

View File

@ -31,15 +31,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
return Port1.Read(c);
}
public ushort ReadAccX1(IController c)
{
return Port1.ReadAccX(c);
}
public ushort ReadAccY1(IController c)
{
return Port1.ReadAccY(c);
}
public (ushort X, ushort Y) ReadAcc1(IController c)
=> Port1.ReadAcc(c);
public ControllerDefinition Definition { get; }

View File

@ -14,9 +14,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
byte Read(IController c);
ushort ReadAccX(IController c);
ushort ReadAccY(IController c);
(ushort X, ushort Y) ReadAcc(IController c);
ControllerDefinition Definition { get; }
@ -84,15 +82,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
return result;
}
public ushort ReadAccX(IController c)
{
return 0;
}
public ushort ReadAccY(IController c)
{
return 0;
}
public (ushort X, ushort Y) ReadAcc(IController c)
=> (0, 0);
private static readonly string[] BaseDefinition =
{
@ -164,9 +155,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
return result;
}
// acc x is the result of rotating around body y AFTER rotating around body x
// therefore this control scheme gives decreasing sensitivity in X as Y rotation inscreases
public ushort ReadAccX(IController c)
public (ushort X, ushort Y) ReadAcc(IController c)
{
theta_prev = theta;
phi_prev_2 = phi_prev;
@ -175,27 +164,23 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
theta = (float)(c.AxisValue(Definition.Axes[1]) * Math.PI / 180.0);
phi = (float)(c.AxisValue(Definition.Axes[0]) * Math.PI / 180.0);
float temp = (float)(Math.Cos(theta) * Math.Sin(phi));
// acc x is the result of rotating around body y AFTER rotating around body x
// therefore this control scheme gives decreasing sensitivity in X as Y rotation increases
var temp = (float) (Math.Cos(theta) * Math.Sin(phi));
// additional acceleration components are dominated by axial components due to off axis rotation.
// They vary widely based on physical hand movements, but this roughly matches what I observe in a real GBP
float temp2 = (float)((phi - 2 * phi_prev + phi_prev_2) * 59.7275 * 59.7275 * 0.1);
return (ushort)(0x8370 - Math.Floor(temp * 216) - temp2);
}
// acc y is just the sine of the angle
// we assume that ReadAccX is called first, which updates the the states
public ushort ReadAccY(IController c)
{
float temp = (float)Math.Sin(theta);
var temp2 = (float) ((phi - 2 * phi_prev + phi_prev_2) * 59.7275 * 59.7275 * 0.1);
var accX = (ushort) (0x8370 - Math.Floor(temp * 216) - temp2);
// acc y is just the sine of the angle
var temp3 = (float) Math.Sin(theta);
// here we add in the acceleration generated by the point of rotation being far away from the accelerometer
// this term dominates other facators due to the cartridge being far from the players hands in whatever system is being used.
// It roughly matches what I observe in a real GBP
float temp2 = (float)(Math.Pow((theta - theta_prev) * 59.7275, 2) * 0.15);
var temp4 = (float) (Math.Pow((theta - theta_prev) * 59.7275, 2) * 0.15);
var accY = (ushort) (0x8370 - Math.Floor(temp3 * 216) + temp4);
return (ushort)(0x8370 - Math.Floor(temp * 216) + temp2);
return (accX, accY);
}
private static readonly string[] BaseDefinition =