@@ -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
@@ -112,10 +114,11 @@ private void UpdateControllerData(InteractionSourceState interactionSourceState)
112114 var lastState = TrackingState ;
113115
114116 IsPositionAvailable = interactionSourceState . sourcePose . TryGetPosition ( out currentControllerPosition ) ;
117+
115118 if ( IsPositionAvailable )
116119 {
117120 TrackingState = TrackingState . Tracked ;
118- IsPositionApproximate = ( interactionSourceState . sourcePose . positionAccuracy == InteractionSourcePositionAccuracy . Approximate ) ;
121+ IsPositionApproximate = interactionSourceState . sourcePose . positionAccuracy == InteractionSourcePositionAccuracy . Approximate ;
119122 }
120123 else
121124 {
@@ -125,10 +128,31 @@ private void UpdateControllerData(InteractionSourceState interactionSourceState)
125128
126129 IsRotationAvailable = interactionSourceState . sourcePose . TryGetRotation ( out currentControllerRotation ) ;
127130
131+ lastControllerPose = currentControllerPose ;
132+ currentControllerPose . Position = currentControllerPosition ;
133+ currentControllerPose . Rotation = currentControllerRotation ;
134+
135+ // Raise input system events if it is enabled.
128136 if ( lastState != TrackingState )
129137 {
130138 InputSystem ? . RaiseSourceTrackingStateChanged ( InputSource , this , TrackingState ) ;
131139 }
140+
141+ if ( TrackingState == TrackingState . Tracked && lastControllerPose != currentControllerPose )
142+ {
143+ if ( IsPositionAvailable && IsRotationAvailable )
144+ {
145+ InputSystem ? . RaiseSourcePoseChanged ( InputSource , this , currentControllerPose ) ;
146+ }
147+ else if ( IsPositionAvailable && ! IsRotationAvailable )
148+ {
149+ InputSystem ? . RaiseSourcePositionChanged ( InputSource , this , currentControllerPosition ) ;
150+ }
151+ else if ( ! IsPositionAvailable && IsRotationAvailable )
152+ {
153+ InputSystem ? . RaiseSourceRotationChanged ( InputSource , this , currentControllerRotation ) ;
154+ }
155+ }
132156 }
133157
134158 /// <summary>
@@ -143,18 +167,18 @@ private void UpdatePointerData(InteractionSourceState interactionSourceState, Mi
143167
144168 if ( CameraCache . Main . transform . parent != null )
145169 {
146- currentPointerData . Position = CameraCache . Main . transform . parent . TransformPoint ( currentPointerPosition ) ;
147- currentPointerData . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentPointerRotation . eulerAngles ) ) ;
170+ currentPointerPose . Position = CameraCache . Main . transform . parent . TransformPoint ( currentPointerPosition ) ;
171+ currentPointerPose . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentPointerRotation . eulerAngles ) ) ;
148172 }
149173
150- //Update the interaction data source
151- interactionMapping . SetPoseValue ( currentPointerData ) ;
174+ // Update the interaction data source
175+ interactionMapping . SetPoseValue ( currentPointerPose ) ;
152176
153177 // If our value changed raise it.
154178 if ( interactionMapping . Changed )
155179 {
156- //Raise input system Event if it enabled
157- InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentPointerData ) ;
180+ // Raise input system Event if it enabled
181+ InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentPointerPose ) ;
158182 }
159183 }
160184
@@ -176,18 +200,18 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed
176200
177201 if ( CameraCache . Main . transform . parent != null )
178202 {
179- currentGripData . Position = CameraCache . Main . transform . parent . TransformPoint ( currentGripPosition ) ;
180- currentGripData . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentGripRotation . eulerAngles ) ) ;
203+ currentGripPose . Position = CameraCache . Main . transform . parent . TransformPoint ( currentGripPosition ) ;
204+ currentGripPose . Rotation = Quaternion . Euler ( CameraCache . Main . transform . parent . TransformDirection ( currentGripRotation . eulerAngles ) ) ;
181205 }
182206
183- //Update the interaction data source
184- interactionMapping . SetPoseValue ( currentGripData ) ;
207+ // Update the interaction data source
208+ interactionMapping . SetPoseValue ( currentGripPose ) ;
185209
186210 // If our value changed raise it.
187211 if ( interactionMapping . Changed )
188212 {
189- //Raise input system Event if it enabled
190- InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentGripData ) ;
213+ // Raise input system Event if it enabled
214+ InputSystem ? . RaisePoseInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , currentGripPose ) ;
191215 }
192216 }
193217 break ;
@@ -199,7 +223,7 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed
199223 // If our value changed raise it.
200224 if ( interactionMapping . Changed )
201225 {
202- //Raise input system Event if it enabled
226+ // Raise input system Event if it enabled
203227 if ( interactionSourceState . grasped )
204228 {
205229 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -225,13 +249,13 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M
225249 {
226250 case DeviceInputType . TouchpadTouch :
227251 {
228- //Update the interaction data source
252+ // Update the interaction data source
229253 interactionMapping . SetBoolValue ( interactionSourceState . touchpadTouched ) ;
230254
231255 // If our value changed raise it.
232256 if ( interactionMapping . Changed )
233257 {
234- //Raise input system Event if it enabled
258+ // Raise input system Event if it enabled
235259 if ( interactionSourceState . touchpadTouched )
236260 {
237261 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -251,7 +275,7 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M
251275 // If our value changed raise it.
252276 if ( interactionMapping . Changed )
253277 {
254- //Raise input system Event if it enabled
278+ // Raise input system Event if it enabled
255279 if ( interactionSourceState . touchpadPressed )
256280 {
257281 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -265,13 +289,13 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M
265289 }
266290 case DeviceInputType . Touchpad :
267291 {
268- //Update the interaction data source
292+ // Update the interaction data source
269293 interactionMapping . SetVector2Value ( interactionSourceState . touchpadPosition ) ;
270294
271295 // If our value changed raise it.
272296 if ( interactionMapping . Changed )
273297 {
274- //Raise input system Event if it enabled
298+ // Raise input system Event if it enabled
275299 InputSystem ? . RaisePositionInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , interactionSourceState . touchpadPosition ) ;
276300 }
277301 break ;
@@ -292,13 +316,13 @@ private void UpdateThumbStickData(InteractionSourceState interactionSourceState,
292316 {
293317 case DeviceInputType . ThumbStickPress :
294318 {
295- //Update the interaction data source
319+ // Update the interaction data source
296320 interactionMapping . SetBoolValue ( interactionSourceState . thumbstickPressed ) ;
297321
298322 // If our value changed raise it.
299323 if ( interactionMapping . Changed )
300324 {
301- //Raise input system Event if it enabled
325+ // Raise input system Event if it enabled
302326 if ( interactionSourceState . thumbstickPressed )
303327 {
304328 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -312,13 +336,13 @@ private void UpdateThumbStickData(InteractionSourceState interactionSourceState,
312336 }
313337 case DeviceInputType . ThumbStick :
314338 {
315- //Update the interaction data source
339+ // Update the interaction data source
316340 interactionMapping . SetVector2Value ( interactionSourceState . thumbstickPosition ) ;
317341
318342 // If our value changed raise it.
319343 if ( interactionMapping . Changed )
320344 {
321- //Raise input system Event if it enabled
345+ // Raise input system Event if it enabled
322346 InputSystem ? . RaisePositionInputChanged ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , interactionSourceState . thumbstickPosition ) ;
323347 }
324348 break ;
@@ -340,13 +364,13 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi
340364 case DeviceInputType . TriggerPress :
341365 case DeviceInputType . Select :
342366 {
343- //Update the interaction data source
367+ // Update the interaction data source
344368 interactionMapping . SetBoolValue ( interactionSourceState . selectPressed ) ;
345369
346370 // If our value changed raise it.
347371 if ( interactionMapping . Changed )
348372 {
349- //Raise input system Event if it enabled
373+ // Raise input system Event if it enabled
350374 if ( interactionSourceState . selectPressed )
351375 {
352376 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
@@ -360,13 +384,13 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi
360384 }
361385 case DeviceInputType . Trigger :
362386 {
363- //Update the interaction data source
387+ // Update the interaction data source
364388 interactionMapping . SetFloatValue ( interactionSourceState . selectPressedAmount ) ;
365389
366390 // If our value changed raise it.
367391 if ( interactionMapping . Changed )
368392 {
369- //Raise input system Event if it enabled
393+ // Raise input system Event if it enabled
370394 InputSystem ? . RaiseOnInputPressed ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction , interactionSourceState . selectPressedAmount ) ;
371395 }
372396 break ;
@@ -389,7 +413,7 @@ private void UpdateMenuData(InteractionSourceState interactionSourceState, Mixed
389413 // If our value changed raise it.
390414 if ( interactionMapping . Changed )
391415 {
392- //Raise input system Event if it enabled
416+ // Raise input system Event if it enabled
393417 if ( interactionSourceState . menuPressed )
394418 {
395419 InputSystem ? . RaiseOnInputDown ( InputSource , ControllerHandedness , interactionMapping . MixedRealityInputAction ) ;
0 commit comments