當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。