Skip to content

Commit 3a0f6c7

Browse files
committed
properly parse the quaternion data from the steam controller
the SC actually sends a quaternion to describe its spacial orientation. Therefore a fourth number has to be read. FYI: the coordinate frame used by the controller has X to the right, y to the front and z pointing upwards
1 parent 240ad8f commit 3a0f6c7

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

include/steam_controller/steam_controller.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ struct vec3
5959
int16_t x, y, z;
6060
};
6161

62+
struct quat
63+
{
64+
int16_t x, y, z, w;
65+
};
66+
6267
enum class event_key : uint32_t
6368
{
6469
UPDATE = (1),
@@ -79,7 +84,7 @@ struct update_event
7984
vec2 left_axis;
8085
vec2 right_axis;
8186

82-
vec3 orientation;
87+
quat orientation;
8388
vec3 acceleration;
8489
vec3 angular_velocity;
8590
};

source/steam_controller.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,10 @@ uint8_t parse_event(steam_controller::event* pEvent, const uint8_t* eventData, i
338338
pEvent->update.angular_velocity.y = eventData[0x24] | (eventData[0x25] << 8);
339339
pEvent->update.angular_velocity.z = eventData[0x26] | (eventData[0x27] << 8);
340340

341-
pEvent->update.orientation.x = eventData[0x28] | (eventData[0x29] << 8);
342-
pEvent->update.orientation.y = eventData[0x2a] | (eventData[0x2b] << 8);
343-
pEvent->update.orientation.z = eventData[0x2c] | (eventData[0x2d] << 8);
341+
pEvent->update.orientation.w = eventData[0x28] | (eventData[0x29] << 8);
342+
pEvent->update.orientation.x = eventData[0x2a] | (eventData[0x2b] << 8);
343+
pEvent->update.orientation.y = eventData[0x2c] | (eventData[0x2d] << 8);
344+
pEvent->update.orientation.z = eventData[0x2e] | (eventData[0x2f] << 8);
344345
break;
345346

346347
case static_cast<std::uint8_t>(event_key::BATTERY):

0 commit comments

Comments
 (0)