本文整理汇总了C#中BoundingSphereD.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingSphereD.Intersects方法的具体用法?C# BoundingSphereD.Intersects怎么用?C# BoundingSphereD.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingSphereD
的用法示例。
在下文中一共展示了BoundingSphereD.Intersects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: IsInStoppingDistance
private bool IsInStoppingDistance()
{
int currentIndex = m_waypoints.IndexOf(CurrentWaypoint);
double currentDstSqr = (WorldMatrix.Translation - CurrentWaypoint.Coords).LengthSquared();
double dstError = CubeGrid.GridSize * 3;
if (m_automaticBehaviour != null && m_automaticBehaviour.IsActive)
{
dstError = m_automaticBehaviour.WaypointThresholdDistance;
}
else if (m_waypointThresholdDistance > 0)
{
dstError = m_waypointThresholdDistance;
}
else if (m_dockingModeEnabled || (m_currentFlightMode == FlightMode.OneWay && currentIndex == m_waypoints.Count - 1))
{
if (CubeGrid.GridSize >= 0.5f)
dstError = CubeGrid.GridSize * 0.25;
else
dstError = CubeGrid.GridSize;
}
if (MyFakes.ENABLE_VR_REMOTE_CONTROL_WAYPOINTS_FAST_MOVEMENT)
{
// Check if movement from previous position to current position intersects waypoint sphere.
if (currentDstSqr < dstError * dstError)
return true;
double prevDstSqr = (m_previousWorldPosition - CurrentWaypoint.Coords).LengthSquared();
if (prevDstSqr < dstError * dstError)
return true;
var dir = WorldMatrix.Translation - m_previousWorldPosition;
double rayLength = dir.Normalize();
if (rayLength > 0.01)
{
RayD ray = new RayD(m_previousWorldPosition, dir);
BoundingSphereD sphere = new BoundingSphereD(CurrentWaypoint.Coords, dstError);
double? intersection = sphere.Intersects(ray);
return (intersection != null) ? intersection.Value <= rayLength : false;
}
}
return currentDstSqr < dstError * dstError;
}
示例3: Drill
public bool Drill(bool collectOre = true, bool performCutout = true)
{
ProfilerShort.Begin("MyDrillBase::Drill()");
bool drillingSuccess = false;
MySoundPair sound = null;
if ((m_drillEntity.Parent != null) && (m_drillEntity.Parent.Physics != null) && !m_drillEntity.Parent.Physics.Enabled)
return false;
if (performCutout)
{
var entitiesInRange = m_sensor.EntitiesInRange;
foreach (var entry in entitiesInRange)
{
drillingSuccess = false;
var entity = entry.Value.Entity;
if (entity.MarkedForClose)
continue;
if (entity is MyCubeGrid)
{
var grid = entity as MyCubeGrid;
if (grid.Physics != null && grid.Physics.Enabled)
{
drillingSuccess = TryDrillBlocks(grid, entry.Value.DetectionPoint, !Sync.IsServer);
}
if (drillingSuccess)
{
m_initialHeatup = false;
sound = m_sounds.MetalLoop;
CreateParticles(entry.Value.DetectionPoint, false, true, false);
}
}
else if (entity is MyVoxelBase)
{
ProfilerShort.Begin("Drill voxel map");
var voxels = entity as MyVoxelBase;
drillingSuccess = TryDrillVoxels(voxels, entry.Value.DetectionPoint, collectOre, !Sync.IsServer);
ProfilerShort.BeginNextBlock("Create particles");
if (drillingSuccess)
{
sound = m_sounds.RockLoop;
CreateParticles(entry.Value.DetectionPoint, true, false, true);
}
ProfilerShort.End();
}
else if (entity is MyFloatingObject)
{
var sphere = (BoundingSphereD)m_cutOut.Sphere;
sphere.Radius *= 1.33f;
if (entity.GetIntersectionWithSphere(ref sphere))
{
MyFloatingObject flObj = entity as MyFloatingObject;
if (Sync.IsServer)
{
if (flObj.Item.Content.TypeId == typeof(MyObjectBuilder_Ore))
{
IMyInventoryOwner invOwn = m_drillEntity as IMyInventoryOwner;
if (invOwn == null)
invOwn = (m_drillEntity as MyHandDrill).Owner as IMyInventoryOwner;
invOwn.GetInventory(0).TakeFloatingObject(flObj);
}
else
(entity as MyFloatingObject).DoDamage(70, MyDamageType.Drill, true);
}
drillingSuccess = true;
}
}
else if (entity is MyCharacter)
{
var sphere = (BoundingSphereD)m_cutOut.Sphere;
sphere.Radius *= (4 / 5f);
var character = entity as MyCharacter;
if (entity.GetIntersectionWithSphere(ref sphere))
{
//MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true);
if (Sync.IsServer)
character.DoDamage(20, MyDamageType.Drill, true);
drillingSuccess = true;
}
else
{
BoundingSphereD headSphere = new BoundingSphereD(character.PositionComp.WorldMatrix.Translation + character.WorldMatrix.Up * 1.25f, 0.6f);
//MyRenderProxy.DebugDrawSphere(headSphere.Center, headSphere.Radius, Color.Red.ToVector3(), 1, false);
if (headSphere.Intersects(sphere))
{
//MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true);
if (Sync.IsServer)
character.DoDamage(20, MyDamageType.Drill, true);
drillingSuccess = true;
}
}
}
if (drillingSuccess)
{
m_lastContactTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
}
}
}
//.........这里部分代码省略.........
示例4: Drill
//.........这里部分代码省略.........
{
MyFloatingObject flObj = entity as MyFloatingObject;
if (Sync.IsServer)
{
if (flObj.Item.Content.TypeId == typeof(MyObjectBuilder_Ore))
{
var invOwn = (m_drillEntity != null && m_drillEntity.HasInventory) ? m_drillEntity : null;
if (invOwn == null)
invOwn = (m_drillEntity as MyHandDrill).Owner;
System.Diagnostics.Debug.Assert((invOwn.GetInventory(0) as MyInventory) != null, "Null or unexpected inventory type!");
(invOwn.GetInventory(0) as MyInventory).TakeFloatingObject(flObj);
}
else
(entity as MyFloatingObject).DoDamage(70, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
}
drillingSuccess = true;
}
}
else if (entity is MyCharacter)
{
var sphere = (BoundingSphereD)m_cutOut.Sphere;
sphere.Radius *= 0.8f;
var character = entity as MyCharacter;
if (targetMaterial == MyStringHash.NullOrEmpty)
targetMaterial = MyStringHash.GetOrCompute((entity as MyCharacter).Definition.PhysicalMaterial);
if (entity.GetIntersectionWithSphere(ref sphere))
{
//MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true);
//damage tracking
if ((m_drillEntity is MyHandDrill) && (m_drillEntity as MyHandDrill).Owner == MySession.Static.LocalCharacter && character != MySession.Static.LocalCharacter && character.IsDead == false)
MySession.Static.TotalDamageDealt += 20;
if (Sync.IsServer)
character.DoDamage(20, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
drillingSuccess = true;
}
else
{
BoundingSphereD headSphere = new BoundingSphereD(character.PositionComp.WorldMatrix.Translation + character.WorldMatrix.Up * 1.25f, 0.6f);
//MyRenderProxy.DebugDrawSphere(headSphere.Center, headSphere.Radius, Color.Red.ToVector3(), 1, false);
if (headSphere.Intersects(sphere))
{
//MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true);
//damage tracking
if ((m_drillEntity is MyHandDrill) && (m_drillEntity as MyHandDrill).Owner == MySession.Static.LocalCharacter && character != MySession.Static.LocalCharacter && character.IsDead == false)
MySession.Static.TotalDamageDealt += 20;
if (Sync.IsServer)
character.DoDamage(20, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
drillingSuccess = true;
}
}
}
if (drillingSuccess)
{
m_lastContactTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
float dist = Vector3.DistanceSquared(entry.Value.DetectionPoint, Sensor.Center);
if (targetMaterial != null && targetMaterial != MyStringHash.NullOrEmpty && dist < distanceBest)
{
bestMaterial = targetMaterial;
distanceBest = dist;
}
}
}
if (bestMaterial != null && bestMaterial != MyStringHash.NullOrEmpty)
{
sound = MyMaterialPropertiesHelper.Static.GetCollisionCue(MyMaterialPropertiesHelper.CollisionType.Start, m_drillMaterial, bestMaterial);
if (sound == null || sound == MySoundPair.Empty)//target material was not set in definition - using metal/rock sound
{
if (targetIsBlock)
{
bestMaterial = m_metalMaterial;
}
else
{
bestMaterial = m_rockMaterial;
}
}
sound = MyMaterialPropertiesHelper.Static.GetCollisionCue(MyMaterialPropertiesHelper.CollisionType.Start, m_drillMaterial, bestMaterial);
}
}
if (sound != null && sound != MySoundPair.Empty)
StartLoopSound(sound);
else
StartIdleSound(m_idleSoundLoop);
if (!IsDrilling)
{
IsDrilling = true;
m_animationLastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
}
ProfilerShort.End();
return drillingSuccess;
}