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 || !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 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(); }