Skip to content

Commit 97b8b4d

Browse files
author
schm1dtmac
authored
Merge branch 'master' into patch-1
2 parents 24cfe8f + 8dbe887 commit 97b8b4d

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

rpcs3/Emu/Cell/Modules/cellGem.cpp

+31-8
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ struct gem_config_data
232232
u8 rumble = 0; // Rumble intensity
233233
gem_color sphere_rgb = {}; // RGB color of the sphere LED
234234
u32 hue = 0; // Tracking hue of the motion controller
235-
f32 distance_mm{1500.0f}; // Distance from the camera in mm
236-
f32 radius{10.0f}; // Radius of the sphere in camera pixels
235+
f32 distance_mm{3000.0f}; // Distance from the camera in mm
236+
f32 radius{5.0f}; // Radius of the sphere in camera pixels
237237
bool radius_valid = true; // If the radius and distance of the sphere was computed.
238238

239239
bool is_calibrating{false}; // Whether or not we are currently calibrating
@@ -919,9 +919,13 @@ static inline void pos_to_gem_state(u32 gem_num, gem_config::gem_controller& con
919919
const f32 image_x = static_cast<f32>(x_pos) / scaling_width;
920920
const f32 image_y = static_cast<f32>(y_pos) / scaling_height;
921921

922+
// Half of the camera image
923+
const f32 half_width = shared_data.width / 2.f;
924+
const f32 half_height = shared_data.height / 2.f;
925+
922926
// Centered image coordinates in pixels
923-
const f32 centered_x = image_x - (shared_data.width / 2.f);
924-
const f32 centered_y = (shared_data.height / 2.f) - image_y; // Image coordinates increase downwards, so we have to invert this
927+
const f32 centered_x = image_x - half_width;
928+
const f32 centered_y = half_height - image_y; // Image coordinates increase downwards, so we have to invert this
925929

926930
// Camera coordinates in mm (centered, so it's the same as world coordinates)
927931
const f32 camera_x = centered_x * mmPerPixel;
@@ -949,10 +953,29 @@ static inline void pos_to_gem_state(u32 gem_num, gem_config::gem_controller& con
949953
}
950954
else
951955
{
952-
gem_state->quat[0] = 320.f - image_x;
953-
gem_state->quat[1] = (y_pos / scaling_width) - 180.f;
954-
gem_state->quat[2] = 1200.f;
955-
gem_state->quat[3] = 1.f;
956+
static constexpr f32 PI = 3.14159265f;
957+
const auto degree_to_rad = [](f32 degree) -> f32 { return degree * PI / 180.0f; };
958+
959+
static constexpr f32 CONE = 10.0f / 2.0f;
960+
const f32 roll = -degree_to_rad((image_y - half_height) / half_height * CONE); // This is actually the pitch
961+
const f32 pitch = -degree_to_rad((image_x - half_width) / half_width * CONE); // This is actually the yaw
962+
const f32 yaw = degree_to_rad(0.0f);
963+
const f32 cr = std::cos(roll * 0.5f);
964+
const f32 sr = std::sin(roll * 0.5f);
965+
const f32 cp = std::cos(pitch * 0.5f);
966+
const f32 sp = std::sin(pitch * 0.5f);
967+
const f32 cy = std::cos(yaw * 0.5f);
968+
const f32 sy = std::sin(yaw * 0.5f);
969+
970+
const f32 q_x = sr * cp * cy - cr * sp * sy;
971+
const f32 q_y = cr * sp * cy + sr * cp * sy;
972+
const f32 q_z = cr * cp * sy - sr * sp * cy;
973+
const f32 q_w = cr * cp * cy + sr * sp * sy;
974+
975+
gem_state->quat[0] = q_x;
976+
gem_state->quat[1] = q_y;
977+
gem_state->quat[2] = q_z;
978+
gem_state->quat[3] = q_w;
956979
}
957980

958981
if (g_cfg.io.show_move_cursor)

rpcs3/Input/ps_move_calibration.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -49,82 +49,86 @@ static void psmove_dump_calibration(const reports::ps_move_calibration_blob& cal
4949

5050
const u8* data = calibration.data.data();
5151

52+
std::string msg;
53+
5254
switch (device.model)
5355
{
5456
case ps_move_model::ZCM1:
5557
t = psmove_calibration_decode_12bits(data, 0x02);
56-
move_log.error("Temperature: 0x%04X", t);
58+
fmt::append(msg, "Temperature: 0x%04X\n", t);
5759
for (int orientation = 0; orientation < 6; orientation++)
5860
{
5961
x = psmove_calibration_decode_16bit_unsigned(data, 0x04 + 6 * orientation);
6062
y = psmove_calibration_decode_16bit_unsigned(data, 0x04 + 6 * orientation + 2);
6163
z = psmove_calibration_decode_16bit_unsigned(data, 0x04 + 6 * orientation + 4);
62-
move_log.error("Orientation #%d: (%5d | %5d | %5d)", orientation, x, y, z);
64+
fmt::append(msg, "Orientation #%d: (%5d | %5d | %5d)\n", orientation, x, y, z);
6365
}
6466

6567
t = psmove_calibration_decode_12bits(data, 0x42);
66-
move_log.error("Temperature: 0x%04X", t);
68+
fmt::append(msg, "Temperature: 0x%04X\n", t);
6769
for (int orientation = 0; orientation < 3; orientation++)
6870
{
6971
x = psmove_calibration_decode_16bit_unsigned(data, 0x46 + 8 * orientation);
7072
y = psmove_calibration_decode_16bit_unsigned(data, 0x46 + 8 * orientation + 2);
7173
z = psmove_calibration_decode_16bit_unsigned(data, 0x46 + 8 * orientation + 4);
72-
move_log.error("Gyro %c, 80 rpm: (%5d | %5d | %5d)", "XYZ"[orientation], x, y, z);
74+
fmt::append(msg, "Gyro %c, 80 rpm: (%5d | %5d | %5d)\n", "XYZ"[orientation], x, y, z);
7375
}
7476

7577
t = psmove_calibration_decode_12bits(data, 0x28);
7678
x = psmove_calibration_decode_16bit_unsigned(data, 0x2a);
7779
y = psmove_calibration_decode_16bit_unsigned(data, 0x2a + 2);
7880
z = psmove_calibration_decode_16bit_unsigned(data, 0x2a + 4);
79-
move_log.error("Temperature: 0x%04X", t);
80-
move_log.error("Gyro, 0 rpm (@0x2a): (%5d | %5d | %5d)", x, y, z);
81+
fmt::append(msg, "Temperature: 0x%04X\n", t);
82+
fmt::append(msg, "Gyro, 0 rpm (@0x2a): (%5d | %5d | %5d)\n", x, y, z);
8183

8284
t = psmove_calibration_decode_12bits(data, 0x30);
8385
x = psmove_calibration_decode_16bit_unsigned(data, 0x32);
8486
y = psmove_calibration_decode_16bit_unsigned(data, 0x32 + 2);
8587
z = psmove_calibration_decode_16bit_unsigned(data, 0x32 + 4);
86-
move_log.error("Temperature: 0x%04X", t);
87-
move_log.error("Gyro, 0 rpm (@0x32): (%5d | %5d | %5d)", x, y, z);
88+
fmt::append(msg, "Temperature: 0x%04X\n", t);
89+
fmt::append(msg, "Gyro, 0 rpm (@0x32): (%5d | %5d | %5d)\n", x, y, z);
8890

8991
t = psmove_calibration_decode_12bits(data, 0x5c);
9092
fx = psmove_calibration_decode_float(data, 0x5e);
9193
fy = psmove_calibration_decode_float(data, 0x5e + 4);
9294
fz = psmove_calibration_decode_float(data, 0x5e + 8);
93-
move_log.error("Temperature: 0x%04X", t);
94-
move_log.error("Vector @0x5e: (%f | %f | %f)", fx, fy, fz);
95+
fmt::append(msg, "Temperature: 0x%04X\n", t);
96+
fmt::append(msg, "Vector @0x5e: (%f | %f | %f)\n", fx, fy, fz);
9597

9698
fx = psmove_calibration_decode_float(data, 0x6a);
9799
fy = psmove_calibration_decode_float(data, 0x6a + 4);
98100
fz = psmove_calibration_decode_float(data, 0x6a + 8);
99-
move_log.error("Vector @0x6a: (%f | %f | %f)", fx, fy, fz);
101+
fmt::append(msg, "Vector @0x6a: (%f | %f | %f)\n", fx, fy, fz);
100102

101-
move_log.error("byte @0x3f: 0x%02x", static_cast<u8>(data[0x3f]));
102-
move_log.error("float @0x76: %f", psmove_calibration_decode_float(data, 0x76));
103-
move_log.error("float @0x7a: %f", psmove_calibration_decode_float(data, 0x7a));
103+
fmt::append(msg, "byte @0x3f: 0x%02x\n", static_cast<u8>(data[0x3f]));
104+
fmt::append(msg, "float @0x76: %f\n", psmove_calibration_decode_float(data, 0x76));
105+
fmt::append(msg, "float @0x7a: %f\n", psmove_calibration_decode_float(data, 0x7a));
104106
break;
105107
case ps_move_model::ZCM2:
106108
for (int orientation = 0; orientation < 6; orientation++)
107109
{
108110
x = psmove_calibration_decode_16bit_signed(data, 0x04 + 6 * orientation);
109111
y = psmove_calibration_decode_16bit_signed(data, 0x04 + 6 * orientation + 2);
110112
z = psmove_calibration_decode_16bit_signed(data, 0x04 + 6 * orientation + 4);
111-
move_log.error("Orientation #%d: (%5d | %5d | %5d)", orientation, x, y, z);
113+
fmt::append(msg, "Orientation #%d: (%5d | %5d | %5d)\n", orientation, x, y, z);
112114
}
113115

114116
x = psmove_calibration_decode_16bit_signed(data, 0x26);
115117
y = psmove_calibration_decode_16bit_signed(data, 0x26 + 2);
116118
z = psmove_calibration_decode_16bit_signed(data, 0x26 + 4);
117-
move_log.error("Gyro Bias?, 0 rpm (@0x26): (%5d | %5d | %5d)", x, y, z);
119+
fmt::append(msg, "Gyro Bias?, 0 rpm (@0x26): (%5d | %5d | %5d)\n", x, y, z);
118120

119121
for (int orientation = 0; orientation < 6; orientation++)
120122
{
121123
x = psmove_calibration_decode_16bit_signed(data, 0x30 + 6 * orientation);
122124
y = psmove_calibration_decode_16bit_signed(data, 0x30 + 6 * orientation + 2);
123125
z = psmove_calibration_decode_16bit_signed(data, 0x30 + 6 * orientation + 4);
124-
move_log.error("Gyro %c, 90 rpm: (%5d | %5d | %5d)", "XYZXYZ"[orientation], x, y, z);
126+
fmt::append(msg, "Gyro %c, 90 rpm: (%5d | %5d | %5d)\n", "XYZXYZ"[orientation], x, y, z);
125127
}
126128
break;
127129
}
130+
131+
move_log.notice("Calibration:\n%s", msg);
128132
}
129133

130134
void psmove_calibration_get_usb_accel_values(const reports::ps_move_calibration_blob& calibration, ps_move_device& device)

rpcs3/Input/ps_move_handler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ void ps_move_handler::check_add_device(hid_device* hidDevice, std::string_view p
362362
// Initialize Fusion
363363
FusionAhrsInitialise(&device->ahrs);
364364
device->ahrs.settings.convention = FusionConvention::FusionConventionEnu;
365+
device->ahrs.settings.gain = 0.0f; // If gain is set, the algorithm tries to adjust the orientation over time.
365366
FusionAhrsSetSettings(&device->ahrs, &device->ahrs.settings);
366367
FusionAhrsReset(&device->ahrs);
367368

0 commit comments

Comments
 (0)