Exemple #1
0
        public Form4()
        {
            InitializeComponent();
            Circle circle = new Circle(new Vector3(), control_radius_);

            control_obj_.SetCollideShape(circle);
            control_obj_.SetPosition(new Vector3());
        }
Exemple #2
0
 private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
 {
     if (!IsValid())
     {
         return;
     }
     if (is_mouse_down_)
     {
         switch (left_button_function_)
         {
         case FunctionType.kMoveObj:
             Vector3 new_pos = new Vector3(e.X, 0, map_height_ - e.Y);
             control_obj_.SetPosition(new_pos);
             break;
         }
     }
 }
Exemple #3
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            line_end_ = new Point(e.X, e.Y);
            CellPos end = new CellPos();

            cell_manager_.GetCell(new Vector3(e.X, 0, map_height_ - e.Y), out end.row, out end.col);
            CellPos start = new CellPos();

            cell_manager_.GetCell(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), out start.row, out start.col);

            if (e.Button == MouseButtons.Left)
            {
                switch (left_button_function_)
                {
                case FunctionType.kSetStaticBlock:
                {
                    int  row         = end.row;
                    int  col         = end.col;
                    byte obstacle    = byte.Parse(obstacleType.Text);
                    byte oldObstacle = cell_manager_.GetCellStatus(row, col);
                    cell_manager_.SetCellStatus(row, col, obstacle);

                    if (map_patch_parser_.Exist(row, col))
                    {
                        map_patch_parser_.Update(row, col, obstacle);
                    }
                    else
                    {
                        map_patch_parser_.Update(row, col, obstacle, oldObstacle);
                    }

                    UpdateObstacleGraph();
                }
                break;

                case FunctionType.kHitPoint:
                {
                    long           stTime = TimeUtility.Instance.GetElapsedTimeUs();
                    List <CellPos> result = cell_manager_.GetCellsCrossByLine(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y),
                                                                              new Vector3(line_end_.X, 0, map_height_ - line_end_.Y));
                    long edTime = TimeUtility.Instance.GetElapsedTimeUs();
                    this.Text = "pos(" + line_start_.X + "," + line_start_.Y + "->" + line_end_.X + "," + line_end_.Y + ") GetCellsCrossByLine consume " + (edTime - stTime) + "us";
                    hit_points_.Clear();
                    foreach (CellPos pos in result)
                    {
                        hit_points_.Add(pos);
                    }
                }
                break;

                case FunctionType.kGetCell:
                {
                    byte obstacle = cell_manager_.GetCellStatus(end.row, end.col);
                    obstacleType.Text = obstacle.ToString();
                    this.Text         = "pos(" + e.X + "," + e.Y + ") cell(" + end.row + "," + end.col + ") obstacle:" + obstacle;
                }
                break;

                case FunctionType.kAddObj:
                {
                    TestSpaceObject obj = new TestSpaceObject(next_space_objid_);
                    ++next_space_objid_;
                    obj.SetPosition(new Vector3(e.X, 0, e.Y));
                    space_objs_.Add(obj);

                    prkdtree_.Clear();
                    kdtree_.Clear();
                    int objCt = space_objs_.Count;
                    if (objCt > 0)
                    {
                        ISpaceObject[] temp = new ISpaceObject[objCt];
                        for (int i = 0; i < objCt; ++i)
                        {
                            temp[i] = space_objs_[i];
                        }
                        long stTime1 = TimeUtility.Instance.GetElapsedTimeUs();
                        prkdtree_.Build(temp);
                        long edTime1 = TimeUtility.Instance.GetElapsedTimeUs();

                        long stTime2 = TimeUtility.Instance.GetElapsedTimeUs();
                        kdtree_.Build(temp);
                        long edTime2 = TimeUtility.Instance.GetElapsedTimeUs();

                        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                        stopWatch.Start();
                        cell_manager_.ClearDynamic();
                        foreach (ISpaceObject spaceObj in space_objs_)
                        {
                            List <CellPos> cells = cell_manager_.GetCellsInCircle(Transform(spaceObj.GetPosition()), 20);
                            foreach (CellPos cellpos in cells)
                            {
                                cell_manager_.SetCellStatus(cellpos.row, cellpos.col, BlockType.DYNAMIC_BLOCK);
                            }
                        }
                        stopWatch.Stop();


                        this.Text = "obj num " + objCt + " prkdtree consume " + (edTime1 - stTime1) + "us kdtree consume " + (edTime2 - stTime1) + "us dynmic consume " + (stopWatch.ElapsedTicks) + "ticks";
                    }
                }
                break;

                case FunctionType.kQueryObj:
                {
                    Vector3 pos   = new Vector3(e.X, 0, e.Y);
                    int     objCt = space_objs_.Count;
                    if (objCt > 0)
                    {
                        float radius  = float.Parse(queryRadius.Text);
                        long  stTime1 = TimeUtility.Instance.GetElapsedTimeUs();
                        selected_objs_.Clear();
                        prkdtree_.Query(pos, radius * scale, (float distSqr, PrKdTreeObject treeObj) =>
                            {
                                selected_objs_.Add(treeObj.SpaceObject as TestSpaceObject);
                            });
                        long edTime1 = TimeUtility.Instance.GetElapsedTimeUs();

                        long stTime2 = TimeUtility.Instance.GetElapsedTimeUs();
                        selected_objs2_.Clear();
                        kdtree_.Query(pos, radius * scale, (float distSqr, KdTreeObject treeObj) =>
                            {
                                selected_objs2_.Add(treeObj.SpaceObject as TestSpaceObject);
                            });
                        long edTime2 = TimeUtility.Instance.GetElapsedTimeUs();

                        this.Text = "obj num " + objCt + " query prkdtree " + selected_objs_.Count + " consume " + (edTime1 - stTime1) + "us query kdtree " + selected_objs2_.Count + " consume " + (edTime2 - stTime2) + "us";
                    }
                }
                break;
                }
            }
            else
            {
                if (e.Button == MouseButtons.Right && left_button_function_ == FunctionType.kSetStaticBlock)
                {
                    int row, col;
                    cell_manager_.GetCell(new Vector3(e.X, 0, e.Y), out row, out col);
                    byte oldObstacle = cell_manager_.GetCellStatus(row, col);
                    byte obstacle    = BlockType.NOT_BLOCK;
                    cell_manager_.SetCellStatus(end.row, end.col, obstacle);

                    if (map_patch_parser_.Exist(row, col))
                    {
                        map_patch_parser_.Update(row, col, obstacle);
                    }
                    else
                    {
                        map_patch_parser_.Update(row, col, obstacle, oldObstacle);
                    }

                    UpdateObstacleGraph();
                }
                else
                {
                    long stTime = TimeUtility.Instance.GetElapsedTimeUs();
                    found_path_ = spatial_system_.FindPathWithCellMap(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), new Vector3(line_end_.X, 0, map_height_ - line_end_.Y));
                    long edTime = TimeUtility.Instance.GetElapsedTimeUs();

                    long stTime2 = TimeUtility.Instance.GetElapsedTimeUs();
                    int  stRow, stCol, edRow, edCol;
                    spatial_system_.GetCell(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), out stRow, out stCol);
                    spatial_system_.GetCell(new Vector3(line_end_.X, 0, map_height_ - line_end_.Y), out edRow, out edCol);
                    //List<CellPos> path = new List<CellPos>();
                    //tree_cache_finder_.GetPath(new CellPos(stRow, stCol), new CellPos(edRow, edCol), path);
                    found_path_ = jump_point_finder_.FindPath(new CellPos(stRow, stCol), new CellPos(edRow, edCol));
                    long edTime2 = TimeUtility.Instance.GetElapsedTimeUs();

                    long stTime3 = TimeUtility.Instance.GetElapsedTimeUs();
                    found_path_ = spatial_system_.FindPath(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), new Vector3(line_end_.X, 0, map_height_ - line_end_.Y));
                    long edTime3 = TimeUtility.Instance.GetElapsedTimeUs();

                    /*//
                     * found_path_.Clear();
                     * if (path.Count > 0) {
                     * foreach (CellPos p in path) {
                     * found_path_.Add(spatial_system_.GetCellCenter(p.row, p.col));
                     * }
                     * }
                     * ///*/
                    this.Text = "findpath:" + new Vector2(line_start_.X, map_height_ - line_start_.Y).ToString() + " to " + new Vector2(line_end_.X, map_height_ - line_end_.Y).ToString() + " consume " + (edTime - stTime) / 1000.0f + "ms no preprocess consume " + (edTime2 - stTime2) / 1000.0f + "ms triangulation network consume " + (edTime3 - stTime3) / 1000.0f + "ms";
                }
            }
            is_mouse_down_ = false;
            key_hit_       = 0;
        }