public void Dispose() { if (CharacterProxy != null) { CharacterProxy.Dispose(); CharacterProxy = null; } if (CharacterPhantom != null) { CharacterPhantom.Dispose(); CharacterPhantom = null; } if (CharacterRigidBody != null) { if (CharacterRigidBody.GetRigidBody() != null) { CharacterRigidBody.GetRigidBody().ContactPointCallback -= RigidBody_ContactPointCallback; } CharacterRigidBody.Dispose(); CharacterRigidBody = null; } m_characterShape.RemoveReference(); m_characterCollisionShape.RemoveReference(); m_crouchShape.RemoveReference(); }
private void ReplaceShape(HkShape shape) { if (shape.IsZero) { IsEmpty = true; } else { RigidBody.SetShape(shape); shape.RemoveReference(); m_voxelMap.RaisePhysicsChanged(); } }
public void Dispose() { if (CharacterProxy != null) { CharacterProxy.Dispose(); CharacterProxy = null; } if (CharacterPhantom != null) { CharacterPhantom.Dispose(); CharacterPhantom = null; } if (CharacterRigidBody != null) { CharacterRigidBody.Dispose(); CharacterRigidBody = null; } m_characterShape.RemoveReference(); m_characterCollisionShape.RemoveReference(); m_crouchShape.RemoveReference(); }
protected override void OnComplete() { base.OnComplete(); if (MyPrecalcComponent.Loaded && !m_isCancelled) { m_args.TargetPhysics.OnTaskComplete(m_args.GeometryCell, m_result); } if (!m_isCancelled) { m_args.Tracker.Complete(m_args.GeometryCell); } if (!m_result.IsZero) { m_result.RemoveReference(); } m_args = default(Args); m_isCancelled = false; m_result = HkShape.Empty; m_instancePool.Deallocate(this); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( BlockDefinition.ResourceSinkGroup, BlockDefinition.RequiredPowerInput, this.CalculateRequiredPowerInput); ResourceSink = sinkComp; base.Init(objectBuilder, cubeGrid); m_items = new List<ToolbarItem>(2); for (int i = 0; i < 2; i++) { m_items.Add(new ToolbarItem() { EntityID = 0 }); } Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1); Toolbar.DrawNumbers = false; var builder = (MyObjectBuilder_SensorBlock)objectBuilder; m_fieldMin.Value = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One); m_fieldMax.Value = Vector3.Clamp(builder.FieldMax, Vector3.One, new Vector3(MaxRange)); PlayProximitySound = builder.PlaySound; DetectPlayers = builder.DetectPlayers; DetectFloatingObjects = builder.DetectFloatingObjects; DetectSmallShips = builder.DetectSmallShips; DetectLargeShips = builder.DetectLargeShips; DetectStations = builder.DetectStations; DetectAsteroids = builder.DetectAsteroids; DetectOwner = builder.DetectOwner; DetectFriendly = builder.DetectFriendly; DetectNeutral = builder.DetectNeutral; DetectEnemy = builder.DetectEnemy; m_active.Value = builder.IsActive; Toolbar.Init(builder.Toolbar, this); for (int i = 0; i < 2; i++) { var item = Toolbar.GetItemAtIndex(i); if (item == null) continue; m_items.RemoveAt(i); m_items.Insert(i, ToolbarItem.FromItem(item)); } Toolbar.ItemChanged += Toolbar_ItemChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged; ResourceSink.RequiredInputChanged += Receiver_RequiredInputChanged; ResourceSink.Update(); m_fieldShape = GetHkShape(); OnClose += delegate(MyEntity self) { m_fieldShape.RemoveReference(); }; m_gizmoColor = MySandboxGame.IsDirectX11 ? new Vector4(0.35f, 0, 0, 0.5f) : new Vector4(0.1f, 0, 0, 0.1f); }
public override void UpdateAfterSimulation10() { base.UpdateAfterSimulation10(); if (!Sync.IsServer || !IsWorking || !PowerReceiver.IsPowered) { return; } var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up); var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax + m_fieldMin) * 0.5f, rotation1); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field"); if (m_recreateField) { m_recreateField = false; m_fieldShape.RemoveReference(); m_fieldShape = GetHkShape(); PowerReceiver.Update(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); var boundingBox = new BoundingBoxD(m_fieldMin, m_fieldMax).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition()); m_potentialPenetrations.Clear(); MyGamePruningStructure.GetAllTopMostEntitiesInBox <MyEntity>(ref boundingBox, m_potentialPenetrations); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics"); LastDetectedEntity = null; if (IsActive) { bool empty = true; foreach (var entity in m_potentialPenetrations) { if (ShouldDetect(entity)) { if (entity.Physics == null || !entity.Physics.Enabled) { continue; } Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (entity.Physics.RigidBody != null) { shape2 = entity.Physics.RigidBody.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; if (entity is MyVoxelMap) { var voxel = entity as MyVoxelMap; posDiff -= voxel.Storage.Size / 2; } } else if (entity.Physics.CharacterProxy != null) { shape2 = entity.Physics.CharacterProxy.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; } else { continue; } if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; empty = false; break; } } } if (empty) { IsActive = false; } } else { foreach (var entity in m_potentialPenetrations) { if (ShouldDetect(entity)) { if (entity.Physics == null || !entity.Physics.Enabled) { continue; } Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (entity.Physics.RigidBody != null) { shape2 = entity.Physics.RigidBody.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; if (entity is MyVoxelMap) { var voxel = entity as MyVoxelMap; posDiff -= voxel.Storage.Size / 2; } } else if (entity.Physics.CharacterProxy != null) { shape2 = entity.Physics.CharacterProxy.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; } else { continue; } if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; IsActive = true; break; } } } } m_potentialPenetrations.Clear(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); m_items = new List <ToolbarItem>(2); for (int i = 0; i < 2; i++) { m_items.Add(new ToolbarItem() { EntityID = 0 }); } Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1); Toolbar.DrawNumbers = false; var builder = (MyObjectBuilder_SensorBlock)objectBuilder; m_fieldMin = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One); m_fieldMax = Vector3.Clamp(builder.FieldMax, Vector3.One, new Vector3(MaxRange)); PlayProximitySound = builder.PlaySound; DetectPlayers = builder.DetectPlayers; DetectFloatingObjects = builder.DetectFloatingObjects; DetectSmallShips = builder.DetectSmallShips; DetectLargeShips = builder.DetectLargeShips; DetectStations = builder.DetectStations; DetectAsteroids = builder.DetectAsteroids; DetectOwner = builder.DetectOwner; DetectFriendly = builder.DetectFriendly; DetectNeutral = builder.DetectNeutral; DetectEnemy = builder.DetectEnemy; m_active = builder.IsActive; Toolbar.Init(builder.Toolbar, this); for (int i = 0; i < 2; i++) { var item = Toolbar.GetItemAtIndex(i); if (item == null) { continue; } m_items.RemoveAt(i); m_items.Insert(i, ToolbarItem.FromItem(item)); } Toolbar.ItemChanged += Toolbar_ItemChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; PowerReceiver = new MyPowerReceiver( MyConsumerGroupEnum.Utility, false, BlockDefinition.RequiredPowerInput, this.CalculateRequiredPowerInput); PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged; PowerReceiver.RequiredInputChanged += Receiver_RequiredInputChanged; PowerReceiver.Update(); m_fieldShape = GetHkShape(); OnClose += delegate(MyEntity self) { m_fieldShape.RemoveReference(); }; }
private static MyEntity SpawnBagAround(MyEntity itemOwner, MyContainerDefinition bagDefinition, int sideCheckCount = 3, int frontCheckCount = 2, int upCheckCount = 5, float stepSize = 1f) { MatrixD xd; Vector3D?nullable = null; MyModel modelOnlyData = null; foreach (MyContainerDefinition.DefaultComponent component in bagDefinition.DefaultComponents) { if (typeof(MyObjectBuilder_ModelComponent).IsAssignableFrom((System.Type)component.BuilderType)) { MyComponentDefinitionBase componentDefinition = null; MyStringHash subtypeId = bagDefinition.Id.SubtypeId; if (component.SubtypeId != null) { subtypeId = component.SubtypeId.Value; } if (MyComponentContainerExtension.TryGetComponentDefinition(component.BuilderType, subtypeId, out componentDefinition)) { MyModelComponentDefinition definition = componentDefinition as MyModelComponentDefinition; if (definition != null) { modelOnlyData = MyModels.GetModelOnlyData(definition.Model); } } break; } } if (modelOnlyData == null) { return(null); } float radius = modelOnlyData.BoundingBox.HalfExtents.Max(); HkShape shape = (HkShape) new HkSphereShape(radius); try { Vector3 vector3; Vector3 vector5; Vector3 vector6; int num4; Vector3D vectord3; int num5; Vector3D translation = itemOwner.PositionComp.WorldMatrix.Translation; float num2 = radius * stepSize; Vector3 up = -MyGravityProviderSystem.CalculateNaturalGravityInPoint(itemOwner.PositionComp.WorldMatrix.Translation); if (up == Vector3.Zero) { up = Vector3.Up; } else { up.Normalize(); } up.CalculatePerpendicularVector(out vector3); Vector3 vector4 = Vector3.Cross(vector3, up); vector4.Normalize(); Quaternion identity = Quaternion.Identity; Vector3[] vectorArray = new Vector3[] { vector3, vector4, -vector3, -vector4 }; Vector3[] vectorArray2 = new Vector3[] { vector4, -vector3, -vector4, vector3 }; int index = 0; goto TR_0026; TR_000D: if (nullable == null) { MyOrientedBoundingBoxD xd3 = new MyOrientedBoundingBoxD(itemOwner.PositionComp.LocalAABB, itemOwner.PositionComp.WorldMatrix); Vector3D[] corners = new Vector3D[8]; xd3.GetCorners(corners, 0); float minValue = float.MinValue; Vector3D[] vectordArray2 = corners; int num8 = 0; while (true) { if (num8 >= vectordArray2.Length) { nullable = new Vector3D?(itemOwner.PositionComp.WorldMatrix.Translation); if (minValue > 0f) { nullable = new Vector3D?(xd3.Center + (minValue * up)); } break; } float num9 = Vector3.Dot((Vector3)(vectordArray2[num8] - xd3.Center), up); minValue = Math.Max(minValue, num9); num8++; } } goto TR_0003; TR_000E: index++; goto TR_0026; TR_000F: num4++; goto TR_0022; TR_0010: num5++; TR_001E: while (true) { if (num5 >= sideCheckCount) { goto TR_000F; } else if (nullable == null) { for (int i = 0; (i < upCheckCount) && (nullable == null); i++) { Vector3D pos = (vectord3 + ((num5 * num2) * vector6)) + ((i * num2) * up); if (MyEntities.IsInsideWorld(pos) && !MyEntities.IsShapePenetrating(shape, ref pos, ref identity, 15)) { BoundingSphereD sphere = new BoundingSphereD(pos, (double)radius); if (MySession.Static.VoxelMaps.GetOverlappingWithSphere(ref sphere) == null) { nullable = new Vector3D?(pos); break; } } } } else { goto TR_000F; } break; } goto TR_0010; TR_0022: while (true) { if (num4 >= frontCheckCount) { goto TR_000E; } else if (nullable == null) { vectord3 = (((translation + (0.25f * vector5)) + (radius * vector5)) + ((num4 * num2) * vector5)) - (((0.5f * (sideCheckCount - 1)) * num2) * vector6); num5 = 0; } else { goto TR_000E; } break; } goto TR_001E; TR_0026: while (true) { if (index >= vectorArray.Length) { goto TR_000D; } else if (nullable == null) { vector5 = vectorArray[index]; vector6 = vectorArray2[index]; num4 = 0; } else { goto TR_000D; } break; } goto TR_0022; } finally { shape.RemoveReference(); } TR_0003: xd = itemOwner.PositionComp.WorldMatrix; xd.Translation = nullable.Value; MyEntity entity = MyEntities.CreateFromComponentContainerDefinitionAndAdd(bagDefinition.Id, false, true); if (entity == null) { return(null); } entity.PositionComp.SetWorldMatrix(xd, null, false, true, true, false, false, false); entity.Physics.LinearVelocity = Vector3.Zero; entity.Physics.AngularVelocity = Vector3.Zero; return(entity); }
public override void UpdateAfterSimulation10() { base.UpdateAfterSimulation10(); if (!Sync.IsServer || !IsWorking || !ResourceSink.IsPowered) { return; } var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up); var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax + m_fieldMin) * 0.5f, rotation1); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field"); if (m_recreateField) { m_recreateField = false; m_fieldShape.RemoveReference(); m_fieldShape = GetHkShape(); ResourceSink.Update(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); var boundingBox = new BoundingBoxD(m_fieldMin, m_fieldMax).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition()); m_potentialPenetrations.Clear(); MyGamePruningStructure.GetAllTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations); m_potentialVoxelPenetrations.Clear(); MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics"); LastDetectedEntity = null; if (IsActive) { bool empty = true; foreach (var entity in m_potentialPenetrations) { if (entity is MyVoxelBase) { continue; } if (ShouldDetect(entity)) { Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; empty = false; break; } } } } foreach (var entity in m_potentialVoxelPenetrations) { if (ShouldDetect(entity)) { Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; empty = false; break; } } } } if (empty) { IsActive = false; } } else { foreach (var entity in m_potentialPenetrations) { if (entity is MyVoxelBase) { continue; } if (ShouldDetect(entity)) { Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; IsActive = true; break; } } } } foreach (var entity in m_potentialVoxelPenetrations) { if (ShouldDetect(entity)) { Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; IsActive = true; break; } } } } } m_potentialPenetrations.Clear(); m_potentialVoxelPenetrations.Clear(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }
public override void UpdateAfterSimulation10() { base.UpdateAfterSimulation10(); if (!Sync.IsServer || !IsWorking) { return; } if (!ResourceSink.IsPowered) { if (ResourceSink.IsPowerAvailable(MyResourceDistributorComponent.ElectricityId, BlockDefinition.RequiredPowerInput)) { float origInput = ResourceSink.RequiredInput; ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, 0); ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, origInput); } else { return; } } var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up); var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax.Value + m_fieldMin.Value) * 0.5f, rotation1); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field"); if (m_recreateField) { m_recreateField = false; m_fieldShape.RemoveReference(); m_fieldShape = GetHkShape(); ResourceSink.Update(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); var boundingBox = new BoundingBoxD(m_fieldMin.Value, m_fieldMax.Value).Translate(PositionComp.LocalVolume.Center).TransformFast(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition()); m_potentialPenetrations.Clear(); MyGamePruningStructure.GetTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations); m_potentialVoxelPenetrations.Clear(); MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);//disabled until heightmap queries are finished VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics"); LastDetectedEntity = null; bool empty = true; foreach (var entity in m_potentialPenetrations) { if (entity is MyVoxelBase) { //voxels are handled in different loop (becaose of planets) continue; } if (ShouldDetect(entity)) { Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; empty = false; break; } } } } if (DetectAsteroids) { foreach (var entity in m_potentialVoxelPenetrations) { var voxel = entity as MyVoxelPhysics; if (voxel != null) { Vector3D localPositionMin, localPositionMax; MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Min, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMin); MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Max, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMax); var aabb = new BoundingBox(localPositionMin, localPositionMax); aabb.Translate(voxel.StorageMin); if (voxel.Storage.Intersect(ref aabb) != ContainmentType.Disjoint) { LastDetectedEntity = voxel; empty = false; break; } } else { Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; empty = false; break; } } } } } IsActive = !empty; m_potentialPenetrations.Clear(); m_potentialVoxelPenetrations.Clear(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }
private bool SmallBlockConnectsToLarge(MySlimBlock smallBlock, ref BoundingBoxD smallBlockWorldAabb, MySlimBlock largeBlock, ref BoundingBoxD largeBlockWorldAabb) { Quaternion quaternion; Vector3D vectord2; BoundingBoxD box = smallBlockWorldAabb; box.Inflate((double)(-smallBlock.CubeGrid.GridSize / 4f)); if (!largeBlockWorldAabb.Intersects(box)) { Quaternion quaternion2; Vector3I addNormal = this.GetSmallBlockAddDirection(ref smallBlockWorldAabb, ref box, ref largeBlockWorldAabb); smallBlock.Orientation.GetQuaternion(out quaternion2); quaternion2 = Quaternion.CreateFromRotationMatrix(smallBlock.CubeGrid.WorldMatrix) * quaternion2; if (!MyCubeGrid.CheckConnectivitySmallBlockToLargeGrid(largeBlock.CubeGrid, smallBlock.BlockDefinition, ref quaternion2, ref addNormal)) { return(false); } } BoundingBoxD xd2 = smallBlockWorldAabb; xd2.Inflate((double)((2f * smallBlock.CubeGrid.GridSize) / 3f)); BoundingBoxD xd3 = xd2.Intersect(largeBlockWorldAabb); Vector3D center = xd3.Center; HkShape shape = (HkShape) new HkBoxShape((Vector3)xd3.HalfExtents); largeBlock.Orientation.GetQuaternion(out quaternion); quaternion = Quaternion.CreateFromRotationMatrix(largeBlock.CubeGrid.WorldMatrix) * quaternion; largeBlock.ComputeWorldCenter(out vectord2); bool flag = false; try { if (largeBlock.FatBlock == null) { HkShape shape3 = (HkShape) new HkBoxShape((largeBlock.BlockDefinition.Size * largeBlock.CubeGrid.GridSize) / 2f); flag = MyPhysics.IsPenetratingShapeShape(shape, ref center, ref Quaternion.Identity, shape3, ref vectord2, ref quaternion); shape3.RemoveReference(); } else { MyModel model = largeBlock.FatBlock.Model; if ((model == null) || (model.HavokCollisionShapes == null)) { HkShape shape2 = (HkShape) new HkBoxShape((largeBlock.BlockDefinition.Size * largeBlock.CubeGrid.GridSize) / 2f); flag = MyPhysics.IsPenetratingShapeShape(shape, ref center, ref Quaternion.Identity, shape2, ref vectord2, ref quaternion); shape2.RemoveReference(); } else { HkShape[] havokCollisionShapes = model.HavokCollisionShapes; for (int i = 0; i < havokCollisionShapes.Length; i++) { flag = MyPhysics.IsPenetratingShapeShape(shape, ref center, ref Quaternion.Identity, havokCollisionShapes[i], ref vectord2, ref quaternion); if (flag) { break; } } } } } finally { shape.RemoveReference(); } return(flag); }
private void DoDetection(bool useHead, bool doModelIntersection) { bool flag; if (ReferenceEquals(base.Character, MySession.Static.ControlledEntity)) { MyHud.SelectedObjectHighlight.RemoveHighlight(); } MatrixD xd = base.Character.GetHeadMatrix(false, true, false, false, false); Vector3D translation = xd.Translation; Vector3D forward = xd.Forward; if (!useHead) { Vector3D planePoint = xd.Translation - (xd.Forward * 0.3); if (!ReferenceEquals(base.Character, MySession.Static.LocalCharacter)) { translation = planePoint; forward = xd.Forward; } else { translation = MySector.MainCamera.WorldMatrix.Translation; forward = MySector.MainCamera.WorldMatrix.Forward; translation = MyUtils.LinePlaneIntersection(planePoint, (Vector3)forward, translation, (Vector3)forward); } } Vector3D to = translation + (forward * 2.5); base.StartPosition = translation; MatrixD transform = MatrixD.CreateTranslation(translation); HkShape shape = (HkShape) new HkSphereShape(this.ShapeRadius); IMyEntity objA = null; base.ShapeKey = uint.MaxValue; base.HitPosition = Vector3D.Zero; base.HitNormal = Vector3.Zero; base.HitMaterial = MyStringHash.NullOrEmpty; base.HitTag = null; this.m_hits.Clear(); Vector3 zero = (Vector3)Vector3D.Zero; try { bool flag2; bool flag3; int num; base.EnableDetectorsInArea(translation); MyPhysics.CastShapeReturnContactBodyDatas(to, shape, ref transform, 0, 0f, this.m_hits, true); this.m_rayOrigin = translation; this.m_rayDirection = forward; this.m_hits.Sort(new Comparison <MyPhysics.HitInfo>(this.CompareHits)); if (this.m_hits.Count <= 0) { goto TR_0012; } else { flag2 = false; flag3 = false; num = 0; } goto TR_002F; TR_0017: num++; TR_002F: while (true) { if (num >= this.m_hits.Count) { break; } HkRigidBody hkEntity = this.m_hits[num].HkHitInfo.Body; IMyEntity hitEntity = this.m_hits[num].HkHitInfo.GetHitEntity(); if (!ReferenceEquals(hitEntity, base.Character)) { int num1; if (hitEntity is MyEntitySubpart) { hitEntity = hitEntity.Parent; } if (((hkEntity == null) || (hitEntity == null)) || ReferenceEquals(hitEntity, base.Character)) { num1 = 0; } else { num1 = (int)!hkEntity.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT); } flag2 = (bool)num1; flag3 = (hitEntity != null) && (hitEntity.Physics != null); if (ReferenceEquals(objA, null) & flag2) { objA = hitEntity; base.ShapeKey = this.m_hits[num].HkHitInfo.GetShapeKey(0); } if (hitEntity is MyCubeGrid) { List <MyCube> list = (hitEntity as MyCubeGrid).RayCastBlocksAllOrdered(translation, to); if ((list != null) && (list.Count > 0)) { MySlimBlock cubeBlock = list[0].CubeBlock; if (cubeBlock.FatBlock != null) { flag3 = true; objA = cubeBlock.FatBlock; base.ShapeKey = 0; } } } if (!((base.HitMaterial.Equals(MyStringHash.NullOrEmpty) & flag2) & flag3)) { if (hkEntity == null) { num++; goto TR_0017; } else { zero = this.m_hits[num].GetFixedPosition(); } } else { base.HitBody = hkEntity; base.HitNormal = this.m_hits[num].HkHitInfo.Normal; base.HitPosition = this.m_hits[num].GetFixedPosition(); base.HitMaterial = hkEntity.GetBody().GetMaterialAt(base.HitPosition); zero = (Vector3)base.HitPosition; } break; } goto TR_0017; } } finally { shape.RemoveReference(); } TR_0012: flag = false; IMyUseObject interactive = objA as IMyUseObject; base.DetectedEntity = objA; if (objA != null) { MyUseObjectsComponentBase component = null; objA.Components.TryGet <MyUseObjectsComponentBase>(out component); if (component != null) { interactive = component.GetInteractiveObject(base.ShapeKey); } if (doModelIntersection) { LineD line = new LineD(translation, to); MyCharacter character = objA as MyCharacter; if (character == null) { MyIntersectionResultLineTriangleEx?nullable; if (objA.GetIntersectionWithLine(ref line, out nullable, IntersectionFlags.ALL_TRIANGLES)) { base.HitPosition = nullable.Value.IntersectionPointInWorldSpace; base.HitNormal = nullable.Value.NormalInWorldSpace; } } else if (character.GetIntersectionWithLine(ref line, ref base.CharHitInfo, IntersectionFlags.ALL_TRIANGLES)) { base.HitPosition = base.CharHitInfo.Triangle.IntersectionPointInWorldSpace; base.HitNormal = base.CharHitInfo.Triangle.NormalInWorldSpace; base.HitTag = base.CharHitInfo; } } } if (((interactive != null) && ((interactive.SupportedActions != UseActionEnum.None) && (Vector3D.Distance(translation, zero) < interactive.InteractiveDistance))) && ReferenceEquals(base.Character, MySession.Static.ControlledEntity)) { HandleInteractiveObject(interactive); base.UseObject = interactive; flag = true; } if (!flag) { base.UseObject = null; } base.DisableDetectors(); }