private void CreateHalfExtents() { _oldGridHalfExtents = DsState.State.GridHalfExtents; var myAabb = MyGrid.PositionComp.LocalAABB; var shieldGrid = MyGrid; var expandedAabb = myAabb; if (ShieldComp.GetSubGrids.Count > 1) { foreach (var grid in ShieldComp.GetSubGrids) { if (grid == null || grid == shieldGrid) { continue; } var shieldMatrix = shieldGrid.PositionComp.WorldMatrixNormalizedInv; var gQuaternion = Quaternion.CreateFromRotationMatrix(grid.WorldMatrix); var gOriBBoxD = new MyOrientedBoundingBox(grid.PositionComp.WorldAABB.Center, grid.PositionComp.LocalAABB.HalfExtents, gQuaternion); gOriBBoxD.Transform(shieldMatrix); expandedAabb.Include(gOriBBoxD.GetAABB()); } } if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield) { var extend = DsSet.Settings.ExtendFit ? 2 : 1; var fortify = DsSet.Settings.FortifyShield ? 3 : 1; var size = expandedAabb.HalfExtents.Max() * fortify; var scaler = 4; if (shieldGrid.GridSizeEnum == MyCubeSize.Small && !DsSet.Settings.ExtendFit) { scaler = 5; } var vectorSize = new Vector3D(size, size, size); var fudge = shieldGrid.GridSize * scaler * extend; var extentsDiff = DsState.State.GridHalfExtents.LengthSquared() - vectorSize.LengthSquared(); if (extentsDiff < -1 || extentsDiff > 1 || DsState.State.GridHalfExtents == Vector3D.Zero || !fudge.Equals(DsState.State.ShieldFudge)) { DsState.State.GridHalfExtents = vectorSize; } DsState.State.ShieldFudge = fudge; } else { var blockHalfSize = MyGrid.GridSize * 0.5; DsState.State.ShieldFudge = 0f; var extentsDiff = DsState.State.GridHalfExtents.LengthSquared() - expandedAabb.HalfExtents.LengthSquared(); var overThreshold = extentsDiff <-blockHalfSize || extentsDiff> blockHalfSize; if (overThreshold || DsState.State.GridHalfExtents == Vector3D.Zero) { DsState.State.GridHalfExtents = expandedAabb.HalfExtents; } } _halfExtentsChanged = !DsState.State.GridHalfExtents.Equals(_oldGridHalfExtents); if (_halfExtentsChanged) { _adjustShape = true; } }
public void CreateHalfExtents(bool forceUpdate = false, bool growOnly = false) { _oldGridHalfExtents = DsState.State.GridHalfExtents; var myAabb = MyGrid.PositionComp.LocalAABB; var shieldGrid = MyGrid; var expandedAabb = myAabb; if (ShieldComp.SubGrids.Count > 1) { foreach (var grid in ShieldComp.SubGrids.Keys) { using (grid.Pin()) { if (grid == shieldGrid || grid.MarkedForClose) { continue; } var shieldMatrix = shieldGrid.PositionComp.WorldMatrixNormalizedInv; var gQuaternion = Quaternion.CreateFromRotationMatrix(grid.WorldMatrix); var gOriBBoxD = new MyOrientedBoundingBox(grid.PositionComp.WorldAABB.Center, grid.PositionComp.LocalAABB.HalfExtents, gQuaternion); gOriBBoxD.Transform(shieldMatrix); expandedAabb.Include(gOriBBoxD.GetAABB()); } } } if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield) { var fortify = DsSet.Settings.FortifyShield ? 3 : 1; var fit = (float)UtilsStatic.GetFit(DsSet.Settings.Fit) * 0.5f; var scaler = 4f; if (shieldGrid.GridSizeEnum == MyCubeSize.Small && DsSet.Settings.Fit < 15) { scaler = 5; } var size = (expandedAabb.HalfExtents.Max() * fortify) * fit; var vectorSize = new Vector3D(size, size, size); var fudge = shieldGrid.GridSize * scaler; var extentsDiff = DsState.State.GridHalfExtents.LengthSquared() - vectorSize.LengthSquared(); if (extentsDiff < -1 || extentsDiff > 1 || DsState.State.GridHalfExtents == Vector3D.Zero || !fudge.Equals(DsState.State.ShieldFudge)) { DsState.State.GridHalfExtents = vectorSize; } DsState.State.ShieldFudge = fudge; } else { var offset = MyGrid.GridSize * 0.01; DsState.State.ShieldFudge = 0f; var extentsDiff = DsState.State.GridHalfExtents.Length() - expandedAabb.HalfExtents.Length(); var overThreshold = extentsDiff <-offset || extentsDiff> offset || forceUpdate; //first grow, second shrink if (overThreshold || DsState.State.GridHalfExtents == Vector3D.Zero) { DsState.State.GridHalfExtents = expandedAabb.HalfExtents; } } _halfExtentsChanged = !DsState.State.GridHalfExtents.Equals(_oldGridHalfExtents) || (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield) && SettingsUpdated; if (_halfExtentsChanged || SettingsUpdated) { _adjustShape = true; } }