diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs index 436aab7c0e..a43eaf7795 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs @@ -120,7 +120,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public int PortNum { get; } - public float theta, phi, theta_prev, phi_prev; + public float theta, phi, theta_prev, phi_prev, phi_prev_2; public ControllerDefinition Definition { get; } @@ -169,6 +169,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public ushort ReadAccX(IController c) { theta_prev = theta; + phi_prev_2 = phi_prev; phi_prev = phi; theta = (float)(c.AxisValue(Definition.Axes[1]) * Math.PI / 180.0); @@ -176,10 +177,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk float temp = (float)(Math.Cos(theta) * Math.Sin(phi)); - // here we add in rates of change parameters. - // a typical rate of change for a fast rotation is guessed at 0.5 rad / frame - // since rotations about X have less of a moment arm compared to by, we take 1/5 of the effect as a baseline - float temp2 = (float)((phi - phi_prev) / 0.5 * 25); + // 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); } @@ -190,10 +191,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { float temp = (float)Math.Sin(theta); - // here we add in rates of change parameters. - // a typical rate of change for a fast rotation is guessed at 0.5 rad / frame - // further it will be assumed that the resulting acceleration is roughly eqvuivalent to gravity - float temp2 = (float)((theta - theta_prev)/0.5 * 125); + // 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); return (ushort)(0x8370 - Math.Floor(temp * 216) + temp2); } @@ -208,6 +209,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // since we need rate of change of angle, need to savestate them ser.Sync(nameof(theta), ref theta); ser.Sync(nameof(phi), ref phi); + ser.Sync(nameof(phi_prev), ref phi_prev); } } } \ No newline at end of file