示例#1
0
        void SetPostGameFilters()
        {
            SCNTransaction.Begin();

            desaturationTechnique.SetValueForKey(new NSNumber(1.0), (NSString)"Saturation");
            SCNTransaction.AnimationDuration = 1.0;

            SCNTransaction.Commit();

            SharedAppDelegate appDelegate = SharedAppDelegate.AppDelegate;

            appDelegate.Scene.Technique = desaturationTechnique;
        }
示例#2
0
        public override void DidOrderIn(PresentationViewController presentationViewController)
        {
            var diagramNode = SlideSceneGraph.SharedScenegraphDiagramNode();

            SCNTransaction.Begin();

            SCNTransaction.AnimationDuration = 1.0f;
            diagramNode.Opacity  = 1.0f;
            diagramNode.Rotation = new SCNVector4(1, 0, 0, 0);
            SlideSceneGraph.ShowNodesNamed(new string[] { "scene" });

            SCNTransaction.Commit();
        }
示例#3
0
        public override void WillOrderOut(PresentationViewController presentationViewController)
        {
            // Reset the camera and lights before leaving this slide
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 2;
            presentationViewController.CameraNode.Camera.ZFar = 100.0f;
            SCNTransaction.Commit();

            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 0.5f;
            presentationViewController.RiseMainLight(false);
            SCNTransaction.Commit();
        }
示例#4
0
        public override void WillOrderOut(PresentationViewController presentationViewController)
        {
            // Remove the animation from the camera and restore (animate) its position before leaving this slide
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 0;
            presentationViewController.CameraNode.RemoveAnimation(new NSString("myAnim"));
            presentationViewController.CameraNode.Position = presentationViewController.CameraNode.PresentationNode.Position;
            SCNTransaction.Commit();

            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1;
            presentationViewController.CameraNode.Position = new SCNVector3(0, 0, 0);
            SCNTransaction.Commit();
        }
示例#5
0
        public void BeginFrame()
        {
            currentNodeIndex = 0;
            states.Clear();
            states.Add(new State {
                Transform = SCNMatrix4.Identity
            });
            foreach (var n in entityNodes)
            {
                n.BeginFrame();
            }

            SCNTransaction.Begin();
            SCNTransaction.DisableActions = true;
        }
		public override void DidOrderIn (PresentationViewController presentationViewController)
		{
			// Bring up a screenshot of the editor
			var editorScreenshotNode = Utils.SCPlaneNode (NSBundle.MainBundle.PathForResource ("Images/particleEditor", "png"), 14, true);
			editorScreenshotNode.Geometry.FirstMaterial.Diffuse.MipFilter = SCNFilterMode.Linear;
			editorScreenshotNode.Position = new SCNVector3 (17, 3.8f, 5);
			editorScreenshotNode.Rotation = new SCNVector4 (0, 1, 0, -(float)Math.PI / 1.5f);
			GroundNode.AddChildNode (editorScreenshotNode);

			// Animate it (rotate and move)
			SCNTransaction.Begin ();
			SCNTransaction.AnimationDuration = 1;
			editorScreenshotNode.Position = new SCNVector3 (7, 3.8f, 5);
			editorScreenshotNode.Rotation = new SCNVector4 (0, 1, 0, -(float)Math.PI / 7);
			SCNTransaction.Commit ();
		}
示例#7
0
        public override void DidOrderIn(PresentationViewController presentationViewController)
        {
            // Bring up a screenshot of the editor
            var editorScreenshotNode = Utils.SCPlaneNode(NSBundle.MainBundle.PathForResource("Images/editor", "png"), 14, true);

            editorScreenshotNode.Position = new SCNVector3(17, 4.1f, 5);
            editorScreenshotNode.Rotation = new SCNVector4(0, 1, 0, -(float)(Math.PI / 1.5f));
            GroundNode.AddChildNode(editorScreenshotNode);

            // Animate it (rotate and move)
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1;
            editorScreenshotNode.Position    = new SCNVector3(7.5f, 4.1f, 5);
            editorScreenshotNode.Rotation    = new SCNVector4(0, 1, 0, -(float)(Math.PI / 6.0f));
            SCNTransaction.Commit();
        }
示例#8
0
 void RemoveNumberNodes()
 {
     // Move, fade and remove on completion
     foreach (var node in GroundNode.ChildNodes)
     {
         if (node.Name == "number")
         {
             SCNTransaction.Begin();
             SCNTransaction.AnimationDuration = 1;
             SCNTransaction.SetCompletionBlock(node.RemoveFromParentNode);
             node.Opacity  = 0.0f;
             node.Position = new SCNVector3(node.Position.X, node.Position.Y, node.Position.Z - 20);
             SCNTransaction.Commit();
         }
     }
 }
示例#9
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            SCNTransaction.Begin();

            switch (index)
            {
            case 0:
                // Set the slide's title and subtitle and add some text
                TextManager.SetTitle("More Animations");
                TextManager.SetSubtitle("Watch SceneKit 2013 Presentation");

                TextManager.AddBulletAtLevel("Skinning", 0);
                TextManager.AddBulletAtLevel("Morphing", 0);

                // Animate the character
                CharacterNode.AddAnimation(IdleAnimationGroup, new NSString("idleAnimation"));

                // The character is hidden. Wait a little longer before showing it
                // otherwise it may slow down the transition from the previous slide
                var delayInSeconds = 1.5;
                var popTime        = new DispatchTime(DispatchTime.Now, (long)(delayInSeconds * Utils.NSEC_PER_SEC));
                DispatchQueue.MainQueue.DispatchAfter(popTime, () => {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration = 0;
                    CharacterNode.Hidden             = false;
                    CharacterNode.Opacity            = 0;
                    SCNTransaction.Commit();

                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration       = 1.5;
                    SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
                    CharacterNode.Opacity = 1;
                    SCNTransaction.Commit();
                });
                break;

            case 1:
                CharacterNode.AddAnimation(AnimationGroup1, new NSString("animation"));
                break;

            case 2:
                SCNTransaction.AnimationDuration = 1.5f;
                //TODO SetShowsBones (true);
                break;
            }
            SCNTransaction.Commit();
        }
示例#10
0
        private static void ShowNodesNamed(string[] names)
        {
            var diagramNode = SlideSceneGraph.SharedScenegraphDiagramNode();

            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1.0f;
            foreach (var nodeName in names)
            {
                var node = diagramNode.FindChildNode(nodeName, true);
                node.Opacity = 1.0f;
                if (node.Rotation.Z == 0.0f)
                {
                    node.Rotation = new SCNVector4(0, 1, 0, 0);
                }
            }
            SCNTransaction.Commit();
        }
示例#11
0
        private void PerformCloseAnimation(bool flash = false)
        {
            if (this.isBorderOpen && !this.isAnimating)
            {
                this.isBorderOpen = false;
                this.isAnimating  = true;

                this.borderNode.RemoveAction("pulse");
                this.borderNode.Opacity = 1f;

                // Close animation
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration       = GameBoard.AnimationDuration / 2f;
                SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);

                this.borderNode.Opacity = 0.99f;
                SCNTransaction.SetCompletionBlock(() =>
                {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration       = GameBoard.AnimationDuration / 2f;
                    SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);

                    foreach (var segment in this.borderSegments)
                    {
                        segment.Close();
                    }

                    SCNTransaction.SetCompletionBlock(() =>
                    {
                        this.isAnimating = false;
                    });

                    SCNTransaction.Commit();
                });

                SCNTransaction.Commit();

                if (flash)
                {
                    var waitAction    = SCNAction.Wait(GameBoard.AnimationDuration * 0.75f);
                    var fadeInAction  = SCNAction.FadeOpacityTo(0.6f, GameBoard.AnimationDuration * 0.125f);
                    var fadeOutAction = SCNAction.FadeOpacityTo(0f, GameBoard.AnimationDuration * 0.125f);
                    this.FillPlane.RunAction(SCNAction.Sequence(new SCNAction[] { waitAction, fadeOutAction, fadeInAction }));
                }
            }
        }
示例#12
0
        // Animate (fade out) to remove the text of specified type
        public void FadeOutText(TextType type)
        {
            var node = SubGroups [(int)type];

            SubGroups [(int)type] = null;
            if (node != null)
            {
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = FLIP_DURATION;
                SCNTransaction.SetCompletionBlock(node.RemoveFromParentNode);
                node.Opacity = 0;
                SCNTransaction.Commit();

                // Reset the baseline to what it was before adding this text
                CurrentBaseline = Math.Max(CurrentBaseline, BaselinePerType [(int)type]);
            }
        }
示例#13
0
        protected void PerformEnemyDieWithExplosion(SCNNode enemy, SCNVector3 direction)
        {
            var explositionScene = SCNScene.FromFile("art.scnassets/enemy/enemy_explosion.scn");

            if (explositionScene != null)
            {
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration       = 0.4f;
                SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);

                SCNTransaction.SetCompletionBlock(() =>
                {
                    explositionScene.RootNode.EnumerateHierarchy((SCNNode node, out bool stop) =>
                    {
                        stop = false;
                        if (node.ParticleSystems != null)
                        {
                            foreach (var particle in node.ParticleSystems)
                            {
                                enemy.AddParticleSystem(particle);
                            }
                        }
                    });

                    // Hide
                    if (enemy.ChildNodes.Length > 0)
                    {
                        enemy.ChildNodes[0].Opacity = 0f;
                    }
                });

                direction.Y = 0;
                enemy.RemoveAllAnimations();
                enemy.EulerAngles = new SCNVector3(enemy.EulerAngles.X, enemy.EulerAngles.X + (float)Math.PI * 4.0f, enemy.EulerAngles.Z);

                enemy.WorldPosition += SCNVector3.Normalize(direction) * 1.5f;
                this.PositionAgentFromNode();

                SCNTransaction.Commit();
            }
            else
            {
                Console.WriteLine("Missing enemy_explosion.scn");
            }
        }
示例#14
0
        public override void DidOrderIn(PresentationViewController presentationViewController)
        {
            // Once the slide ordered in, reveal the diagram
            foreach (var node in DiagramNode.ChildNodes)
            {
                node.Rotation = new SCNVector4(0, 1, 0, (float)(Math.PI / 2));                  // initially viewed from the side
            }
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 0.75f;
            DiagramNode.Opacity = 1.0f;

            foreach (var node in DiagramNode.ChildNodes)
            {
                node.Rotation = new SCNVector4(0, 1, 0, 0);
            }

            SCNTransaction.Commit();
        }
示例#15
0
        void SetIngameFilters()
        {
            SCNTransaction.Begin();

            desaturationTechnique.SetValueForKey(new NSNumber(0.0), (NSString)"Saturation");
            SCNTransaction.AnimationDuration = 1.0;
            desaturationTechnique.SetValueForKey(new NSNumber(1.0), (NSString)"Saturation");

            SCNTransaction.Commit();

            SCNAction dropTechnique = SCNAction.Wait(1.0f);

            SharedAppDelegate appDelegate = SharedAppDelegate.AppDelegate;

            appDelegate.Scene.Scene.RootNode.RunAction(dropTechnique, () => {
                appDelegate.Scene.Technique = null;
            });
        }
示例#16
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                TextManager.SetTitle("Animation Events");
                TextManager.AddBulletAtLevel("SCNAnimationEvent", 0);

                TextManager.AddCode("#var anEvent = #SCNAnimationEvent.Create# (0.2,  aBlock); \n"
                                    + "anAnimation.#AnimationEvents# = @[anEvent, anotherEvent];#");

                // Warm up NSSound by playing an empty sound.
                // Otherwise the first sound may take some time to start playing and will be desynchronised.
                var path       = NSBundle.MainBundle.PathForResource("Sounds/emptySound", "m4a");
                var soundUrl   = NSUrl.FromFilename(path);
                var emptySound = new NSSound(soundUrl, false);
                emptySound.Play();
                break;

            case 1:
            case 2:
                // Trigger the attack animation
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Attack], new NSString("attack"));
                break;

            case 3:
                // Trigger the walk animation
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Walk], new NSString("walk"));
                break;

            case 4:
                // Trigger the death animation
                // Make sure to remove the "idle" animation and prevent the model from intersecting with the floor.

                HeroSkeletonNode.RemoveAllAnimations();
                HeroSkeletonNode.AddAnimation(Animations [(int)CharacterAnimation.Die], new NSString("death"));

                SCNTransaction.Begin();
                //TODO heroSkeletonNode.ParentNode.Transform = SCNMatrix4.CreateTranslation (new SCNVector3 (0, 0, 40)); //CATransform3DTranslate(_heroSkeletonNode.parentNode.transform, 0, 0, 40);
                SCNTransaction.Commit();
                break;
            }
        }
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                // Set the slide's title and subtitle and add some text
                TextManager.SetTitle("Materials");
                TextManager.SetSubtitle("CALayer as texture");

                TextManager.AddCode("#// Map a layer tree on a 3D object. \n"
                                    + "aNode.Geometry.FirstMaterial.Diffuse.#Contents# = #aLayerTree#;#");

                // Add the model
                var intermediateNode = SCNNode.Create();
                intermediateNode.Position = new SCNVector3(0, 3.9f, 8);
                intermediateNode.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI / 2));
                GroundNode.AddChildNode(intermediateNode);
                Utils.SCAddChildNode(intermediateNode, "frames", "Scenes/frames/frames", 8);

                presentationViewController.NarrowSpotlight(true);
                break;

            case 1:
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;

                // Change the point of view to "frameCamera" (a camera defined in the "frames" scene)
                var frameCamera = ContentNode.FindChildNode("frameCamera", true);
                ((SCNView)presentationViewController.View).PointOfView = frameCamera;

                // The "frames" scene contains animations, update the end time of our main scene and start to play the animations
                ((SCNView)presentationViewController.View).Scene.SetAttribute(new NSNumber(7.33f), SCNScene.EndTimeAttributeKey);
                ((SCNView)presentationViewController.View).CurrentTime = 0;
                ((SCNView)presentationViewController.View).Playing     = true;
                ((SCNView)presentationViewController.View).Loops       = true;

                PlayerLayer1 = ConfigurePlayer(NSBundle.MainBundle.PathForResource("Movies/movie1", "mov"), "PhotoFrame-Vertical");
                PlayerLayer2 = ConfigurePlayer(NSBundle.MainBundle.PathForResource("Movies/movie2", "mov"), "PhotoFrame-Horizontal");

                SCNTransaction.Commit();
                break;
            }
        }
示例#18
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1.5f;

            var cameraNode = presentationViewController.CameraNode;

            switch (index)
            {
            case 0:
                break;

            case 1:
                // Add a code snippet
                TextManager.AddCode("#aCamera.#FocalDistance# = 16.0f; \n"
                                    + "aCamera.#FocalBlurRadius# = 8.0f;#");
                break;

            case 2:
                // Turn on DOF to illustrate the code snippet
                cameraNode.Camera.FocalDistance   = 16;
                cameraNode.Camera.FocalSize       = 1.5f;
                cameraNode.Camera.Aperture        = 0.3f;
                cameraNode.Camera.FocalBlurRadius = 8;
                break;

            case 3:
                // Focus far away
                cameraNode.Camera.FocalDistance = 35;
                cameraNode.Camera.FocalSize     = 4;
                cameraNode.Camera.Aperture      = 0.1f;

                // and update the code snippet
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                TextManager.AddEmptyLine();
                TextManager.AddCode("#aCamera.#FocalDistance# = #35.0f#; \n"
                                    + "aCamera.#FocalBlurRadius# = 8.0f;#");
                break;
            }

            SCNTransaction.Commit();
        }
示例#19
0
        private void AnimateGrab(SCNVector3 ballPosition)
        {
            // here we want to animate the rotation of the current yaw to the new yaw
            // and also animate the strap moving to the center of the view

            // drop from ballOriginInactiveAbove to ballOriginInactive in a transaction
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = this.properties.GrabAnimationTime;

            // animate the sling and ball to the camera
            this.rope.UpdateRopeModel();

            // animate the ball to the player
            if (this.Projectile != null)
            {
                this.Projectile.WorldPosition = ballPosition;
            }

            SCNTransaction.Commit();
        }
        private void WillOrderOutSlide(int slideIndex)
        {
            var slide = GetSlide(slideIndex, false);

            if (slide != null)
            {
                var node = slide.ContentNode;

                // Fade out and remove on completion
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.75f;
                SCNTransaction.SetCompletionBlock(() => node.RemoveFromParentNode());
                node.Opacity = 0.0f;
                SCNTransaction.Commit();

                slide.WillOrderOut(this);

                SlideCache.Remove(slideIndex.ToString());
            }
        }
示例#21
0
        private void PresentDices(PresentationViewController presentationViewController)
        {
            var count  = 200;
            var spread = 6;

            // drop rigid bodies cubes
            var intervalTime   = 5.0 / count;
            var remainingCount = count;

            Timer = NSTimer.CreateRepeatingTimer(intervalTime, delegate(NSTimer obj) {
                if (Step > 4)
                {
                    Timer.Invalidate();
                    return;
                }

                SCNTransaction.Begin();

                var worldPos = GroundNode.ConvertPositionToNode(new SCNVector3(0, 30, 0), null);

                var dice = CreateBlock(worldPos, new SCNVector3(1.5f, 1.5f, 1.5f));

                //add to scene
                ((SCNView)presentationViewController.View).Scene.RootNode.AddChildNode(dice);

                dice.PhysicsBody.Velocity        = new SCNVector3(RandFloat(-spread, spread), -10, RandFloat(-spread, spread));
                dice.PhysicsBody.AngularVelocity = new SCNVector4(RandFloat(-1, 1), RandFloat(-1, 1), RandFloat(-1, 1), RandFloat(-3, 3));

                SCNTransaction.Commit();

                Dices.Add(dice);

                // ensure we stop firing
                if (--remainingCount < 0)
                {
                    Timer.Invalidate();
                }
            });

            NSRunLoop.Current.AddTimer(Timer, NSRunLoopMode.Default);
        }
        public void CheckIfObjectShouldMoveOntoPlane(ARPlaneAnchor anchor, SCNNode planeAnchorNode)
        {
            foreach (var vo in VirtualObjects)
            {
                // Get the object's position in the plane's coordinate system.
                var objectPos = planeAnchorNode.ConvertPositionToNode(vo.Position, vo.ParentNode);

                if (Math.Abs(objectPos.Y) < float.Epsilon)
                {
                    return;                     // The object is already on the plane - nothing to do here.
                }

                // Add 10% tolerance to the corners of the plane.
                var tolerance = 0.1f;

                var minX = anchor.Center.X - anchor.Extent.X / 2f - anchor.Extent.X * tolerance;
                var maxX = anchor.Center.X + anchor.Extent.X / 2f + anchor.Extent.X * tolerance;
                var minZ = anchor.Center.Z - anchor.Extent.Z / 2f - anchor.Extent.Z * tolerance;
                var maxZ = anchor.Center.Z + anchor.Extent.Z / 2f + anchor.Extent.Z * tolerance;

                if (objectPos.X < minX || objectPos.X > maxX || objectPos.Z < minZ || objectPos.Z > maxZ)
                {
                    return;
                }

                // Drop the object onto the plane if it is near it.
                var verticalAllowance = 0.05f;
                var epsilon           = 0.001;       // Do not bother updating if the difference is less than a mm.
                var distanceToPlane   = Math.Abs(objectPos.Y);
                if (distanceToPlane > epsilon && distanceToPlane < verticalAllowance)
                {
                    Delegate.DidMoveObjectOntoNearbyPlane(this, vo);

                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration       = distanceToPlane * 500;               // Move 2mm per second
                    SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                    vo.Position = new SCNVector3(vo.Position.X, anchor.Transform.M32, vo.Position.Z);
                    SCNTransaction.Commit();
                }
            }
        }
示例#23
0
        // Animate to reveal the text of specified type
        public void FlipInText(TextType type)
        {
            var node = SubGroups [(int)type];

            if (node != null)
            {
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0;
                node.Position = new SCNVector3(-PIVOT_X, 0, 0);
                node.Pivot    = SCNMatrix4.CreateTranslation(-PIVOT_X, 0, 0);
                node.Rotation = new SCNVector4(0, 1, 0, -FLIP_ANGLE);
                node.Opacity  = 0;
                SCNTransaction.Commit();

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = FLIP_DURATION;
                node.Rotation = new SCNVector4(0, 1, 0, 0);
                node.Opacity  = 1;
                SCNTransaction.Commit();
            }
        }
        // Updates the secondary image of the floor if needed
        private void UpdateFloorImage(NSImage image, Slide slide)
        {
            // We don't want to animate if we replace the secondary image by a new one
            // Otherwise we want to translate the secondary image to the new location
            var disableAction = false;

            if (FloorImage != image)
            {
                FloorImage    = image;
                disableAction = true;

                if (image != null)
                {
                    // Set a new material property with this image to the "floorMap" custom property of the floor
                    var property = SCNMaterialProperty.Create(image);
                    property.WrapS     = SCNWrapMode.Repeat;
                    property.WrapT     = SCNWrapMode.Repeat;
                    property.MipFilter = SCNFilterMode.Linear;

                    Floor.FirstMaterial.SetValueForKey(property, new NSString("floorMap"));
                }
            }

            if (image != null)
            {
                var slidePosition = slide.GroundNode.ConvertPositionToNode(new SCNVector3(0, 0, 10), null);

                if (disableAction)
                {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration = 0;
                    Floor.FirstMaterial.SetValueForKey(NSValue.FromVector(slidePosition), new NSString("floorImageNamePosition"));
                    SCNTransaction.Commit();
                }
                else
                {
                    Floor.FirstMaterial.SetValueForKey(NSValue.FromVector(slidePosition), new NSString("floorImageNamePosition"));
                }
            }
        }
示例#25
0
        public void AnimateBallGrowAndDrop()
        {
            // the block is the total time of the transcation, so sub-blocks are limited by that too
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = this.properties.GrowAnimationTime;

            // correct the rope sim by animating back to reset pose no matter what
            var fixupLaunchAnimationTime = 0.1f;

            this.rope.InterpolateToRestPoseAnimation(fixupLaunchAnimationTime);

            // first scale the ball from small to original size
            if (this.Projectile != null)
            {
                this.Projectile.Scale = this.projectileScale;
            }

            SCNTransaction.SetCompletionBlock(() =>
            {
                // after back to scale, then run the ball drop
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = this.properties.DropAnimationTime;

                // next drop from ballOriginInactiveAbove to ballOriginInactive
                if (this.Projectile != null)
                {
                    this.Projectile.WorldPosition = this.ballOriginInactiveBelow.WorldPosition;
                }

                SCNTransaction.SetCompletionBlock(() =>
                {
                    // only allow the ball to be grabbed after animation completes
                    this.ballCanBeGrabbed = true;
                });

                SCNTransaction.Commit();
            });

            SCNTransaction.Commit();
        }
示例#26
0
        public static SCNNode SCGaugeNode(string title, ref SCNNode progressNode)
        {
            var gaugeGroup = SCNNode.Create();

            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1;
            var gauge = SCNNode.Create();

            gauge.Geometry = SCNCapsule.Create(0.4f, 8);
            gauge.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant;
            gauge.Rotation = new SCNVector4(0, 0, 1, (float)(Math.PI / 2));
            gauge.Geometry.FirstMaterial.Diffuse.Contents = NSColor.White;
            gauge.Geometry.FirstMaterial.CullMode         = SCNCullMode.Front;

            var gaugeValue = SCNNode.Create();

            gaugeValue.Geometry = SCNCapsule.Create(0.3f, 7.8f);
            gaugeValue.Pivot    = SCNMatrix4.CreateTranslation(new SCNVector3(0, 3.8f, 0));
            gaugeValue.Position = new SCNVector3(0, 3.8f, 0);
            gaugeValue.Scale    = new SCNVector3(1, 0.01f, 1);
            gaugeValue.Opacity  = 0.0f;
            gaugeValue.Geometry.FirstMaterial.Diffuse.Contents  = NSColor.FromDeviceRgba(0, 1, 0, 1);
            gaugeValue.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant;
            gauge.AddChildNode(gaugeValue);

            if (progressNode != null)
            {
                progressNode = gaugeValue;
            }

            var titleNode = Utils.SCLabelNode(title, LabelSize.Normal, false);

            titleNode.Position = new SCNVector3(-8, -0.55f, 0);

            gaugeGroup.AddChildNode(titleNode);
            gaugeGroup.AddChildNode(gauge);
            SCNTransaction.Commit();

            return(gaugeGroup);
        }
示例#27
0
        private SCNNode AddText(string message, TextType type, int level)
        {
            var parentNode = TextContainerForType(type);

            CurrentBaseline -= LineHeightForTextType(type, level);

            if (type > TextType.Subtitle)
            {
                if (PreviousType <= TextType.Title)
                {
                    CurrentBaseline -= 1.0f;
                }

                if (PreviousType <= TextType.Subtitle && type > TextType.Subtitle)
                {
                    CurrentBaseline -= 1.3f;
                }
                else if (PreviousType != type)
                {
                    CurrentBaseline -= 1.0f;
                }
            }

            var textNode = (type == TextType.Code) ? NodeWithCode(message) : NodeWithText(message, type, level);

            parentNode.AddChildNode(textNode);

            if (FadesIn)
            {
                textNode.Opacity = 0;
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1.0f;
                textNode.Opacity = 1;
                SCNTransaction.Commit();
            }

            PreviousType = type;

            return(textNode);
        }
示例#28
0
文件: GameView.cs 项目: zrma/PolyGlot
        // forward click event to the game view controller
        public override void MouseDown(NSEvent theEvent)
        {
            // Called when a mouse click occurs

            // check what nodes are clicked
            var p          = ConvertPointFromView(theEvent.LocationInWindow, null);
            var hitResults = HitTest(p, (NSDictionary)null);

            // check that we clicked on at least one object
            if (hitResults.Length > 0)
            {
                // retrieved the first clicked object
                var result = hitResults[0];

                // get its material
                var material = result.Node.Geometry.FirstMaterial;

                // highlight it
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.5f;

                // on completion - unhighlight
                SCNTransaction.SetCompletionBlock(() =>
                {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration = 0.5f;

                    material.Emission.Contents = NSColor.Black;

                    SCNTransaction.Commit();
                });

                material.Emission.Contents = NSColor.Red;

                SCNTransaction.Commit();
            }

            base.MouseDown(theEvent);
        }
示例#29
0
        public void Pshhhh()
        {
            if (!Burning)
            {
                return;
            }

            Burning = false;
            fireEmitter.ParticleSystems [0].BirthRate = 0;
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration           = 1.0;
            smokeEmitter.ParticleSystems [0].BirthRate = 0;
            SCNTransaction.Commit();

            whiteSmokeEmitter.ParticleSystems [0].BirthRate = whiteSmokeBirthRate;
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 5.0;
            whiteSmokeEmitter.ParticleSystems [0].BirthRate = 0;
            SCNTransaction.Commit();

            UpdateWalkSpeed(1f);
        }
示例#30
0
        void HandleTap(UIGestureRecognizer gestureRecognize)
        {
            // retrieve the SCNView
            var scnView = (SCNView)View;

            // check what nodes are tapped
            CGPoint p = gestureRecognize.LocationInView(scnView);

            SCNHitTestResult[] hitResults = scnView.HitTest(p, (SCNHitTestOptions)null);

            // check that we clicked on at least one object
            if (hitResults.Length > 0)
            {
                // retrieved the first clicked object
                SCNHitTestResult result = hitResults [0];

                // get its material
                SCNMaterial material = result.Node.Geometry.FirstMaterial;

                // highlight it
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.5f;

                // on completion - unhighlight
                SCNTransaction.SetCompletionBlock(() => {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration = 0.5f;

                    material.Emission.Contents = UIColor.Black;

                    SCNTransaction.Commit();
                });

                material.Emission.Contents = UIColor.Red;

                SCNTransaction.Commit();
            }
        }