コード例 #1
0
        public List <PositionComponent> CollectEntity_ForwardSector(Vector3FP position, Vector2FP facing, FixPoint radius, FixPoint degree, int exclude_id)
        {
            FixPoint cos = FixPoint.Cos(FixPoint.Degree2Radian(degree >> 1));

            m_collection.Clear();
            Vector2FP         source = new Vector2FP(position.x, position.z);
            Vector2FP         target = new Vector2FP();
            PositionComponent cmp;

            for (int i = 0; i < m_entities.Count; ++i)
            {
                cmp = m_entities[i];
                if (cmp.GetOwnerEntityID() == exclude_id)
                {
                    continue;
                }
                target.x = cmp.CurrentPosition.x;
                target.z = cmp.CurrentPosition.z;
                Vector2FP to_target = target - source;
                FixPoint  distance  = to_target.FastNormalize();
                if (distance > radius + cmp.Radius)
                {
                    continue;
                }
                if (to_target.Dot(ref facing) < cos)
                {
                    continue;
                }
                m_collection.Add(cmp);
            }
            return(m_collection);
        }
コード例 #2
0
        public List <PositionComponent> CollectEntity_ForwardSector(Vector3FP position, Vector2FP facing, FixPoint radius, FixPoint degree, int exclude_id)
        {
            FixPoint cos = FixPoint.Cos(FixPoint.Degree2Radian(degree >> 1));

            m_collection.Clear();
            Vector2FP start_position = new Vector2FP(position.x - radius, position.z - radius);
            Vector2FP end_position   = new Vector2FP(position.x + radius, position.z + radius);

            ComputeAreaXZ(start_position, end_position);
            Cell              cell;
            Vector2FP         source = new Vector2FP(position.x, position.z);
            Vector2FP         target = new Vector2FP();
            PositionComponent cmp;

            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;
                        }
                        target.x = cmp.CurrentPosition.x;
                        target.z = cmp.CurrentPosition.z;
                        Vector2FP to_target = target - source;
                        FixPoint  distance  = to_target.FastNormalize();
                        if (distance > radius + cmp.Radius)
                        {
                            continue;
                        }
                        if (to_target.Dot(ref facing) < cos)
                        {
                            continue;
                        }
                        m_collection.Add(cmp);
                    }
                }
            }
            return(m_collection);
        }