void HandlePan(WKPanGestureRecognizer panGesture) { if (!gameNodes.HasValue || !gameStarted) { return; } var gNodes = gameNodes.Value; var location = panGesture.LocationInObject; var bounds = panGesture.ObjectBounds; // Compute the projection of the interface point to the virtual trackball. var sphereLocation = SphereProjection(location, bounds); switch (panGesture.State) { case WKGestureRecognizerState.Began: // Record initial states. initialSphereLocation = sphereLocation; initialObject3DRotation = gNodes.Object.Transform; break; case WKGestureRecognizerState.Cancelled: case WKGestureRecognizerState.Ended: case WKGestureRecognizerState.Changed: // Compute the rotation and apply to the object. var currentRotation = RotationFromPoint(initialSphereLocation, sphereLocation); gNodes.Object.Transform = SCNMatrix4.Mult(initialObject3DRotation, currentRotation); break; default: Console.WriteLine($"Unhandled gesture state: {panGesture.State}"); throw new InvalidProgramException(); } // End the game if the object has the initial orientation. if (panGesture.State == WKGestureRecognizerState.Ended) { EndGameOnCorrectOrientation(); } }
void HandlePan (WKPanGestureRecognizer panGesture) { if (!gameNodes.HasValue || !gameStarted) return; var gNodes = gameNodes.Value; var location = panGesture.LocationInObject; var bounds = panGesture.ObjectBounds; // Compute the projection of the interface point to the virtual trackball. var sphereLocation = SphereProjection (location, bounds); switch (panGesture.State) { case WKGestureRecognizerState.Began: // Record initial states. initialSphereLocation = sphereLocation; initialObject3DRotation = gNodes.Object.Transform; break; case WKGestureRecognizerState.Cancelled: case WKGestureRecognizerState.Ended: case WKGestureRecognizerState.Changed: // Compute the rotation and apply to the object. var currentRotation = RotationFromPoint (initialSphereLocation, sphereLocation); gNodes.Object.Transform = SCNMatrix4.Mult (initialObject3DRotation, currentRotation); break; default: Console.WriteLine ($"Unhandled gesture state: {panGesture.State}"); throw new InvalidProgramException (); } // End the game if the object has the initial orientation. if (panGesture.State == WKGestureRecognizerState.Ended) EndGameOnCorrectOrientation (); }