private void SetupDrillSensor(VRageMath.Matrix fromReference, int id, VRageMath.BoundingBox bb) { // grid size in meters per block float gridSize = sensors[id].CubeGrid.GridSize; // matrix from grid coordinate system to sensor coordinate system VRageMath.Matrix toSensor = new VRageMath.Matrix(); sensors[id].Orientation.GetMatrix(out toSensor); // matrix is orthogonal => transposed matrix = inversed matrix VRageMath.Matrix.Transpose(ref toSensor, out toSensor); VRageMath.Vector3[] corners = bb.GetCorners(); VRageMath.Vector3 diffMax = corners[1] - sensors[id].Position; VRageMath.Vector3 diffMin = corners[7] - sensors[id].Position; List <VRageMath.Vector3> .Enumerator enumerator = XUtils.Directions.GetEnumerator(); while (enumerator.MoveNext()) { VRageMath.Vector3 dir = enumerator.Current; VRageMath.Vector3 gridDir = VRageMath.Vector3.Transform(dir, fromReference); float lengthToMax = (diffMax * gridDir).Max(); float lengthToMin = (diffMin * gridDir).Max(); float offset = Sensors.getOffset(VRageMath.Vector3.Transform(gridDir, toSensor)); float value = _astroidDetectSize + (Math.Max(lengthToMax, lengthToMin) + offset) * gridSize; value = Math.Max(Math.Min(value, sensors.Max), sensors.Min); sensors.Extend(dir, id, value); } }