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


C# Random.NextQuaternionF方法代码示例

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


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

示例1: RandomizedMassSceneUpdate

        public void RandomizedMassSceneUpdate()
        {
            const int NumberOfSceneNodes = 6;
              const int NumberOfSteps = 10000;
              const float Saturation = 0.7f;  // Percent of scene nodes which should be in the scene.

              var random = new Random(1234567);
              var scene = new Scene();

              int numberOfNodesInScene = 0;

              var nodes = new TestSceneNode[NumberOfSceneNodes];

              // Create random nodes.
              for (int i = 0; i < NumberOfSceneNodes; i++)
              {
            var node = new TestSceneNode();
            nodes[i] = node;

            var position = random.NextVector3F(-1000, 1000);
            var orientation = random.NextQuaternionF();
            node.PoseLocal = new Pose(position, orientation);

            float p = random.NextFloat(0, 1);
            if (p < 0.1f)
              node.Shape = Shape.Empty;
            else if (p < 0.2f)
              node.Shape = Shape.Infinite;
            //else if (p < 0.21f)
            //{
            //  node.Shape = new BoxShape(float.PositiveInfinity, 1, 1);

            //  // Remove orientation - otherwise we get infinite AABB.
            //  node.PoseLocal = new Pose(node.PoseLocal.Position);

            //  var aabb = node.Aabb;
            //  var isValid = node.Aabb.Extent.IsNaN;
            //}
            else
              node.Shape = new SphereShape(random.NextFloat(0, 10));
              }

              for (int updateIndex = 0; updateIndex < NumberOfSteps; updateIndex++)
              {
            for (int i = 0; i < NumberOfSceneNodes; i++)
            {
              var node = nodes[i];

              // Add
              if (node.Parent == null)
              {
            if (random.NextFloat(0, 1) < 0.1f) // 10 percent change to add.
            {
              numberOfNodesInScene++;
              scene.Children.Add(node);
            }
              }

              // Remove
              if (node.Parent != null && ((float)numberOfNodesInScene) / (float)NumberOfSceneNodes > Saturation)
              {
            if (random.NextFloat(0, 1) < 0.1f) // 10 percent change to remove.
            {
              numberOfNodesInScene--;
              node.Parent.Children.Remove(node);
            }
              }

              // Move
              //if (node.IsInScene)
              {
            if (random.NextFloat(0, 1) < 0.5f) // 50% change to move
            {
              var pose = node.PoseWorld;
              pose.Position += random.NextVector3F(0, 10);
              node.PoseWorld = pose;
            }
            if (random.NextFloat(0, 1) < 0.1f) // 50% change to scale
            {
              node.ScaleLocal = random.NextVector3F(0.5f, 1.5f);
            }
              }
            }

            scene.Update(TimeSpan.FromSeconds(0.016666666f));
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:87,代码来源:SceneTest.cs

示例2: RandomizedMassSceneUpdate2

        public void RandomizedMassSceneUpdate2()
        {
            const int NumberOfSceneNodes = 10;
              const int NumberOfSteps = 10000;
              const float WorldSize = 1000;

              var random = new Random(123457);
              var scene = new Scene();
              scene.EnableMultithreading = false;

              var nodes = new TestSceneNode[NumberOfSceneNodes];

              // Create random nodes.
              for (int i = 0; i < NumberOfSceneNodes; i++)
              {
            var node = new TestSceneNode();
            nodes[i] = node;

            var position = random.NextVector3F(0, WorldSize);
            var orientation = random.NextQuaternionF();
            node.PoseLocal = new Pose(position, orientation);

            float p = random.NextFloat(0, 100);
            if (p < 0.1f)
              node.Shape = Shape.Empty;
            else if (p < 0.2f)
              node.Shape = Shape.Infinite;
            else if (p < 0.6f)
              node.Shape = new BoxShape(random.NextVector3F(0, WorldSize));
            else
              node.Shape = new SphereShape(random.NextFloat(0, WorldSize));
              }

              var projection = new PerspectiveProjection();
              projection.SetFieldOfView(0.8f, 1, WorldSize / 10000, WorldSize);
              var camera = new Camera(projection);
              var cameraNode = new CameraNode(camera);

              for (int updateIndex = 0; updateIndex < NumberOfSteps; updateIndex++)
              {
            int actionsPerFrame = random.NextInteger(0, 100);
            for (int i = 0; i < actionsPerFrame; i++)
            {
              var node = nodes[random.Next(0, NumberOfSceneNodes)];

              const int numberOfActions = 100;
              int action = random.Next(0, numberOfActions);

              //scene.Validate();

              if (action == 0)
              {
            // Add
            if (node.Parent == null)
            {
              scene.Children.Add(node);
              //scene.Validate();
            }
              }
              else if (action == 1)
              {
            // Remove
            if (node.Parent != null)
            {
              node.Parent.Children.Remove(node);
              //scene.Validate();
            }
              }
              else if (action == 2)
              {
            // Move
            var pose = node.PoseWorld;
            pose.Position = random.NextVector3F(0, WorldSize);
            node.PoseWorld = pose;
            //scene.Validate();
              }
              else if (action == 3)
              {
            // Very small Move
            var pose = node.PoseWorld;
            const float maxDistance = WorldSize / 10000;
            pose.Position += random.NextVector3F(-maxDistance, maxDistance);
            node.PoseWorld = pose;
            //scene.Validate();
              }
              else if (action == 4)
              {
            // Small Move
            var pose = node.PoseWorld;
            const float maxDistance = WorldSize / 100;
            pose.Position += random.NextVector3F(-maxDistance, maxDistance);
            node.PoseWorld = pose;
            //scene.Validate();
              }
              else if (action == 5)
              {
            // Scale
            node.ScaleLocal = random.NextVector3F(0.0f, 10f);
            //scene.Validate();
              }
//.........这里部分代码省略.........
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:101,代码来源:SceneTest.cs


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