@@ -40,14 +40,16 @@ public WindowsMixedRealityController(TrackingState trackingState, Handedness con
4040
4141 private Vector3 currentControllerPosition = Vector3 . zero ;
4242 private Quaternion currentControllerRotation = Quaternion . identity ;
43+ private MixedRealityPose lastControllerPose = MixedRealityPose . ZeroIdentity ;
44+ private MixedRealityPose currentControllerPose = MixedRealityPose . ZeroIdentity ;
4345
4446 private Vector3 currentPointerPosition = Vector3 . zero ;
4547 private Quaternion currentPointerRotation = Quaternion . identity ;
46- private MixedRealityPose currentPointerData = new MixedRealityPose ( Vector3 . zero , Quaternion . identity ) ;
48+ private MixedRealityPose currentPointerPose = MixedRealityPose . ZeroIdentity ;
4749
4850 private Vector3 currentGripPosition = Vector3 . zero ;
4951 private Quaternion currentGripRotation = Quaternion . identity ;
50- private MixedRealityPose currentGripData = new MixedRealityPose ( Vector3 . zero , Quaternion . identity ) ;
52+ private MixedRealityPose currentGripPose = MixedRealityPose . ZeroIdentity ;
5153
5254 #region Update data functions
5355
@@ -110,14 +112,15 @@ public void UpdateController(InteractionSourceState interactionSourceState)
110112 private void UpdateControllerData ( InteractionSourceState interactionSourceState )
111113 {
112114 var lastState = TrackingState ;
115+ var sourceKind = interactionSourceState . source . kind ;
113116
114- InteractionSourceKind sourceKind = interactionSourceState . source . kind ;
115117 if ( ( sourceKind == InteractionSourceKind . Hand ) ||
116- ( ( sourceKind == InteractionSourceKind . Controller ) && interactionSourceState . source . supportsPointing ) )
118+ ( ( sourceKind == InteractionSourceKind . Controller ) && interactionSourceState . source . supportsPointing ) )
117119 {
118120 // The source is either a hand or a controller that supports pointing.
119121 // We can now check for position and rotation.
120122 IsPositionAvailable = interactionSourceState . sourcePose . TryGetPosition ( out currentControllerPosition ) ;
123+
121124 if ( IsPositionAvailable )
122125 {
123126 IsPositionApproximate = ( interactionSourceState . sourcePose . positionAccuracy == InteractionSourcePositionAccuracy . Approximate ) ;
@@ -138,11 +141,31 @@ private void UpdateControllerData(InteractionSourceState interactionSourceState)
138141 TrackingState = TrackingState . NotApplicable ;
139142 }
140143
144+ lastControllerPose = currentControllerPose ;
145+ currentControllerPose . Position = currentControllerPosition ;
146+ currentControllerPose . Rotation = currentControllerRotation ;
141147
148+ // Raise input system events if it is enabled.
142149 if ( lastState != TrackingState )
143150 {
144151 InputSystem ? . RaiseSourceTrackingStateChanged ( InputSource , this , TrackingState ) ;
145152 }
153+
154+ if ( TrackingState == TrackingState . Tracked && lastControllerPose != currentControllerPose )
155+ {
156+ if ( IsPositionAvailable && IsRotationAvailable )
157+ {
158+ InputSystem ? . RaiseSourcePoseChanged ( InputSource , this , currentControllerPose ) ;
159+ }
160+ else if ( IsPositionAvailable && ! IsRotationAvailable )
161+ {
162+ InputSystem ? . RaiseSourcePositionChanged ( InputSource , this , currentControllerPosition ) ;
163+ }
164+ else if ( ! IsPositionAvailable && IsRotationAvailable )
165+ {
166+ InputSystem ? . RaiseSourceRotationChanged ( InputSource , this , currentControllerRotation ) ;
167+ }
168+ }
146169 }
147170
148171 /// <summary>
@@ -157,18 +180,18 @@ private void UpdatePointerData(InteractionSourceState interactionSourceState, Mi
157180
158181 if ( CameraCache . Main . transform . parent != null )
159182 {
160- currentPointerData . Position = CameraCache . Main . transform . parent . TransformPoint ( currentPointerPosition ) ;
161- currentPointerData . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentPointerRotation . eulerAngles ) ) ;
183+ currentPointerPose . Position = CameraCache . Main . transform . parent . TransformPoint ( currentPointerPosition ) ;
184+ currentPointerPose . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentPointerRotation . eulerAngles ) ) ;
162185 }
163186
164- //Update the interaction data source
165- interactionMapping . SetPoseValue ( currentPointerData ) ;
187+ // Update the interaction data source
188+ interactionMapping . SetPoseValue ( currentPointerPose ) ;
166189
167190 // If our value changed raise it.
168191 if ( interactionMapping . Changed )
169192 {
170- //Raise input system Event if it enabled
171- InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentPointerData ) ;
193+ // Raise input system Event if it enabled
194+ InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentPointerPose ) ;
172195 }
173196 }
174197
@@ -190,18 +213,18 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed
190213
191214 if ( CameraCache . Main . transform . parent != null )
192215 {
193- currentGripData . Position = CameraCache . Main . transform . parent . TransformPoint ( currentGripPosition ) ;
194- currentGripData . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentGripRotation . eulerAngles ) ) ;
216+ currentGripPose . Position = CameraCache . Main . transform . parent . TransformPoint ( currentGripPosition ) ;
217+ currentGripPose . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentGripRotation . eulerAngles ) ) ;
195218 }
196219
197- //Update the interaction data source
198- interactionMapping . SetPoseValue ( currentGripData ) ;
220+ // Update the interaction data source
221+ interactionMapping . SetPoseValue ( currentGripPose ) ;
199222
200223 // If our value changed raise it.
201224 if ( interactionMapping . Changed )
202225 {
203- //Raise input system Event if it enabled
204- InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentGripData ) ;
226+ // Raise input system Event if it enabled
227+ InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentGripPose ) ;
205228 }
206229 }
207230 break ;
@@ -213,7 +236,7 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed
213236 // If our value changed raise it.
214237 if ( interactionMapping . Changed )
215238 {
216- //Raise input system Event if it enabled
239+ // Raise input system Event if it enabled
217240 if ( interactionSourceState . grasped )
218241 {
219242 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -239,13 +262,13 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M
239262 {
240263 case DeviceInputType . TouchpadTouch :
241264 {
242- //Update the interaction data source
265+ // Update the interaction data source
243266 interactionMapping . SetBoolValue ( interactionSourceState . touchpadTouched ) ;
244267
245268 // If our value changed raise it.
246269 if ( interactionMapping . Changed )
247270 {
248- //Raise input system Event if it enabled
271+ // Raise input system Event if it enabled
249272 if ( interactionSourceState . touchpadTouched )
250273 {
251274 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -265,7 +288,7 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M
265288 // If our value changed raise it.
266289 if ( interactionMapping . Changed )
267290 {
268- //Raise input system Event if it enabled
291+ // Raise input system Event if it enabled
269292 if ( interactionSourceState . touchpadPressed )
270293 {
271294 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -279,13 +302,13 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M
279302 }
280303 case DeviceInputType . Touchpad :
281304 {
282- //Update the interaction data source
305+ // Update the interaction data source
283306 interactionMapping . SetVector2Value ( interactionSourceState . touchpadPosition ) ;
284307
285308 // If our value changed raise it.
286309 if ( interactionMapping . Changed )
287310 {
288- //Raise input system Event if it enabled
311+ // Raise input system Event if it enabled
289312 InputSystem ? . RaisePositionInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , interactionSourceState . touchpadPosition ) ;
290313 }
291314 break ;
@@ -306,13 +329,13 @@ private void UpdateThumbStickData(InteractionSourceState interactionSourceState,
306329 {
307330 case DeviceInputType . ThumbStickPress :
308331 {
309- //Update the interaction data source
332+ // Update the interaction data source
310333 interactionMapping . SetBoolValue ( interactionSourceState . thumbstickPressed ) ;
311334
312335 // If our value changed raise it.
313336 if ( interactionMapping . Changed )
314337 {
315- //Raise input system Event if it enabled
338+ // Raise input system Event if it enabled
316339 if ( interactionSourceState . thumbstickPressed )
317340 {
318341 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -326,13 +349,13 @@ private void UpdateThumbStickData(InteractionSourceState interactionSourceState,
326349 }
327350 case DeviceInputType . ThumbStick :
328351 {
329- //Update the interaction data source
352+ // Update the interaction data source
330353 interactionMapping . SetVector2Value ( interactionSourceState . thumbstickPosition ) ;
331354
332355 // If our value changed raise it.
333356 if ( interactionMapping . Changed )
334357 {
335- //Raise input system Event if it enabled
358+ // Raise input system Event if it enabled
336359 InputSystem ? . RaisePositionInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , interactionSourceState . thumbstickPosition ) ;
337360 }
338361 break ;
@@ -354,13 +377,13 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi
354377 case DeviceInputType . TriggerPress :
355378 case DeviceInputType . Select :
356379 {
357- //Update the interaction data source
380+ // Update the interaction data source
358381 interactionMapping . SetBoolValue ( interactionSourceState . selectPressed ) ;
359382
360383 // If our value changed raise it.
361384 if ( interactionMapping . Changed )
362385 {
363- //Raise input system Event if it enabled
386+ // Raise input system Event if it enabled
364387 if ( interactionSourceState . selectPressed )
365388 {
366389 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -374,13 +397,13 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi
374397 }
375398 case DeviceInputType . Trigger :
376399 {
377- //Update the interaction data source
400+ // Update the interaction data source
378401 interactionMapping . SetFloatValue ( interactionSourceState . selectPressedAmount ) ;
379402
380403 // If our value changed raise it.
381404 if ( interactionMapping . Changed )
382405 {
383- //Raise input system Event if it enabled
406+ // Raise input system Event if it enabled
384407 InputSystem ? . RaiseOnInputPressed ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , interactionSourceState . selectPressedAmount ) ;
385408 }
386409 break ;
@@ -403,7 +426,7 @@ private void UpdateMenuData(InteractionSourceState interactionSourceState, Mixed
403426 // If our value changed raise it.
404427 if ( interactionMapping . Changed )
405428 {
406- //Raise input system Event if it enabled
429+ // Raise input system Event if it enabled
407430 if ( interactionSourceState . menuPressed )
408431 {
409432 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
0 commit comments