Beispiel #1
0
        public static T Create <T>(SCNNode prototypeNode, int?index, Dictionary <string, object> gamedefs) where T : Projectile, new()
        {
            var node = prototypeNode.Clone();

            // geometry and materials are reference types, so here we
            // do a deep copy. that way, each projectile gets its own color.
            node.CopyGeometryAndMaterials();

            var physicsNode = node.FindNodeWithPhysicsBody();

            if (physicsNode?.PhysicsBody == null)
            {
                throw new Exception("Projectile node has no physics");
            }

            physicsNode.PhysicsBody.ContactTestBitMask = (int)(CollisionMask.RigidBody | CollisionMask.GlitterObject | CollisionMask.TriggerVolume);
            physicsNode.PhysicsBody.CategoryBitMask    = (int)CollisionMask.Ball;

            var result = GameObject.Create <T>(node, index, gamedefs, false, false);

            result.PhysicsNode = physicsNode;
            result.PhysicsBody = physicsNode.PhysicsBody;

            return(result);
        }
Beispiel #2
0
        SCNNode CreateBanana()
        {
            //Create model
            if (bananaCollectable == null)
            {
                bananaCollectable       = GameSimulation.LoadNodeWithName("banana", GameSimulation.PathForArtResource("level/banana.dae"));
                bananaCollectable.Scale = new SCNVector3(0.5f, 0.5f, 0.5f);


                SCNSphere       sphereGeometry = SCNSphere.Create(40);
                SCNPhysicsShape physicsShape   = SCNPhysicsShape.Create(sphereGeometry, new SCNPhysicsShapeOptions());
                bananaCollectable.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Kinematic, physicsShape);

                // Only collide with player and ground
                bananaCollectable.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
                // Declare self in the banana category
                bananaCollectable.PhysicsBody.CategoryBitMask = GameCollisionCategory.Banana;

                // Rotate and Hover forever.
                bananaCollectable.Rotation = new SCNVector4(0.5f, 1f, 0.5f, -(nfloat)Math.PI / 4);
                SCNAction idleHoverGroupAction = SCNAction.Group(new SCNAction[] { BananaIdleAction, HoverAction });
                SCNAction repeatForeverAction  = SCNAction.RepeatActionForever(idleHoverGroupAction);
                bananaCollectable.RunAction(repeatForeverAction);
            }

            return(bananaCollectable.Clone());
        }
        public SCNNode GetBox()
        {
            if (_prefab != null)
            {
                return(_prefab.Clone());
            }

            var g = new SCNBox {
                Height = .066f, Width = .066f, Length = .066f
            };

            g.FirstMaterial.Diffuse.Contents = UIImage.FromFile("xamagon-fill");

            var box = new SCNNode {
                Geometry = g
            };

            box.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Dynamic, SCNPhysicsShape.Create(g, new SCNPhysicsShapeOptions {
                ShapeType = SCNPhysicsShapeType.BoundingBox
            }));
            box.PhysicsBody.ContinuousCollisionDetectionThreshold = g.Width * 2;

            _prefab = box;

            return(_prefab.Clone());
        }
Beispiel #4
0
        SCNNode CreateLargeBanana()
        {
            //Create model
            if (largeBananaCollectable == null)
            {
                var   node      = GameSimulation.LoadNodeWithName("banana", GameSimulation.PathForArtResource("level/banana.dae"));
                float scaleMode = 0.5f * 10 / 4;
                node.Scale = new SCNVector3(scaleMode, scaleMode, scaleMode);


                SCNSphere       sphereGeometry = SCNSphere.Create(100);
                SCNPhysicsShape physicsShape   = SCNPhysicsShape.Create(sphereGeometry, new SCNPhysicsShapeOptions());
                node.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Kinematic, physicsShape);

                // Only collide with player and ground
                node.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
                // Declare self in the banana category
                node.PhysicsBody.CategoryBitMask = GameCollisionCategory.Coin;

                // Rotate forever.
                SCNAction rotateCoin = SCNAction.RotateBy(0f, 8f, 0f, 2f);
                SCNAction repeat     = SCNAction.RepeatActionForever(rotateCoin);

                node.Rotation = new SCNVector4(0f, 1f, 0f, (nfloat)Math.PI / 2);
                node.RunAction(repeat);

                largeBananaCollectable = node;
            }

            SCNNode nodeSparkle = largeBananaCollectable.Clone();

            SCNParticleSystem newSystem = GameSimulation.LoadParticleSystemWithName("sparkle");

            nodeSparkle.AddParticleSystem(newSystem);

            return(nodeSparkle);
        }
		public static SCNNode SharedScenegraphDiagramNode ()
		{
			if (DiagramNode == null) {
				DiagramNode = SCNNode.Create ();
				DiagramNode.Opacity = 0.0f;


				// "Scene"
				var blue = NSColor.FromDeviceRgba (49.0f / 255.0f, 80.0f / 255.0f, 201.0f / 255.0f, 1);
				var box = Utils.SCBoxNode ("Scene", new CGRect (-53.5f, -25, 107, 50), blue, 10, true);
				box.Name = "scene";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (5.4f, 4.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrow from "Scene" to "Root Node"
				var arrowNode = new SCNNode {
					Name = "sceneArrow",
					Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (3, 0.2f), new CGSize (0.5f, 0.7f), 0.2f, false), 0),
					Scale = new SCNVector3 (20, 20, 1),
					Position = new SCNVector3 (-5, 0, 8),
					Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 2))
				};
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = blue;
				box.AddChildNode (arrowNode);


				// "Root Node"
				var green = NSColor.FromDeviceRgba (154.0f / 255.0f, 197.0f / 255.0f, 58.0f / 255.0f, 1);
				box = Utils.SCBoxNode ("Root Node", new CGRect (-40, -36, 80, 72), green, 10, true);
				box.Name = "rootNode";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (5.405f, 1.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrows from "Root Node" to child nodes
				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "nodeArrow1";
				arrowNode.Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (5.8f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, true), 0);
				arrowNode.Position = new SCNVector3 (0, -30, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI * 0.85f));
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
				box.AddChildNode (arrowNode);

				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "nodeArrow2";
				arrowNode.Position = new SCNVector3 (0, -43, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI * (1 - 0.85f)));
				box.AddChildNode (arrowNode);

				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "nodeArrow3";
				arrowNode.Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (2.6f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, true), 0);
				arrowNode.Position = new SCNVector3 (-4, -38, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI * 0.5f));
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
				box.AddChildNode (arrowNode);


				// Multiple "Child Node"
				box = Utils.SCBoxNode ("Child Node", new CGRect (-40, -36, 80, 72), green, 10, true);
				box.Name = "child1";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (2.405f, -2, 0);
				DiagramNode.AddChildNode (box);

				box = box.Clone ();
				box.Name = "child2";
				box.Position = new SCNVector3 (5.405f, -2, 0);
				DiagramNode.AddChildNode (box);

				box = box.Clone ();
				box.Name = "child3";
				box.Position = new SCNVector3 (8.405f, -2, 0);
				DiagramNode.AddChildNode (box);


				// "Light"
				var purple = NSColor.FromDeviceRgba (190.0f / 255.0f, 56.0f / 255.0f, 243.0f / 255.0f, 1);
				box = Utils.SCBoxNode ("Light", new CGRect (-40, -20, 80, 40), purple, 10, true);
				box.Name = "light";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (2.405f, -4.8f, 0);
				DiagramNode.AddChildNode (box);
				

				// Arrow to "Light"
				arrowNode = new SCNNode {
					Name = "lightArrow",
					Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (2.0f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, false), 0),
					Position = new SCNVector3 (-5, 60, 8),
					Scale = new SCNVector3 (20, 20, 1),
					Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 2))
				};
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
				box.AddChildNode (arrowNode);


				// "Camera"
				box = Utils.SCBoxNode ("Camera", new CGRect (-45, -20, 90, 40), purple, 10, true);
				box.Name = "camera";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (5.25f, -4.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrow to "Camera"
				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "cameraArrow";
				arrowNode.Position = new SCNVector3 (0, 60, 8);
				box.AddChildNode (arrowNode);


				// "Geometry"
				box = Utils.SCBoxNode ("Geometry", new CGRect (-55, -20, 110, 40), purple, 10, true);
				box.Name = "geometry";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (8.6f, -4.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrows to "Geometry"
				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "geometryArrow";
				arrowNode.Position = new SCNVector3 (-10, 60, 8);
				box.AddChildNode (arrowNode);

				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "geometryArrow2";
				arrowNode.Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (5.0f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, false), 0);
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
				arrowNode.Position = new SCNVector3 (-105, 53, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 8));
				box.AddChildNode (arrowNode);


				// Multiple "Material"
				var redColor = NSColor.FromDeviceRgba (168.0f / 255.0f, 21.0f / 255.0f, 0.0f / 255.0f, 1);

				var materialsBox = Utils.SCBoxNode (null, new CGRect (-151, -25, 302, 50), NSColor.LightGray, 2, true);
				materialsBox.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				materialsBox.Name = "materials";
				materialsBox.Position = new SCNVector3 (8.7f, -7.1f, -0.2f);
				DiagramNode.AddChildNode (materialsBox);

				box = Utils.SCBoxNode ("Material", new CGRect (-45, -20, 90, 40), redColor, 0, true);
				box.Position = new SCNVector3 (-100, 0, 0.2f);
				materialsBox.AddChildNode (box);

				box = box.Clone ();
				box.Position = new SCNVector3 (100, 0, 0.2f);
				materialsBox.AddChildNode (box);

				box = box.Clone ();
				box.Position = new SCNVector3 (0, 0, 0.2f);
				materialsBox.AddChildNode (box);

				// Arrow from "Geometry" to the materials
				arrowNode = new SCNNode {
					Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (2.0f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, false), 0),
					Position = new SCNVector3 (-6, 65, 8),
					Scale = new SCNVector3 (20, 20, 1),
					Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 2))
				};
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = redColor;
				box.AddChildNode (arrowNode);

				materialsBox.ParentNode.ReplaceChildNode (materialsBox, materialsBox.FlattenedClone ());
			}
			return DiagramNode;
		}
Beispiel #6
0
        public static SCNNode SharedScenegraphDiagramNode()
        {
            if (DiagramNode == null)
            {
                DiagramNode         = SCNNode.Create();
                DiagramNode.Opacity = 0.0f;


                // "Scene"
                var blue = NSColor.FromDeviceRgba(49.0f / 255.0f, 80.0f / 255.0f, 201.0f / 255.0f, 1);
                var box  = Utils.SCBoxNode("Scene", new CGRect(-53.5f, -25, 107, 50), blue, 10, true);
                box.Name     = "scene";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(5.4f, 4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrow from "Scene" to "Root Node"
                var arrowNode = new SCNNode {
                    Name     = "sceneArrow",
                    Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(3, 0.2f), new CGSize(0.5f, 0.7f), 0.2f, false), 0),
                    Scale    = new SCNVector3(20, 20, 1),
                    Position = new SCNVector3(-5, 0, 8),
                    Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2))
                };
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = blue;
                box.AddChildNode(arrowNode);


                // "Root Node"
                var green = NSColor.FromDeviceRgba(154.0f / 255.0f, 197.0f / 255.0f, 58.0f / 255.0f, 1);
                box          = Utils.SCBoxNode("Root Node", new CGRect(-40, -36, 80, 72), green, 10, true);
                box.Name     = "rootNode";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(5.405f, 1.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrows from "Root Node" to child nodes
                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "nodeArrow1";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(5.8f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, true), 0);
                arrowNode.Position = new SCNVector3(0, -30, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.85f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
                box.AddChildNode(arrowNode);

                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "nodeArrow2";
                arrowNode.Position = new SCNVector3(0, -43, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * (1 - 0.85f)));
                box.AddChildNode(arrowNode);

                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "nodeArrow3";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.6f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, true), 0);
                arrowNode.Position = new SCNVector3(-4, -38, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.5f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
                box.AddChildNode(arrowNode);


                // Multiple "Child Node"
                box          = Utils.SCBoxNode("Child Node", new CGRect(-40, -36, 80, 72), green, 10, true);
                box.Name     = "child1";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(2.405f, -2, 0);
                DiagramNode.AddChildNode(box);

                box          = box.Clone();
                box.Name     = "child2";
                box.Position = new SCNVector3(5.405f, -2, 0);
                DiagramNode.AddChildNode(box);

                box          = box.Clone();
                box.Name     = "child3";
                box.Position = new SCNVector3(8.405f, -2, 0);
                DiagramNode.AddChildNode(box);


                // "Light"
                var purple = NSColor.FromDeviceRgba(190.0f / 255.0f, 56.0f / 255.0f, 243.0f / 255.0f, 1);
                box          = Utils.SCBoxNode("Light", new CGRect(-40, -20, 80, 40), purple, 10, true);
                box.Name     = "light";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(2.405f, -4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrow to "Light"
                arrowNode = new SCNNode {
                    Name     = "lightArrow",
                    Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.0f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0),
                    Position = new SCNVector3(-5, 60, 8),
                    Scale    = new SCNVector3(20, 20, 1),
                    Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2))
                };
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
                box.AddChildNode(arrowNode);


                // "Camera"
                box          = Utils.SCBoxNode("Camera", new CGRect(-45, -20, 90, 40), purple, 10, true);
                box.Name     = "camera";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(5.25f, -4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrow to "Camera"
                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "cameraArrow";
                arrowNode.Position = new SCNVector3(0, 60, 8);
                box.AddChildNode(arrowNode);


                // "Geometry"
                box          = Utils.SCBoxNode("Geometry", new CGRect(-55, -20, 110, 40), purple, 10, true);
                box.Name     = "geometry";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(8.6f, -4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrows to "Geometry"
                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "geometryArrow";
                arrowNode.Position = new SCNVector3(-10, 60, 8);
                box.AddChildNode(arrowNode);

                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "geometryArrow2";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(5.0f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0);
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
                arrowNode.Position = new SCNVector3(-105, 53, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 8));
                box.AddChildNode(arrowNode);


                // Multiple "Material"
                var redColor = NSColor.FromDeviceRgba(168.0f / 255.0f, 21.0f / 255.0f, 0.0f / 255.0f, 1);

                var materialsBox = Utils.SCBoxNode(null, new CGRect(-151, -25, 302, 50), NSColor.LightGray, 2, true);
                materialsBox.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                materialsBox.Name     = "materials";
                materialsBox.Position = new SCNVector3(8.7f, -7.1f, -0.2f);
                DiagramNode.AddChildNode(materialsBox);

                box          = Utils.SCBoxNode("Material", new CGRect(-45, -20, 90, 40), redColor, 0, true);
                box.Position = new SCNVector3(-100, 0, 0.2f);
                materialsBox.AddChildNode(box);

                box          = box.Clone();
                box.Position = new SCNVector3(100, 0, 0.2f);
                materialsBox.AddChildNode(box);

                box          = box.Clone();
                box.Position = new SCNVector3(0, 0, 0.2f);
                materialsBox.AddChildNode(box);

                // Arrow from "Geometry" to the materials
                arrowNode = new SCNNode {
                    Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.0f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0),
                    Position = new SCNVector3(-6, 65, 8),
                    Scale    = new SCNVector3(20, 20, 1),
                    Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2))
                };
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = redColor;
                box.AddChildNode(arrowNode);

                materialsBox.ParentNode.ReplaceChildNode(materialsBox, materialsBox.FlattenedClone());
            }
            return(DiagramNode);
        }