@@ -117,17 +117,17 @@ bool HandTracker::Impl::update(XrTime time)
117117 return left_ok || right_ok;
118118}
119119
120- const HandData & HandTracker::Impl::get_left_hand () const
120+ const HandPoseT & HandTracker::Impl::get_left_hand () const
121121{
122122 return left_hand_;
123123}
124124
125- const HandData & HandTracker::Impl::get_right_hand () const
125+ const HandPoseT & HandTracker::Impl::get_right_hand () const
126126{
127127 return right_hand_;
128128}
129129
130- bool HandTracker::Impl::update_hand (XrHandTrackerEXT tracker, XrTime time, HandData & out_data)
130+ bool HandTracker::Impl::update_hand (XrHandTrackerEXT tracker, XrTime time, HandPoseT & out_data)
131131{
132132 XrHandJointsLocateInfoEXT locate_info{ XR_TYPE_HAND_JOINTS_LOCATE_INFO_EXT };
133133 locate_info.baseSpace = base_space_;
@@ -150,23 +150,37 @@ bool HandTracker::Impl::update_hand(XrHandTrackerEXT tracker, XrTime time, HandD
150150 out_data.is_active = locations.isActive ;
151151 out_data.timestamp = time;
152152
153- for (uint32_t i = 0 ; i < 26 ; ++i)
153+ // Ensure joints struct is allocated
154+ if (!out_data.joints )
154155 {
155- const auto & joint_loc = joint_locations[i] ;
156- auto & joint_data = out_data. joints [i];
156+ out_data. joints = std::make_unique<HandJoints>() ;
157+ }
157158
158- joint_data.position [0 ] = joint_loc.pose .position .x ;
159- joint_data.position [1 ] = joint_loc.pose .position .y ;
160- joint_data.position [2 ] = joint_loc.pose .position .z ;
159+ // Get mutable access to the joints array
160+ auto * mutable_array = const_cast <flatbuffers::Array<HandJointPose, 26 >*>(out_data.joints ->poses ());
161161
162- joint_data.orientation [0 ] = joint_loc.pose .orientation .x ;
163- joint_data.orientation [1 ] = joint_loc.pose .orientation .y ;
164- joint_data.orientation [2 ] = joint_loc.pose .orientation .z ;
165- joint_data.orientation [3 ] = joint_loc.pose .orientation .w ;
162+ for (uint32_t i = 0 ; i < 26 ; ++i)
163+ {
164+ const auto & joint_loc = joint_locations[i];
166165
167- joint_data.radius = joint_loc.radius ;
168- joint_data.is_valid = (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) &&
169- (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT);
166+ // Create Pose from position and orientation using FlatBuffers structs
167+ Point position (
168+ joint_loc.pose .position .x ,
169+ joint_loc.pose .position .y ,
170+ joint_loc.pose .position .z );
171+ Quaternion orientation (
172+ joint_loc.pose .orientation .x ,
173+ joint_loc.pose .orientation .y ,
174+ joint_loc.pose .orientation .z ,
175+ joint_loc.pose .orientation .w );
176+ Pose pose (position, orientation);
177+
178+ bool is_valid = (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) &&
179+ (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT);
180+
181+ // Create HandJointPose and set it in the array
182+ HandJointPose joint_pose (pose, is_valid, joint_loc.radius );
183+ mutable_array->Mutate (i, joint_pose);
170184 }
171185
172186 return true ;
@@ -190,18 +204,18 @@ std::vector<std::string> HandTracker::get_required_extensions() const
190204 return { XR_EXT_HAND_TRACKING_EXTENSION_NAME };
191205}
192206
193- const HandData & HandTracker::get_left_hand () const
207+ const HandPoseT & HandTracker::get_left_hand () const
194208{
195- static const HandData empty_data{};
209+ static const HandPoseT empty_data{};
196210 auto impl = cached_impl_.lock ();
197211 if (!impl)
198212 return empty_data;
199213 return impl->get_left_hand ();
200214}
201215
202- const HandData & HandTracker::get_right_hand () const
216+ const HandPoseT & HandTracker::get_right_hand () const
203217{
204- static const HandData empty_data{};
218+ static const HandPoseT empty_data{};
205219 auto impl = cached_impl_.lock ();
206220 if (!impl)
207221 return empty_data;
0 commit comments