本文整理汇总了C#中Vector3.DistanceSqr方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.DistanceSqr方法的具体用法?C# Vector3.DistanceSqr怎么用?C# Vector3.DistanceSqr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.DistanceSqr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
private void Generate(int xSize, int ySize, int zSize,
int xOffset, int yOffset, int zOffset)
{
Voxels = new float[xSize, ySize, zSize];
for (int x = 0; x < xSize; ++x)
{
float posX = (float)(x + xOffset);
for (int y = 0; y < ySize; ++y)
{
float posY = (float)(y + yOffset);
for (int z = 0; z < zSize; ++z)
{
float posZ = (float)(z + zOffset);
Vector3 pos = new Vector3(posX, posY, posZ);
pos.x *= 0.125f;
pos.y *= 0.25f;
pos.z *= 0.125f;
Voxels[x, y, z] = Noise.SmoothNoise(pos);
const int startTop = 55,
endTop = 60;
int yPos = y + yOffset;
if (yPos >= startTop && yPos <= endTop)
{
float heightLerp = Mathf.InverseLerp(startTop, endTop, yPos);
Voxels[x, y, z] = Mathf.Lerp(Voxels[x, y, z], 1.0f, heightLerp);
}
else if (yPos > endTop)
{
Voxels[x, y, z] = Mathf.Lerp(0.0f, 0.3999f,
NoiseAlgos2D.LinearNoise(new Vector2(pos.x, pos.z) * 6.0f));
}
Vector3 worldPos = new Vector3(x, y, z) + new Vector3(xOffset, yOffset, zOffset),
holePos = new Vector3(30.0f, 60.0f, 30.0f);
float distSqr = worldPos.DistanceSqr(holePos);
if (distSqr < 32.0f)
{
float distLerp = Mathf.Sqrt(distSqr) / 32.0f;
Voxels[x, y, z] = Mathf.Lerp(0.0f, Voxels[x, y, z], distLerp);
}
}
}
}
}
示例2: Explode
public void Explode(Vector3 center, float radius)
{
if (cr != null)
return;
Vector3 minF = center - new Vector3(radius, radius, radius),
maxF = center + new Vector3(radius, radius, radius);
Vector3i min = new Vector3i(Mathf.Max((int)minF.x, XOffset),
Mathf.Max((int)minF.y, YOffset),
Mathf.Max((int)minF.z, ZOffset)),
max = new Vector3i(Mathf.Min((int)maxF.x + 1, XOffset + XSize - 1),
Mathf.Min((int)maxF.y + 1, YOffset + YSize - 1),
Mathf.Min((int)maxF.z + 1, ZOffset + ZSize - 1));
int nChanged = 0;
for (int x = min.x; x <= max.x; ++x)
{
for (int y = min.y; y <= max.y; ++y)
{
for (int z = min.z; z <= max.z; ++z)
{
Vector3 pos = new Vector3(x, y, z);
Vector3i relPos = new Vector3i(x - XOffset, y - YOffset, z - ZOffset);
if (Voxels[relPos.x, relPos.y, relPos.z] > 0.0f &&
pos.DistanceSqr(center) < (radius * radius))
{
Voxels[relPos.x, relPos.y, relPos.z] = 0.0f;
nChanged += 1;
}
}
}
}
if (nChanged > 0)
{
cr = StartCoroutine(RunGenerator(false));
}
}