当前位置: 首页>>代码示例>>C#>>正文


C# World.AddChild方法代码示例

本文整理汇总了C#中World.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# World.AddChild方法的具体用法?C# World.AddChild怎么用?C# World.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在World的用法示例。


在下文中一共展示了World.AddChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_Deliver

        public void Test_Deliver()
        {
            var node1 = new Node ("Node1");
            var node2 = new Node ("Node2");
            var mbox1 = new MailBox ("All");
            var mbox2 = new MailBox ("All");
            node1.Attach (mbox1);
            node2.Attach (mbox2);

            var received1 = false;
            var received2 = false;

            mbox1.Action += (from, to, args) => {
                received1 = true;
            };
            mbox2.Action += (from, to, args) => {
                received2 = true;
            };

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);

            wld.PostOffice.Post (node1, "Node2", null);
            wld.PostOffice.Post (node2, "Node1", null);

            wld.Deliver ();

            Assert.AreEqual (true, received1);
            Assert.AreEqual (true, received2);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:31,代码来源:TestWorld.cs

示例2: Test_Overlaps

        public void Test_Overlaps()
        {
            var node1 = new Node ("Node1");
            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (1, 1, 1);
            node1.Attach (col1);

            var node2 = new Node ("Node2");
            var col2 = new CollisionObject ();
            col2.Shape = new BoxShape (1, 1, 1);
            node2.Attach (col2);

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);

            // コリジョン発生
            wld.CollisionUpdate ();

            Assert.AreEqual (1, col1.OverlappingObjectCount);
            Assert.AreEqual (1, col2.OverlappingObjectCount);

            // コリジョン消失
            node2.Translate (10, 0, 0);
            wld.CollisionUpdate ();

            Assert.AreEqual (0, col1.OverlappingObjectCount);
            Assert.AreEqual (0, col2.OverlappingObjectCount);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:29,代码来源:TestCollisionObject.cs

示例3: Test_CollideWith

        public void Test_CollideWith()
        {
            var node1 = new Node ("Node1");
            node1.Attach(new CollisionObject ());
            node1.CollisionObject.Shape = new BoxShape (1, 1, 1);
            node1.GroupID = 1;

            var node2 = new Node ("Node2");
            node2.Attach (new CollisionObject ());
            node2.CollisionObject.Shape = new BoxShape (1, 1, 1);
            node2.GroupID = 2;

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);

            node1.CollisionObject.CollideWith = -1;
            Assert.AreEqual (true, wld.Overlap (node1, node2));

            node1.CollisionObject.CollideWith = 1;
            Assert.AreEqual (false, wld.Overlap (node1, node2));

            node1.CollisionObject.CollideWith = 2;
            Assert.AreEqual (true, wld.Overlap (node1, node2));

            node1.CollisionObject.CollideWith = 2;
            node1.CollisionObject.IgnoreWith = 2;
            Assert.AreEqual (false, wld.Overlap (node1, node2));
        }
开发者ID:weimingtom,项目名称:erica,代码行数:29,代码来源:TestCollisionAnalyze.cs

示例4: Test_Distance

        public void Test_Distance()
        {
            var node1 = new Node ("Node1");
            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (1, 1, 1);
            node1.Attach (col1);

            var node2 = new Node ("Node2");
            var col2 = new CollisionObject ();
            col2.Shape = new BoxShape (1, 1, 1);
            node2.Attach (col2);

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);

            node1.Translate (0, 0, 0);
            node2.Translate (0, 0, 0);
            Assert.AreEqual (0, wld.Distance (node1, node2));

            node1.Translate (0, 0, 0);
            node2.Translate (10, 0, 0);
            Assert.AreEqual (8, wld.Distance (node1, node2), 0.01f);

            node1.Rotate (0, 0, 0, 0);
            node2.Rotate (45, 0, 0, 1);
            Assert.AreEqual (7.6f, wld.Distance (node1, node2), 0.01f);

            node1.Detach (col1);
            node2.Detach (col2);
            Assert.AreEqual (Single.NaN, wld.Distance (node1, node2), 0.01f);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:32,代码来源:TestCollisionAnalyze.cs

示例5: Test_Distance_Box_to_Box

        public void Test_Distance_Box_to_Box()
        {
            var node1 = new Node ("Node1");

            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (1, 1, 1);
            col1.SetOffset (0, 0, 0);

            node1.Attach (col1);

            var node2 = new Node ("Node2");
            var col2 = new CollisionObject ();
            col2.Shape = new BoxShape (1,1,1);
            col2.SetOffset (0, 10, 0);

            node2.Attach (col2);

            node1.Translate (0, 0, 0);
            node2.Translate (10, 0, 0);

            // 10*√2

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);

            wld.CollisionUpdate ();

            Assert.AreEqual(10*1.4142f - 2*1.4142f, wld.Distance (node1, node2), 0.05f);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:32,代码来源:TestDistance.cs

示例6: Main

        public static void Main(string[] args)
        {
            var g2d = DD.Graphics2D.GetInstance ();
            g2d.CreateWindow (800, 600, "こんにちは、世界");

            // ----------------------------------------

            var wld = new World ();

            var node1 = MySender.Create ("Recver1", new Vector3 (100, 250, 0));
            var node2 = MyRecver.Create ("Recver1", new Vector3 (600, 150, 0));
            var node3 = MyRecver.Create ("Recver2", new Vector3 (600, 250, 0));
            var node4 = MyRecver.Create ("Recver3", new Vector3 (600, 350, 0));
            var node5 = MyRecver.Create ("All", new Vector3 (600, 500, 0));
            var node6 = MyButton.Create ("1", "Recver1", new Vector3 (50, 350, 0));
            var node7 = MyButton.Create ("2", "Recver2", new Vector3 (100, 350, 0));
            var node8 = MyButton.Create ("3", "Recver3", new Vector3 (150, 350, 0));
            var node9 = MyButton.Create ("All", "All", new Vector3 (200, 350, 0));

            wld.AddChild (node1);
            wld.AddChild (node2);
            wld.AddChild (node3);
            wld.AddChild (node4);
            wld.AddChild (node5);
            wld.AddChild (node6);
            wld.AddChild (node7);
            wld.AddChild (node8);
            wld.AddChild (node9);

            // ----------------------------------------
            var active = true;

            g2d.OnClosed += delegate (object sender, EventArgs eventArgs) {
                active = false;
            };

            Console.WriteLine ("Start of Main Loop");

            g2d.SetFrameRateLimit (60);

            var watch = new Stopwatch ();
            watch.Start ();

            while (active) {
                var msec = watch.ElapsedMilliseconds;

                g2d.Dispatch (wld);
                wld.Animate (msec, 33);
                wld.CollisionUpdate ();
                wld.Update (msec);
                wld.Deliver ();
                g2d.Draw (wld);
            }

            Console.WriteLine ("End of Game");
        }
开发者ID:weimingtom,项目名称:erica,代码行数:56,代码来源:Program.cs

示例7: Test_BoxShape

        public void Test_BoxShape()
        {
            var node1 = new Node ("Sweeper");

            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (1, 1, 1);
            col1.SetOffset (0, 1, 0);

            node1.Attach (col1);

            var node2 = new Node ("Target1");
            var col2 = new CollisionObject ();
            col2.Shape = new SphereShape (1);
            col2.SetOffset (0, 1, 0);

            node2.Attach (col2);

            var node3 = new Node ("Target2");
            var col3 = new CollisionObject ();
            col3.Shape = new SphereShape (1);
            col3.SetOffset (0, 1, 0);

            node1.Translate (0, 0, 0);
            node2.Translate (10, 0, 0);
            node3.Translate (20, 0, 0);

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);
            wld.AddChild (node3);

            wld.CollisionUpdate ();

            var result = wld.Sweep (node1, new Vector3 (100, 0, 0));
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (9, 1, 0), result.Point);
            Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
            Assert.AreEqual (8, result.Distance, 0.01f);
            Assert.AreEqual (0.08f, result.Fraction, 0.01f);

            result = wld.Sweep (node1, new Vector3 (0, 100, 0));
            Assert.AreEqual (false, result.Hit);

            result = wld.Sweep (node1, new Vector3 (-100, 100, 0));
            Assert.AreEqual (false, result.Hit);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:48,代码来源:TestSweep.cs

示例8: Test_Distance_Invalid_Objects

        public void Test_Distance_Invalid_Objects()
        {
            var node1 = new Node ("Node1");
            var node2 = new Node ("Node2");

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);

            wld.CollisionUpdate ();

            var d = wld.Distance (node1, node2);
            Assert.AreEqual (Single.NaN, d);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:16,代码来源:TestDistance.cs

示例9: Test_BoxShape

        public void Test_BoxShape()
        {
            var node = new Node ();

            var col = new CollisionObject ();
            col.Shape = new BoxShape (1, 1, 1);
            col.SetOffset (1, 0, 0);
            node.Attach (col);

            node.Translate (1, 0, 0);
            node.Rotate (45, 0, 0, 1);

            var wld = new World ();
            wld.AddChild (node);

            wld.CollisionUpdate ();

            // (1+1) - 1*√2
            var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (0.5858f, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
            Assert.AreEqual (10.58579f, result.Distance, 0.01f);
            Assert.AreEqual (0.5245f, result.Fraction, 0.01f);

            // (1+1) + 1*√2
            result = wld.RayCast (new Vector3 (10, 0, 0), new Vector3 (-10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (3.4142f, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (1, 0, 0), result.Normal);
            Assert.AreEqual (6.585786f, result.Distance, 0.01f);
            Assert.AreEqual (0.3225f, result.Fraction, 0.01f);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:35,代码来源:TestRayCast.cs

示例10: Test_DeliveryRecord

        public void Test_DeliveryRecord()
        {
            var node = new Node ("Node");
            var mbox = new MailBox ("Address");
            node.Attach (mbox);

            var wld = new World ();
            wld.AddChild (node);

            wld.Update (16);
            wld.PostOffice.Post (node, "Address", "Hello World");
            wld.Update (33);
            wld.PostOffice.Deliver ();

            var po = wld.PostOffice;

            Assert.AreEqual (1, po.DeliveryRecordCount);
            Assert.AreEqual (1, po.DeliveryRecords.Count());

            var rec = po.DeliveryRecords.ElementAt (0);

            Assert.AreEqual (33, rec.Time);
            Assert.AreEqual ("Node", rec.From);
            Assert.AreEqual ("Address", rec.Address);
            Assert.AreEqual ("Hello World", rec.LetterType);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:26,代码来源:TestPostOffice.cs

示例11: Test_Deliver

        public void Test_Deliver()
        {
            var node = new Node ("Node");
            var mbox = new MailBox ("Address");
            node.Attach (mbox);

            var received = false;
            Node from = null;
            string address = "";
            string letter = "";

            mbox.Action += (frm, addr, let) => {
                received = true;
                from = frm;
                address = addr;
                letter = (string)let;
            };

            var wld = new World ();
            wld.AddChild (node);

            wld.PostOffice.Post (node, "Address", "Hello World");
            wld.PostOffice.Deliver ();

            Assert.AreEqual (true, received);
            Assert.AreEqual (node, from);
            Assert.AreEqual ("Address", address);
            Assert.AreEqual ("Hello World", letter);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:29,代码来源:TestPostOffice.cs

示例12: Main

        public static void Main(string[] args)
        {
            var g2d = DD.Graphics2D.GetInstance ();
            g2d.CreateWindow (800, 600, "こんにちは、世界");

            Resource.SetTextureDirectory ("DatabaseSample/Textures/");

            // ----------------------------------------
            var node1 = MyCharacterHolder.Create ();
            var node2 = MyCharacterViewer.Create (new Vector3 (0, 0, 0));
            var node3 = MyCharacterSelector.Create (new Vector3 (0,0,0));

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);
            wld.AddChild (node3);

            // ----------------------------------------
            var active = true;

            g2d.OnClosed += delegate (object sender, EventArgs eventArgs) {
                active = false;
            };

            Console.WriteLine ("Start of Main Loop");

            g2d.SetFrameRateLimit (60);

            var watch = new Stopwatch ();
            watch.Start ();

            while (active) {
                var msec = watch.ElapsedMilliseconds;

                g2d.Dispatch (wld);
                wld.Animate (msec, 33);
                wld.Deliver ();
                wld.CollisionUpdate ();
                wld.Update (msec);
                wld.Purge ();
                g2d.Draw (wld);
            }

            Console.WriteLine ("End of Game");
            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:46,代码来源:Program2.cs

示例13: CreateWorld

        static World CreateWorld()
        {
            var wld = new World ("MyWorld");

            var node1 = MyCharacters.Create ();
            var node2 = MyBackground.Create ();
            var node3 = MyDisplayPanel.Create (new Vector3(0, 380, 0));
            var node4 = MyStatusPanel.Create (new Vector3 (100, 100, 0));
            var node5 = MyButtons.Create (new Vector3 (520, 300, 0));

            wld.AddChild (node1);
            wld.AddChild (node2);
            wld.AddChild (node3);
            wld.AddChild (node4);
            wld.AddChild (node5);

            return wld;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:18,代码来源:Program.cs

示例14: Test_ApplyImpulse

        public void Test_ApplyImpulse()
        {
            var box1 = new Node ("Box1");
            box1.Attach (new RigidBody());
            box1.RigidBody.AddShape (new BoxShape (1,1,1));
            box1.RigidBody.Material = new PhysicsMaterial ();
            box1.RigidBody.Mass = 1;
            box1.RigidBody.Material.Restitution = 1;

            var box2 = new Node ("Box2");
            box2.Attach (new RigidBody ());
            box2.RigidBody.AddShape (new BoxShape (1, 1, 1));
            box2.RigidBody.Material = new PhysicsMaterial ();
            box2.RigidBody.Mass = 1;
            box2.RigidBody.Material.Restitution = 1;

            var wld = new World ("");
            wld.AddChild (box1);
            wld.AddChild (box2);

            wld.PhysicsSimulator.SetGravity (0, 0, 0);

            box2.Translate (10, 0, 0);

            // ①→②
            //   ①②→ (運動量保存の法則)
            //
            // (impulse)=(force)x(dt)
            // ApplyForce()は BulletPhysics の1タイムステップ分(16msec)の力積を与えたに等しい
            // 自分で力積を計算するなら ApplyImpulse() を使用する
            box1.RigidBody.ApplyImpulse (1000 * 0.0166667f, 0, 0);

            for (var i = 0; i < 100; i++) {
                wld.PhysicsUpdate (33);
                //Debug.WriteLine ("Box1 = {0}, Box2 = {1}", box1.Position, box2.Position);
            }

            Assert.AreEqual (new Vector3 (8.03333f, 0, 0), box1.Position);
            Assert.AreEqual (new Vector3 (56.6890f, 0, 0), box2.Position);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:42,代码来源:TestPhysicsSimulation.cs

示例15: Test_ActiveCamera

        public void Test_ActiveCamera()
        {
            var cam = new Camera ();
            var node = new Node ();
            node.Attach (cam);

            var wld = new World ();
            wld.AddChild (node);

            wld.ActiveCamera = node;
            Assert.AreEqual (node, wld.ActiveCamera);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:12,代码来源:TestWorld.cs


注:本文中的World.AddChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。