本文整理匯總了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);
}
}
}
示例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);
}
}