本文整理汇总了C#中BoundingBoxD.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBoxD.Intersects方法的具体用法?C# BoundingBoxD.Intersects怎么用?C# BoundingBoxD.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingBoxD
的用法示例。
在下文中一共展示了BoundingBoxD.Intersects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Contains
public bool Contains(IMyEntity entity)
{
switch (Shape)
{
case ProtectionAreaShape.Cube:
var boundingBox = new BoundingBoxD(new Vector3D(Center.X - Size, Center.Y - Size, Center.Z - Size), new Vector3D(Center.X + Size, Center.Y + Size, Center.Z + Size));
return boundingBox.Intersects(entity.WorldAABB);
case ProtectionAreaShape.Sphere:
var boundingSphere = new BoundingSphereD(Center, Size);
return boundingSphere.Intersects(entity.WorldAABB);
}
return false;
}
示例2: 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;
}
示例3: DefaultGizmoCloseEnough
public static bool DefaultGizmoCloseEnough(ref MatrixD invGridWorldMatrix, BoundingBoxD gizmoBox, float gridSize, float intersectionDistance)
{
//MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 0.0f), "Intersection distance = " + intersectionDistance, Color.Red, 1.0f);
var m = invGridWorldMatrix;
MyCharacter character = MySession.LocalCharacter;
if (character == null)
return false;
// Character head for measuring distance to intesection.
Vector3D originHead = character.GetHeadMatrix(true).Translation;
// Camera position adn direction. Used for ray cast to cube block box.
Vector3D originCamera = MySector.MainCamera.Position;
Vector3 direction = MySector.MainCamera.ForwardVector;
Vector3 localHead = Vector3D.Transform(originHead, m);
Vector3 localStart = Vector3D.Transform(originCamera, m);
Vector3 localEnd = Vector3D.Transform(originCamera + direction * intersectionDistance, m);
LineD line = new LineD(localStart, localEnd);
// AABB of added block
float inflate = 0.025f * gridSize;
gizmoBox.Inflate(inflate);
/*{
Vector4 blue = Color.Blue.ToVector4();
Matrix mtx = Matrix.Invert(invGridWorldMatrix);
MySimpleObjectDraw.DrawTransparentBox(ref mtx, ref gizmoBox, ref blue, MySimpleObjectRasterizer.Wireframe, 1, 0.04f);
}*/
double distance = double.MaxValue;
if (gizmoBox.Intersects(line, out distance))
{
// Distance from the player's head to the gizmo box.
double distanceToPlayer = gizmoBox.Distance(localHead);
return distanceToPlayer <= 5.0;
}
return false;
}
示例4: 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;
}
示例5: GeneratePhysicalShapeForBox
private void GeneratePhysicalShapeForBox(ref Vector3I increment, ref BoundingBoxD shapeBox)
{
if (!shapeBox.Intersects(PositionComp.WorldAABB))
return;
Vector3I minCorner, maxCorner;
MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref shapeBox.Min, out minCorner);
MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref shapeBox.Max, out maxCorner);
minCorner /= PHYSICS_SECTOR_SIZE_METERS;
maxCorner /= PHYSICS_SECTOR_SIZE_METERS;
for (var it = new Vector3I.RangeIterator(ref minCorner, ref maxCorner);
it.IsValid(); it.MoveNext())
{
ProfilerShort.Begin("Myplanet::create physics shape");
CreatePhysicsShape(ref increment, ref it);
ProfilerShort.End();
}
}
示例6: SpawnInventoryContainer
public bool SpawnInventoryContainer(bool spawnAboveEntity = true)
{
//TODO: this should not be here but we have to know if session is being closed if so then no new entity will be created.
// Entity closing method and event should have parameter with sessionIsClosing.
if (Sandbox.Game.World.MySession.Static == null || !Sandbox.Game.World.MySession.Static.Ready)
return false;
var ownerEntity = Entity as MyEntity;
for (int i = 0; i < ownerEntity.InventoryCount; ++i)
{
var inventory = ownerEntity.GetInventory(i);
if (inventory != null && inventory.GetItemsCount() > 0)
{
MyEntity inventoryOwner = Entity as MyEntity;
var worldMatrix = inventoryOwner.WorldMatrix;
if (spawnAboveEntity)
{
Vector3 upDir = -Sandbox.Game.GameSystems.MyGravityProviderSystem.CalculateNaturalGravityInPoint(inventoryOwner.PositionComp.GetPosition());
if (upDir == Vector3.Zero)
upDir = Vector3.Up;
upDir.Normalize();
Vector3 forwardDir = Vector3.CalculatePerpendicularVector(upDir);
var ownerPosition = worldMatrix.Translation;
var ownerAabb = inventoryOwner.PositionComp.WorldAABB;
for (int moveIter = 0; moveIter < 20; ++moveIter)
{
var newPosition = ownerPosition + 0.1f * moveIter * upDir + 0.1f * moveIter * forwardDir;
var aabb = new BoundingBoxD(newPosition - 0.25 * Vector3D.One, newPosition + 0.25 * Vector3D.One);
if (!aabb.Intersects(ref ownerAabb))
{
// Move newPosition a little to avoid collision with fractured pieces.
worldMatrix.Translation = newPosition + 0.25f * upDir;
break;
}
}
if (worldMatrix.Translation == ownerPosition)
worldMatrix.Translation += upDir + forwardDir;
}
else
{
var model = (inventoryOwner.Render.ModelStorage as MyModel);
if (model != null)
{
Vector3 modelCenter = model.BoundingBox.Center;
Vector3 translationToCenter = Vector3.Transform(modelCenter, worldMatrix);
worldMatrix.Translation = translationToCenter;
}
}
MyContainerDefinition entityDefinition;
if (!MyComponentContainerExtension.TryGetContainerDefinition(m_containerDefinition.TypeId, m_containerDefinition.SubtypeId, out entityDefinition))
{
System.Diagnostics.Debug.Fail("Container Definition: " + m_containerDefinition.ToString() + " was not found!");
return false;
}
MyEntity entity = MyEntities.CreateFromComponentContainerDefinitionAndAdd(entityDefinition.Id);
System.Diagnostics.Debug.Assert(entity != null);
if (entity == null)
return false;
entity.PositionComp.SetWorldMatrix(worldMatrix);
System.Diagnostics.Debug.Assert(inventoryOwner != null, "Owner is not set!");
if (inventoryOwner.InventoryCount == 1)
{
inventoryOwner.Components.Remove<MyInventoryBase>();
}
else
{
var aggregate = inventoryOwner.GetInventoryBase() as MyInventoryAggregate;
if (aggregate != null)
{
aggregate.RemoveComponent(inventory);
}
else
{
System.Diagnostics.Debug.Fail("Inventory owners indicates that it owns more inventories, but doesn't have aggregate?");
return false;
}
}
// Replaces bag default inventory with existing one.
entity.Components.Add<MyInventoryBase>(inventory);
inventory.RemoveEntityOnEmpty = true;
entity.Physics.LinearVelocity = Vector3.Zero;
entity.Physics.AngularVelocity = Vector3.Zero;
if (ownerEntity.Physics != null)
{
entity.Physics.LinearVelocity = ownerEntity.Physics.LinearVelocity;
entity.Physics.AngularVelocity = ownerEntity.Physics.AngularVelocity;
}
else if (ownerEntity is MyCubeBlock)
{
//.........这里部分代码省略.........
示例7: DefaultGizmoCloseEnough
public static bool DefaultGizmoCloseEnough(ref MatrixD invGridWorldMatrix, BoundingBoxD gizmoBox, float gridSize, float intersectionDistance)
{
//MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 0.0f), "Intersection distance = " + intersectionDistance, Color.Red, 1.0f);
var m = invGridWorldMatrix;
MyCharacter character = MySession.Static.LocalCharacter;
if (character == null)
return false;
// Character head for measuring distance to intesection.
Vector3D originHead = character.GetHeadMatrix(true).Translation;
// Camera position adn direction. Used for ray cast to cube block box.
Vector3D originCamera = MySector.MainCamera.Position;
Vector3 direction = MySector.MainCamera.ForwardVector;
double cameraHeadDist = (originHead - MySector.MainCamera.Position).Length();
Vector3 localHead = Vector3D.Transform(originHead, m);
Vector3 localStart = Vector3D.Transform(originCamera, m);
Vector3 localEnd = Vector3D.Transform(originCamera + direction * (intersectionDistance + (float)cameraHeadDist), m);
LineD line = new LineD(localStart, localEnd);
// AABB of added block
float inflate = 0.025f * gridSize;
gizmoBox.Inflate(inflate);
//{
// Color blue = Color.Blue;
// MatrixD mtx = MatrixD.Invert(invGridWorldMatrix);
// MySimpleObjectDraw.DrawTransparentBox(ref mtx, ref gizmoBox, ref blue, MySimpleObjectRasterizer.Wireframe, 1, 0.04f);
// MyRenderProxy.DebugDrawLine3D(originCamera, originCamera + direction * (intersectionDistance + (float)cameraHeadDist), Color.Red, Color.Red, false);
//}
double distance = double.MaxValue;
if (gizmoBox.Intersects(ref line, out distance))
{
// Distance from the player's head to the gizmo box.
double distanceToPlayer = gizmoBox.Distance(localHead);
if (MySession.Static.ControlledEntity is MyShipController)
{
if (MyCubeBuilder.Static.CubeBuilderState.CurrentBlockDefinition.CubeSize == MyCubeSize.Large)
return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistLargeSurvivalShip;
else
return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistSmallSurvivalShip;
}
else
{
if (MyCubeBuilder.Static.CubeBuilderState.CurrentBlockDefinition.CubeSize == MyCubeSize.Large)
return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistLargeSurvivalCharacter;
else
return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistSmallSurvivalCharacter;
}
}
return false;
}