本文整理汇总了C#中BoundingBoxD.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBoxD.Intersect方法的具体用法?C# BoundingBoxD.Intersect怎么用?C# BoundingBoxD.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingBoxD
的用法示例。
在下文中一共展示了BoundingBoxD.Intersect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVoxelContentInBoundingBox_Obsolete
public float GetVoxelContentInBoundingBox_Obsolete(BoundingBoxD worldAabb, out float cellCount)
{
MyPrecalcComponent.AssertUpdateThread();
cellCount = 0;
float result = 0;
Vector3I minCorner, maxCorner;
MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref worldAabb.Min, out minCorner);
MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref worldAabb.Max, out maxCorner);
minCorner += StorageMin;
maxCorner += StorageMin;
Storage.ClampVoxelCoord(ref minCorner);
Storage.ClampVoxelCoord(ref maxCorner);
m_storageCache.Resize(minCorner, maxCorner);
Storage.ReadRange(m_storageCache, MyStorageDataTypeFlags.Content, 0, ref minCorner, ref maxCorner);
BoundingBoxD voxelBox;
Vector3I coord, cache;
for (coord.Z = minCorner.Z, cache.Z = 0; coord.Z <= maxCorner.Z; coord.Z++, cache.Z++)
{
for (coord.Y = minCorner.Y, cache.Y = 0; coord.Y <= maxCorner.Y; coord.Y++, cache.Y++)
{
for (coord.X = minCorner.X, cache.X = 0; coord.X <= maxCorner.X; coord.X++, cache.X++)
{
MyVoxelCoordSystems.VoxelCoordToWorldAABB(PositionLeftBottomCorner - StorageMin * MyVoxelConstants.VOXEL_SIZE_IN_METRES, ref coord, out voxelBox);
if (worldAabb.Intersects(voxelBox))
{
float content = m_storageCache.Content(ref cache) / MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT;
float containPercent = (float)(worldAabb.Intersect(voxelBox).Volume / MyVoxelConstants.VOXEL_VOLUME_IN_METERS);
result += content * containPercent;
cellCount += containPercent;
}
}
}
}
return result;
}
示例2: SplitArea
private void SplitArea(BoundingBoxD box1, BoundingBoxD box2, List<BoundingBoxD> output)
{
var intersectValue = box1.Intersect(box2);
double x1 = Math.Min(intersectValue.Min.X, box2.Min.X);
double x2 = intersectValue.Min.X;
double x3 = intersectValue.Max.X;
double x4 = Math.Max(intersectValue.Max.X, box2.Max.X);
double z1 = Math.Min(intersectValue.Min.Z, box2.Min.Z);
double z2 = intersectValue.Min.Z;
double z3 = intersectValue.Max.Z;
double z4 = Math.Max(intersectValue.Max.Z, box2.Max.Z);
bool sameXMin = x1 == x2;
bool sameXMax = x3 == x4;
bool sameZMin = z1 == z2;
bool sameZMax = z3 == z4;
double minY = DEBUG_BOX_Y_MIN_POS;
double maxY = DEBUG_BOX_Y_MAX_POS;
if (sameXMin && sameXMax)
{
if (sameZMin && !sameZMax)
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z3), new Vector3D(x4, maxY, z4)));
}
else if (!sameZMin && sameZMax)
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x4, maxY, z2)));
}
else
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x4, maxY, z2)));
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z3), new Vector3D(x4, maxY, z4)));
}
}
else if (sameZMin && sameZMax)
{
if (sameXMin && !sameXMax)
{
output.Add(new BoundingBoxD(new Vector3D(x3, minY, z1), new Vector3D(x4, maxY, z4)));
}
else if (!sameXMin && sameXMax)
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x2, maxY, z2)));
}
else
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x2, maxY, z4)));
output.Add(new BoundingBoxD(new Vector3D(x3, minY, z1), new Vector3D(x4, maxY, z4)));
}
}
else
{
if (sameXMin)
{
if (sameZMin)
{
output.Add(new BoundingBoxD(new Vector3D(x3, minY, z1), new Vector3D(x4, maxY, z3)));
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z3), new Vector3D(x4, maxY, z4)));
}
else if (sameZMax)
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x4, maxY, z2)));
output.Add(new BoundingBoxD(new Vector3D(x3, minY, z2), new Vector3D(x4, maxY, z4)));
}
else
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x4, maxY, z2)));
output.Add(new BoundingBoxD(new Vector3D(x3, minY, z2), new Vector3D(x4, maxY, z3)));
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z3), new Vector3D(x4, maxY, z4)));
}
}
else if (sameXMax)
{
if (sameZMin)
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x2, maxY, z3)));
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z3), new Vector3D(x4, maxY, z4)));
}
else if (sameZMax)
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x4, maxY, z2)));
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z2), new Vector3D(x4, maxY, z4)));
}
else
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x4, maxY, z2)));
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z2), new Vector3D(x3, maxY, z3)));
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z3), new Vector3D(x4, maxY, z4)));
}
}
else if (sameZMin)
{
output.Add(new BoundingBoxD(new Vector3D(x1, minY, z1), new Vector3D(x2, maxY, z4)));
output.Add(new BoundingBoxD(new Vector3D(x2, minY, z3), new Vector3D(x3, maxY, z4)));
output.Add(new BoundingBoxD(new Vector3D(x3, minY, z1), new Vector3D(x4, maxY, z4)));
}
//.........这里部分代码省略.........
示例3: IsOverlapOverThreshold
public override bool IsOverlapOverThreshold(BoundingBoxD worldAabb, float thresholdPercentage)
{
//Debug.Assert(
// worldAabb.Size.X > MyVoxelConstants.VOXEL_SIZE_IN_METRES &&
// worldAabb.Size.Y > MyVoxelConstants.VOXEL_SIZE_IN_METRES &&
// worldAabb.Size.Z > MyVoxelConstants.VOXEL_SIZE_IN_METRES,
// "One of the sides of queried AABB is too small compared to voxel size. Results will be unreliable.");
Vector3I minCorner, maxCorner;
MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref worldAabb.Min, out minCorner);
MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref worldAabb.Max, out maxCorner);
minCorner += StorageMin;
maxCorner += StorageMin;
Storage.ClampVoxelCoord(ref minCorner);
Storage.ClampVoxelCoord(ref maxCorner);
m_storageCache.Resize(minCorner, maxCorner);
Storage.ReadRange(m_storageCache, MyStorageDataTypeFlags.Content, 0, ref minCorner, ref maxCorner);
BoundingBoxD voxelBox;
//MyRenderProxy.DebugDrawAABB(worldAabb, Color.White, 1f, 1f, true);
var invFullVoxel = 1.0 / (double)MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT;
var voxelVolume = 1.0 / (double)MyVoxelConstants.VOXEL_VOLUME_IN_METERS;
double overlapContentVolume = 0.0;
var queryVolume = worldAabb.Volume;
//using (var batch = MyRenderProxy.DebugDrawBatchAABB(Matrix.Identity, new Color(Color.Green, 0.1f), true, true))
{
Vector3I coord, cache;
for (coord.Z = minCorner.Z, cache.Z = 0; coord.Z <= maxCorner.Z; coord.Z++, cache.Z++)
{
for (coord.Y = minCorner.Y, cache.Y = 0; coord.Y <= maxCorner.Y; coord.Y++, cache.Y++)
{
for (coord.X = minCorner.X, cache.X = 0; coord.X <= maxCorner.X; coord.X++, cache.X++)
{
MyVoxelCoordSystems.VoxelCoordToWorldAABB(PositionLeftBottomCorner, ref coord, out voxelBox);
if (worldAabb.Intersects(voxelBox))
{
var contentVolume = m_storageCache.Content(ref cache) * invFullVoxel * voxelVolume;
var overlapVolume = worldAabb.Intersect(voxelBox).Volume;
overlapContentVolume += contentVolume * overlapVolume;
//batch.Add(ref voxelBox);
}
}
}
}
}
var overlapVolumePercentage = overlapContentVolume / queryVolume;
//MyRenderProxy.DebugDrawText3D(worldAabb.Center, overlapVolumePercentage.ToString("0.000"), Color.White, 1f, false);
return overlapVolumePercentage >= thresholdPercentage;
}
示例4: IntersectInternalWStack
// To help debug even when using stackalloc
public unsafe bool IntersectInternalWStack(ref LineD line, MyCellCoord * stack, int stackSize) {
#else
int stackSize = MySparseOctree.EstimateStackSize(m_treeHeight);
MyCellCoord* stack = stackalloc MyCellCoord[stackSize];
#endif
var finalB = BoundingBoxD.CreateInvalid();
LineD result;
result.From = line.To;
result.To = line.From;
MyCellCoord data = new MyCellCoord(m_treeHeight + LeafLodCount, ref Vector3I.Zero);
int stackIdx = 0;
stack[stackIdx++] = data;
MyCellCoord cell = new MyCellCoord();
BoundingBoxI bb = new BoundingBoxI(new Vector3I(Vector3.Min(line.From, line.To)), new Vector3I(Vector3.Ceiling(Vector3.Max(line.From, line.To))));
double startOfft, endOfft;
while (stackIdx > 0)
{
Debug.Assert(stackIdx <= stackSize);
data = stack[--stackIdx];
cell.Lod = Math.Max(data.Lod - LeafLodCount, 0);
cell.CoordInLod = data.CoordInLod;
int lodDiff;
IMyOctreeLeafNode leaf;
if (m_contentLeaves.TryGetValue(cell.PackId64(), out leaf))
{
lodDiff = data.Lod;
var rangeMinInDataLod = bb.Min >> lodDiff;
var rangeMaxInDataLod = bb.Max >> lodDiff;
if (data.CoordInLod.IsInsideInclusive(ref rangeMinInDataLod, ref rangeMaxInDataLod))
{
var start = rangeMinInDataLod << data.Lod;
var end = (rangeMaxInDataLod) << data.Lod;
var leafBounds = new BoundingBoxD(start, end);
LineD ll;
leafBounds.Intersect(ref line, out ll);
if (leaf.Intersect(ref ll, out startOfft, out endOfft))
{
if (finalB.Contains(ll.From) == ContainmentType.Disjoint)
{
result.From = ll.From;
finalB.Include(ll.From);
}
if (finalB.Contains(ll.To) == ContainmentType.Disjoint)
{
result.To = ll.To;
finalB.Include(ll.To);
}
}
}
continue;
}
cell.Lod -= 1;
lodDiff = data.Lod - 1;
var node = m_contentNodes[cell.PackId64()];
var min = bb.Min >> lodDiff;
var max = bb.Max >> lodDiff;
var nodePositionInChild = data.CoordInLod << 1;
min -= nodePositionInChild;
max -= nodePositionInChild;
for (int i = 0; i < MyOctreeNode.CHILD_COUNT; ++i)
{
Vector3I childPosRelative;
ComputeChildCoord(i, out childPosRelative);
if (!childPosRelative.IsInsideInclusive(ref min, ref max))
continue;
BoundingBoxD nodeBounds;
nodeBounds.Min = childPosRelative + cell.CoordInLod << lodDiff;
nodeBounds.Max = nodeBounds.Min + (1 << data.Lod);
if (finalB.Contains(nodeBounds) == ContainmentType.Contains) continue;
if (!nodeBounds.Intersects(ref line))
continue;
if (node.HasChild(i))
{
Debug.Assert(stackIdx < stackSize);
stack[stackIdx++] = new MyCellCoord(data.Lod - 1, nodePositionInChild + childPosRelative);
}
}
}
if (!finalB.Valid) return false;
//.........这里部分代码省略.........