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


C# World.RayCast方法代码示例

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


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

示例1: 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

示例2: Test_AllNodes

        public void Test_AllNodes()
        {
            var wld = new World ();

            for (var i = 0; i < 10; i++) {
                var node = new Node ("" + i);

                var col = new CollisionObject ();
                col.Shape = new SphereShape (1);
                node.Attach (col);

                node.Translate (i, 0, 0);

                wld.AddChild (node);
            }

            wld.CollisionUpdate ();

            var results = wld.RayCast (new Vector3 (-10, 10, 0), new Vector3 (10, 10, 0));
            Assert.AreEqual (0, results.Count ());

            results = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0));

            Assert.AreEqual (10, results.Count ());
            Assert.AreEqual ("0", results.ElementAt (0).Node.Name);
            Assert.AreEqual ("1", results.ElementAt (1).Node.Name);
            Assert.AreEqual ("2", results.ElementAt (2).Node.Name);
            Assert.AreEqual ("3", results.ElementAt (3).Node.Name);
            Assert.AreEqual ("4", results.ElementAt (4).Node.Name);
            Assert.AreEqual ("5", results.ElementAt (5).Node.Name);
            Assert.AreEqual ("6", results.ElementAt (6).Node.Name);
            Assert.AreEqual ("7", results.ElementAt (7).Node.Name);
            Assert.AreEqual ("8", results.ElementAt (8).Node.Name);
            Assert.AreEqual ("9", results.ElementAt (9).Node.Name);

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

示例3: Test_RayCast

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

            var node2 = new Node ("Node1");
            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 (1, 0, 0);
            node2.Translate (-1, 0, 0);

            wld.CollisionUpdate ();

            var start = new Vector3 (10, 0, 0);
            var end = new Vector3 (-10, 0, 0);
            var results = wld.RayCast (start, end).ToArray ();

            Assert.AreEqual (2, results.Count ());
            var result1 = results[0];
            var result2 = results[1];

            Assert.AreEqual (node1, result1.Node);
            Assert.AreEqual (0.39394f, result1.Fraction, 0.01f);
            Assert.AreEqual (new Vector3 (2, 0, 0), result1.Point);

            Assert.AreEqual (node2, result2.Node);
            Assert.AreEqual (0.49495f, result2.Fraction, 0.01f);
            Assert.AreEqual (new Vector3 (0, 0, 0), result2.Point);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:37,代码来源:TestCollisionAnalyze.cs

示例4: Test_SphereShape

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

            var col = new CollisionObject ();
            col.Shape = new SphereShape (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
            var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (1, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
            Assert.AreEqual (11, result.Distance, 0.01f);
            Assert.AreEqual (0.55f, result.Fraction, 0.01f);

            // (1+1) + 1
            result = wld.RayCast (new Vector3 (10, 0, 0), new Vector3 (-10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (3, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (1, 0, 0), result.Normal);
            Assert.AreEqual (7, result.Distance, 0.01f);
            Assert.AreEqual (0.35f, result.Fraction, 0.01f);

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

示例5: Test_CollideWith

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

            var col = new CollisionObject ();
            col.Shape = new SphereShape (1);
            node.Attach (col);

            node.GroupID = 1 << 1;

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

            wld.CollisionUpdate ();

            // 1<<0
            var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 1 << 0).FirstOrDefault ();
            Assert.AreEqual (false, result.Hit);

            // 1<<1
            result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 1 << 1).FirstOrDefault ();
            Assert.AreEqual (true, result.Hit);

            // 1<<2
            result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 1 << 2).FirstOrDefault ();
            Assert.AreEqual (false, result.Hit);

            // 0
            result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 0).FirstOrDefault ();
            Assert.AreEqual (false, result.Hit);

            // -1
            result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), -1).FirstOrDefault ();
            Assert.AreEqual (true, result.Hit);

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


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