/// <summary> /// Determines which sector the emitting face of a radar is pointing at /// </summary> /// <param name="antenna"></param> /// <returns></returns> private Sector DetermineAntennaSector(IMySlimBlock antenna) { // Start with the default direction // The model antenna points in the +X, +Y, and -Z directions VRageMath.Vector3D direction = new VRageMath.Vector3D(1.0f, 1.0f, -1.0f); // Rotate this vector by the orientation of the block VRageMath.Vector3D rotated = VRageMath.Vector3D.Rotate( direction, antenna.FatBlock.LocalMatrix); _logger.debugLog("New radar's vector is " + rotated.ToString(), "DetermineAntennaSector"); return(SectorExtensions.ClassifyVector(rotated)); }
/// <summary> /// Goes through all tracks in the list and determines whether or not /// they can currently be seen. This function does not add or remove /// contacts from the list. That can only be done in ProcessAcquiredContacts. /// </summary> private void DoTrackingSweep() { //_logger.debugLog("Beginning sweep", "DoTrackingSweep"); Vector3D myPos = _grid.WorldAABB.Center; // Go through all current tracks and update their makers foreach (Track track in _allTracks.Values) { //_logger.debugLog($"For Track {track.trackId}", "DoTrackingSweep"); // If the entity is null, this track is only available on the // server so use the stored value. Otherwise get the most // up to date value if (track.ent != null) { //_logger.debugLog("Entity is not null", "DoTrackingSweep"); track.position = track.ent.WorldAABB.Center; } // Transform the coordinates into grid space so we // can compare it against our radar coverage VRageMath.Vector3D relative = VRageMath.Vector3D.Transform( track.position, _grid.WorldMatrixNormalizedInv); //Check that the sector is covered by our radars Sector sec = SectorExtensions.ClassifyVector(relative); if (IsSectorBlind(sec)) { //_logger.debugLog("Sector is blind", "DoTrackingSweep"); // If a contact is not trackable, clear its GPS marker ClearTrackMarker(track); continue; } // Vector to target Vector3D vecTo = track.position - myPos; // If the entity is available, calculate the cross-section // Otherwise we will use the stored value from the server if (track.ent != null) { track.xsec = EWMath.DetermineXSection(track.ent as IMyCubeGrid, vecTo); } double range = vecTo.Length(); double minxsec = EWMath.MinimumXSection( Constants.radarBeamWidths[(int)_assignedType], range); if (track.xsec < minxsec) { //_logger.debugLog("Cross-section not large enough", "DoTrackingSweep"); ClearTrackMarker(track); continue; } // TODO: raycast // If all of the previous checks passed, this contact should // be visible with a marker AddUpdateTrackMarker(track); } }