本文整理汇总了C#中Sphere.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# Sphere.DistanceTo方法的具体用法?C# Sphere.DistanceTo怎么用?C# Sphere.DistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sphere
的用法示例。
在下文中一共展示了Sphere.DistanceTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeIslandHemisphere
void MakeIslandHemisphere( Vector3I offset, Sphere sphere ) {
Vector3I origin = new Vector3I( (int)Math.Floor( sphere.Origin.X - sphere.Radius ),
(int)Math.Floor( sphere.Origin.Y - sphere.Radius ),
(int)Math.Floor( sphere.Origin.Z - sphere.Radius ) );
BoundingBox box = new BoundingBox( origin,
(int)Math.Ceiling( sphere.Radius )*2,
(int)Math.Ceiling( sphere.Radius )*2,
(int)Math.Ceiling( sphere.Radius ) );
for( int x = box.XMin; x <= box.XMax; x++ ) {
for( int y = box.YMin; y <= box.YMax; y++ ) {
for( int z = box.ZMin; z <= box.ZMax; z++ ) {
Vector3I coord = new Vector3I( x, y, z );
if( sphere.DistanceTo( coord ) < sphere.Radius ) {
map.SetBlock( coord + offset, Block.Stone );
}
}
}
}
}
示例2: CreateIsland
Island CreateIsland( Vector3I offset ) {
List<Sphere> spheres = new List<Sphere>();
const int hSpread = 100;
double vSpreadMin = -hSpread*genParams.Verticality/2,
vSpreadMax = hSpread*genParams.Verticality/2;
double sphereSize = Math.Max( 1,
rand.Next( genParams.SphereSize - genParams.SphereSizeSpread,
genParams.SphereSize + genParams.SphereSizeSpread + 1 ) );
Sphere firstSphere = new Sphere( 0, 0, 0, (float)sphereSize );
spheres.Add( firstSphere );
for( int i = 1; i < genParams.SphereCount; i++ ) {
float newRadius = (float)(sphereSize + 1);
double angle = rand.NextDouble()*Math.PI*2;
Sphere newSphere = new Sphere( (float)(Math.Cos( angle )*rand.NextDouble()*hSpread),
(float)(Math.Sin( angle )*rand.NextDouble()*hSpread),
(float)(rand.NextDouble() * (vSpreadMax - vSpreadMin) + vSpreadMin),
newRadius );
double closestDist = newSphere.DistanceTo( spheres[0] );
Sphere closestSphere = spheres[0];
for( int j = 1; j < i; j++ ) {
double newDist = newSphere.DistanceTo( spheres[j] );
if( newDist < closestDist ) {
closestDist = newDist;
closestSphere = spheres[j];
}
}
Vector3F displacement = newSphere.Origin - closestSphere.Origin;
Vector3F direction = displacement.Normalize();
float distance = (float)Math.Pow( newSphere.Radius + closestSphere.Radius, genParams.SphereSeparation );
newSphere.Origin = closestSphere.Origin + direction*distance;
spheres.Add( newSphere );
sphereSize *= genParams.SphereSizeReduction;
}
// step 2: voxelize our spheres
foreach( Sphere sphere in spheres ) {
MakeIslandHemisphere( offset, sphere );
}
return new Island {
Spheres = spheres,
Offset = offset
};
}