Example #1
0
        public SCNAction RotationY(double time)
        {
            var action  = SCNAction.RotateBy(0, 360, 0, time);
            var forever = SCNAction.RepeatActionForever(action);

            return(forever);
        }
        void ShowEndScreen()
        {
            gameIsComplete = true;

            // Add confettis
            SCNMatrix4 particlePosition = SCNMatrix4.CreateTranslation(0f, 8f, 0f);

            GameView.Scene.AddParticleSystem(confetti, particlePosition);

            // Congratulation title
            SKSpriteNode congrat = SKSpriteNode.FromImageNamed("Images/congratulations.png");

            congrat.Position = new CGPoint(GameView.Bounds.Width / 2, GameView.Bounds.Height / 2);
            SKScene overlay = GameView.OverlayScene;

            congrat.XScale = congrat.YScale = 0;
            congrat.Alpha  = 0;
            congrat.RunAction(SKAction.Group(new [] {
                SKAction.FadeInWithDuration(0.25),
                SKAction.Sequence(new [] {
                    SKAction.ScaleTo(.55f, 0.25),
                    SKAction.ScaleTo(.3f, 0.1),
                })
            }));

            // Panda Image
            SKSpriteNode congratPanda = SKSpriteNode.FromImageNamed("Images/congratulations_pandaMax.png");

            congratPanda.Position    = new CGPoint(GameView.Bounds.Width / 2f, GameView.Bounds.Height / 2f - 90f);
            congratPanda.AnchorPoint = new CGPoint(.5f, 0f);
            congratPanda.XScale      = congratPanda.YScale = 0f;
            congratPanda.Alpha       = 0;

            congratPanda.RunAction(SKAction.Sequence(new [] {
                SKAction.WaitForDuration(.5f),
                SKAction.Sequence(new [] {
                    SKAction.ScaleTo(.5f, 0.25),
                    SKAction.ScaleTo(.4f, 0.1)
                })
            }));

            overlay.AddChild(congratPanda);
            overlay.AddChild(congrat);

            // Stop music
            GameView.Scene.RootNode.RemoveAllAudioPlayers();

            // Play the congrat sound.
            GameView.Scene.RootNode.AddAudioPlayer(SCNAudioPlayer.FromSource(victoryMusic));

            // Animate the camera forever
            DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 1 * NanoSecondsPerSeond), () => {
                cameraYHandle.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0f, -1f, 0f, 3.0)));
                cameraXHandle.RunAction(SCNAction.RotateTo(-(float)Math.PI / 4f, 0f, 0f, 5.0));
            });
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // Create a session configuration
            var configuration = new ARWorldTrackingConfiguration {
                PlaneDetection         = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true
            };

            // Run the view's session
            SceneView.Session.Run(configuration, ARSessionRunOptions.ResetTracking);

            // randomly choose a point to place the Earth
            var pos = new SCNVector3(-2f, 0f, -2f);


            // earth r=0.2
            var globe     = SCNSphere.Create(0.2f);
            var globeNode = new SCNNode {
                Position = pos, Geometry = globe
            };

            globeNode.Geometry.Materials = LoadMaterials();
            //globeNode.Transform = SCNMatrix4.CreateRotationX(0.4101524f); // 23.5 degrees
            SceneView.Scene.RootNode.AddChildNode(globeNode);

            globeNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 1, 0, 3)));


            //moon r=0.08, orbit=0.6
            var pivotNode = new SCNNode {
                Position = new SCNVector3(0, 0, 0)
            };

            pivotNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 1, 0, 5)));

            var moon     = SCNSphere.Create(0.08f);
            var moonNode = new SCNNode {
                Geometry = moon
            };

            //moonNode.Position = new SCNVector3(pos.X - 0.6f, pos.Y + 0.1f, pos.Z);
            moonNode.Position           = new SCNVector3(0.6f, 0.1f, pos.Z);
            moonNode.Geometry.Materials = LoadMoonMaterials();
            pivotNode.AddChildNode(moonNode);

            globeNode.AddChildNode(pivotNode);
        }
Example #4
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // Create a session configuration
            var configuration = new ARWorldTrackingConfiguration
            {
                PlaneDetection         = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true
            };

            // Run the view's session
            SceneView.Session.Run(configuration, ARSessionRunOptions.ResetTracking);

            // Find the ship and position it just in front of the camera
            var ship = SceneView.Scene.RootNode.FindChildNode("ship", true);

            //ship.Position = new SCNVector3(2f, -2f, -9f);
            //HACK: to see the jet move (circle around the viewer in a roll), comment out the ship.Position line above
            // and uncomment the code below (courtesy @lobrien)

            var animation = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, (float)Math.PI, (float)Math.PI, (float)1));
            var pivotNode = new SCNNode {
                Position = new SCNVector3(0.0f, 2.0f, 0.0f)
            };

            pivotNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, -2, 0, 10)));
            ship.RemoveFromParentNode();
            pivotNode.AddChildNode(ship);
            SceneView.Scene.RootNode.AddChildNode(pivotNode);
            ship.Scale    = new SCNVector3(0.1f, 0.1f, 0.1f);
            ship.Position = new SCNVector3(2f, -2f, -3f);
            ship.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 2, 1)));

            //ENDHACK
        }
Example #5
0
        public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeAddedForAnchor(renderer, node, anchor);

            var imageAnchor = anchor as ARImageAnchor;

            if (imageAnchor == null)
            {
                return;
            }

            SoundManager.PlaySound("camera");

            var anchorTransform = imageAnchor.Transform;

            var referenceImage = imageAnchor.ReferenceImage;
            var item           = ReferenceLookup[referenceImage];
            var next           = GetNodeForItem(item.ItemData);

            next.Position    = new SCNVector3(anchorTransform.Column3.X, anchorTransform.Column3.Y + 0.05f, anchorTransform.Column3.Z);
            NodeLookup[next] = item;

            var hoverDistance = .025f;
            var hoverDuration = 2;
            var up            = SCNAction.MoveBy(0, hoverDistance, 0, hoverDuration);
            var down          = SCNAction.MoveBy(0, -hoverDistance, 0, hoverDuration);
            var seq           = SCNAction.Sequence(new[] { up, down });

            seq.TimingMode = SCNActionTimingMode.EaseInEaseOut;

            var hover = SCNAction.RepeatActionForever(seq);

            next.RunAction(hover);

            SCNView.Scene.RootNode.AddChildNode(next);
        }