public List <PositionComponent> CollectEntity_ForwardRectangle(Vector3FP position, Vector2FP direction, FixPoint length, FixPoint width, int exclude_id) { m_collection.Clear(); Vector2FP start_position = new Vector2FP(position); Vector2FP end_position = start_position + direction * length; ComputeAreaXZ(start_position, end_position); Vector2FP side = direction.Perpendicular(); width = width >> 1; Cell cell; PositionComponent cmp; Vector2FP offset; for (int x = m_min_x; x <= m_max_x; ++x) { for (int z = m_min_z; z <= m_max_z; ++z) { cell = m_cells[x, z]; for (int i = 0; i < cell.m_entities.Count; ++i) { cmp = cell.m_entities[i]; if (cmp.GetOwnerEntityID() == exclude_id) { continue; } offset.x = cmp.CurrentPosition.x - position.x; offset.z = cmp.CurrentPosition.z - position.z; FixPoint component = offset.Dot(ref direction); FixPoint radius = cmp.Radius; if (component < -radius || component > length + radius) { continue; } component = offset.Dot(ref side); if (component < FixPoint.Zero) { component = -component; } if (component > width + radius) { continue; } m_collection.Add(cmp); } } } return(m_collection); }
public List <PositionComponent> CollectEntity_ForwardRectangle(Vector3FP position, Vector2FP direction, FixPoint length, FixPoint width, int exclude_id) { m_collection.Clear(); Vector2FP side = direction.Perpendicular(); width = width >> 1; PositionComponent cmp; Vector2FP offset; for (int i = 0; i < m_entities.Count; ++i) { cmp = m_entities[i]; if (cmp.GetOwnerEntityID() == exclude_id) { continue; } offset.x = cmp.CurrentPosition.x - position.x; offset.z = cmp.CurrentPosition.z - position.z; FixPoint component = offset.Dot(ref direction); FixPoint radius = cmp.Radius; if (component < -radius || component > length + radius) { continue; } component = offset.Dot(ref side); if (component < FixPoint.Zero) { component = -component; } if (component > width + radius) { continue; } m_collection.Add(cmp); } return(m_collection); }