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


C# Random.Direction方法代码示例

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


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

示例1: AddVein

        public static void AddVein(MyMwcObjectBuilder_VoxelMap builder, float thickness, Vector3 position, Random rnd, MyMwcVoxelMaterialsEnum material, float veinAngleDev, int maxLevel, int level = 0)
        {
            int numSplits = 2;// rnd.Next(2, 4);

            List<Vector3> targets = new List<Vector3>(numSplits);

            float handDist = thickness * 1.5f;

            for (int iSplit = 0; iSplit < numSplits; iSplit++)
            {
                // Hands per line
                int numHands = rnd.Next(8, 12);

                Vector3 direction = rnd.Direction();
                Vector3 target = position;
                for (int i = 0; i < numHands; i++)
                {
                    direction = rnd.Direction(direction, veinAngleDev);
                    target += direction * handDist;

                    // TODO: uncomment this to see material better (shown as tunnels, not only as voxel material)
                    //var voxelHand = new MyMwcObjectBuilder_VoxelHand_Sphere(target, thickness - 1, MyMwcVoxelHandModeTypeEnum.SUBTRACT);
                    //voxelHand.VoxelHandMaterial = material;
                    //builder.VoxelHandShapes.Add(voxelHand);

                    var voxelHand2 = new MyMwcObjectBuilder_VoxelHand_Sphere(new MyMwcPositionAndOrientation(target, Vector3.Forward, Vector3.Up), thickness, MyMwcVoxelHandModeTypeEnum.SET_MATERIAL);
                    voxelHand2.VoxelHandMaterial = material;
                    builder.VoxelHandShapes.Add(voxelHand2);
                }
                targets.Add(target);
            }

            if (level < maxLevel)
            {
                foreach (var t in targets)
                {
                    AddVein(builder, thickness * 0.7f, t, rnd, material, veinAngleDev, maxLevel, level + 1);
                }
            }
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:40,代码来源:MySectorGenerator.cs

示例2: AddAsteroidField

        void AddAsteroidField(MySolarSystemMapEntity entity)
        {
            Vector3 areaPos = EntityPosition(entity, m_currentCamera);
            float areaRadius = KmToGameUnits(entity.Radius);

            float blendSizeLower = SectorToGameUnits(10000);
            float blendSizeUpper = SectorToGameUnits(150000);
            float minAsteroidFieldDist = SectorToGameUnits(20000);
            float maxAsteroidFieldDist = SectorToGameUnits(200000);

            // Size of billboards in fraction of whole size
            const float billboardSizeRatio = 0.2f;
            const int billboardsPerAsteroidField = 25;

            float radius = billboardSizeRatio * areaRadius;

            Random rnd = new Random(entity.Sector.X ^ entity.Sector.Y ^ entity.Sector.Z ^ (int)entity.PositionInSector.X ^ (int)entity.PositionInSector.Y ^ (int)entity.PositionInSector.Z);

            for (int i = 0; i < billboardsPerAsteroidField; i++)
            {
                Vector3 dir = rnd.Direction();
                float maxDist = areaRadius - radius;
                Vector3 pos = areaPos + dir * maxDist;
                float dist = pos.Length();

                float alphaLower = CalculateBlend(minAsteroidFieldDist, minAsteroidFieldDist + blendSizeLower, dist);
                float alphaUpper = 1 - CalculateBlend(maxAsteroidFieldDist, maxAsteroidFieldDist + blendSizeUpper, dist);
                float alpha = alphaLower * alphaUpper;
                if (alpha < float.Epsilon)
                {
                    return;
                }
                Vector4 color = entity.Color.ToVector4();
                color *= alpha;
                //color.W = alpha;
                
                /*if (dist < minAsteroidFieldDist || dist > maxAsteroidFieldDist)
                {
                    return;
                }*/

                MyTransparentGeometry.AddBillboardOriented(MyTransparentMaterialEnum.SolarMapAsteroidField, color, pos, m_currentCamera.Up, m_currentCamera.Left, radius, -2);
            }
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:44,代码来源:MySolarMapRenderer.cs


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