Ejemplo n.º 1
0
        private void HandlerLongPress(UILongPressGestureRecognizer sender)
        {
            ARSCNView longPressScene = sender.View as ARSCNView;

            CoreGraphics.CGPoint longPressLocation = sender.LocationInView(longPressScene);
            SCNHitTestResult[]   hitTest           = longPressScene.HitTest(longPressLocation, new SCNHitTestOptions());

            if (hitTest?.Any() != true)
            {
                return;
            }

            SCNNode node = hitTest.First().Node;

            if (sender.State == UIGestureRecognizerState.Began)
            {
                SCNAction rotateAction  = SCNAction.RotateBy(0, ConvertDegreesToRadians(360f), 0, 1f);
                SCNAction rotateForever = SCNAction.RepeatActionForever(rotateAction);
                node.RunAction(rotateForever);
            }
            else if (sender.State == UIGestureRecognizerState.Ended)
            {
                node.RemoveAllActions();
            }
        }
        public void PositionScene(ARSCNView sceneView, string arLaunchType)
        {
            var arConfiguration = new ARWorldTrackingConfiguration
            {
                PlaneDetection         = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true
            };

            sceneView.Session.Run(arConfiguration, ARSessionRunOptions.ResetTracking);

            var sceneShipNode = sceneView.Scene.RootNode.FindChildNode("ship", true);

            sceneShipNode.Position = new SCNVector3(2f, -2f, -9f);

            var animationCycle  = SCNAction.RepeatActionForever(SCNAction.RotateBy(0f, 6f, 0, 5));
            var animationCrash  = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, (float)Math.PI, (float)Math.PI, (float)1));
            var animationNormal = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 0, 1));
            var animationRotate = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 2, 1));


            var scenePivotNode = new SCNNode {
                Position = new SCNVector3(0.0f, 2.0f, 0.0f)
            };

            scenePivotNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, -2, 0, 10)));

            sceneShipNode.RemoveFromParentNode();
            scenePivotNode.AddChildNode(sceneShipNode);

            sceneView.Scene.RootNode.AddChildNode(scenePivotNode);

            sceneShipNode.Scale    = new SCNVector3(0.1f, 0.1f, 0.1f);
            sceneShipNode.Position = new SCNVector3(2f, -2f, -3f);


            switch (arLaunchType)
            {
            case "Rotate Fly":
                sceneShipNode.RunAction(animationRotate);
                break;

            case "Crash Fly":
                sceneShipNode.RunAction(animationCrash);
                break;

            case "Cycle Fly":
                sceneShipNode.RunAction(animationCycle);
                break;

            case "Normal Fly":
                sceneShipNode.RunAction(animationNormal);
                break;

            default:
                scenePivotNode.RemoveAllActions();
                scenePivotNode.RunAction(SCNAction.Unhide());
                break;
            }
        }
Ejemplo n.º 3
0
 void BtnRun_TouchUpInside(object sender, EventArgs e)
 {
     if (planetsMove)
     {
         planetsMove = false;
         eartParentNode.RemoveAllActions();
         marsParentNode.RemoveAllActions();
         sunNode.RemoveAllActions();
         earthNode.RemoveAllActions();
         btnRun.SetTitle("PLAY", UIControlState.Normal);
     }
     else
     {
         planetsMove = true;
         eartParentNode.RunAction(RotationY(rotationEarth));
         marsParentNode.RunAction(RotationY(rotationMars));
         sunNode.RunAction(RotationY(rotationSun));
         earthNode.RunAction(RotationY(rotationMoon));
         btnRun.SetTitle("STOP", UIControlState.Normal);
     }
 }
Ejemplo n.º 4
0
        public void PanCamera(CGSize dir)
        {
            if (lockCamera)
            {
                return;
            }

            const float f = 0.005f;

            // Make sure the camera handles are correctly reset (because automatic camera animations may have put the "rotation" in a weird state
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 0.0;

            cameraYHandle.RemoveAllActions();
            cameraXHandle.RemoveAllActions();

            if (cameraYHandle.Rotation.Y < 0f)
            {
                cameraYHandle.Rotation = new SCNVector4(0f, 1f, 0f, -cameraYHandle.Rotation.W);
            }

            if (cameraXHandle.Rotation.X < 0f)
            {
                cameraXHandle.Rotation = new SCNVector4(1f, 0f, 0f, -cameraXHandle.Rotation.W);
            }

            SCNTransaction.Commit();

            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration       = 0.5;
            SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);

            cameraYHandle.Rotation = new SCNVector4(0f, 1f, 0f, cameraYHandle.Rotation.Y * (cameraYHandle.Rotation.W - (float)dir.Width * f));
            cameraXHandle.Rotation = new SCNVector4(1f, 0f, 0f, (float)Math.Max(-Math.PI / 2.0, Math.Min(0.13, cameraXHandle.Rotation.W + dir.Height * f)));
            SCNTransaction.Commit();
        }