Beispiel #1
0
 private void Form4_MouseMove(object sender, MouseEventArgs e)
 {
     if (is_rotate_)
     {
         Vector3 cent         = control_obj_.GetPosition();
         Vector3 gun_word_end = Shape.TransformToWorldPos(cent, gun_end_pos_, control_obj_.CosDir, control_obj_.SinDir);
         double  direction    = GetRotateDegree(control_obj_, gun_word_end, e.X, e.Y);
         control_obj_.SetFaceDirection(direction);
     }
 }
Beispiel #2
0
        private void DrawObj(Pen pen, TestSpaceObject obj)
        {
            obj.GetCollideShape().Transform(obj.GetPosition(), obj.CosDir, obj.SinDir);
            Circle c = obj.GetCollideShape() as Circle;

            if (c != null)
            {
                DrawCircel(pen, c);
                DrawFace(pen, c, obj.GetFaceDirection());
                DrawGun(pen, obj, gun_start_pos_, gun_end_pos_);
            }
        }
Beispiel #3
0
        private double GetRotateDegree(TestSpaceObject obj, Vector3 gun_word_end, float mouse_x, float mouse_y)
        {
            Vector3 center            = obj.GetPosition();
            Vector3 mouse_center_vect = new Vector3(mouse_x - center.X, 0, mouse_y - center.Z);

            Vector3 gun_word_start       = GetGunStartPos(center, gun_word_end, obj.GetFaceDirection());
            float   rotate_circle_radius = DashFire.Geometry.GetMod(new Vector3(mouse_x - center.X, 0, mouse_y - center.Z));
            Vector3 hit_point;

            if (!DashFire.Geometry.GetRayWithCircleFirstHitPoint(gun_word_start,
                                                                 DashFire.Geometry.GetVectorFromDir(obj.GetFaceDirection()),
                                                                 center, rotate_circle_radius,
                                                                 out hit_point))
            {
                return(obj.GetFaceDirection());
            }
            Vector3 hit_vect      = new Vector3(hit_point.X - center.X, 0, hit_point.Z - center.Z);
            float   rotate_degree = DashFire.Geometry.GetVectorAngle(mouse_center_vect, hit_vect);

            double judge_gun_dir = Math.Atan2(mouse_x - gun_word_end.X, mouse_y - gun_word_end.Z);
            double degree        = (judge_gun_dir - obj.GetFaceDirection()) % (2 * Math.PI);

            if (Math.Abs(degree) > Math.PI)
            {
                if (degree > 0)
                {
                    return(obj.GetFaceDirection() - rotate_degree);
                }
                else
                {
                    return(obj.GetFaceDirection() + rotate_degree);
                }
            }
            else
            {
                if (degree > 0)
                {
                    return(obj.GetFaceDirection() + rotate_degree);
                }
                else
                {
                    return(obj.GetFaceDirection() - rotate_degree);
                }
            }
        }
Beispiel #4
0
        private void DoMove(double dir, long deltaTime)
        {
            double  PI_1             = Math.PI;
            double  PI_2             = 2 * Math.PI;
            double  forecastDistance = 0.75 * cell_width_;
            double  speed            = 5.0 * cell_width_ / 0.5;
            Vector3 old_pos          = control_obj_.GetPosition();
            Vector3 new_pos          = new Vector3();
            double  distance         = (speed * deltaTime) / 1000;

            for (int ct = 0; ct < 8; ++ct)
            {
                double cosV = Math.Cos(dir);
                double sinV = Math.Sin(dir);
                double y = old_pos.z + distance * cosV;
                double x = old_pos.x + distance * sinV;
                double checkY, checkX;
                if (distance < forecastDistance)
                {
                    checkY = old_pos.z + forecastDistance * cosV;
                    checkX = old_pos.x + forecastDistance * sinV;
                }
                else
                {
                    checkY = y;
                    checkX = x;
                }
                checkY = y;
                checkX = x;

                new_pos = new Vector3((float)x, 0, (float)y);
                Vector3 check_pos = new Vector3((float)checkX, 0, (float)checkY);
                if (spatial_system_.CanPass(control_obj_, check_pos))
                {
                    //正常移动
                    control_obj_.SetPosition(new_pos);
                    if (cell_manager_.GetCellStatus(new_pos) == BlockType.STATIC_BLOCK)
                    {
                        LogUtil.Info("ERROR !");
                    }
                    break;
                }
                else
                {
                    //自动调节方向
                    double newDir = (dir + PI_1 / 4) % PI_2;
                    if (last_adjust_ >= 0 && CanGo(old_pos.x, old_pos.z, newDir, forecastDistance))
                    {
                        LogUtil.Info("adjust dir:{0}->{1} success, last adjust:{2}", dir, newDir, last_adjust_);
                        dir          = newDir;
                        last_adjust_ = 1;
                    }
                    else
                    {
                        LogUtil.Info("adjust dir:{0}->{1} failed, last adjust:{2}", dir, newDir, last_adjust_);
                        newDir = (dir + PI_2 - PI_1 / 4) % PI_2;
                        if (last_adjust_ <= 0 && CanGo(old_pos.x, old_pos.z, newDir, forecastDistance))
                        {
                            LogUtil.Info("adjust dir:{0}->{1} success, last adjust:{2}", dir, newDir, last_adjust_);
                            dir          = newDir;
                            last_adjust_ = -1;
                        }
                        else
                        {
                            LogUtil.Info("adjust dir:{0}->{1} failed, last adjust:{2}", dir, newDir, last_adjust_);
                            newDir = (dir + PI_1 / 2) % PI_2;
                            if (last_adjust_ >= 0 && CanGo(old_pos.x, old_pos.z, newDir, forecastDistance))
                            {
                                LogUtil.Info("adjust dir:{0}->{1} success, last adjust:{2}", dir, newDir, last_adjust_);
                                dir          = newDir;
                                last_adjust_ = 1;
                            }
                            else
                            {
                                LogUtil.Info("adjust dir:{0}->{1} failed, last adjust:{2}", dir, newDir, last_adjust_);
                                newDir = (dir + PI_2 - PI_1 / 2) % PI_2;
                                if (last_adjust_ <= 0 && CanGo(old_pos.x, old_pos.z, newDir, forecastDistance))
                                {
                                    LogUtil.Info("adjust dir:{0}->{1} success, last adjust:{2}", dir, newDir, last_adjust_);
                                    dir          = newDir;
                                    last_adjust_ = -1;
                                }
                                else
                                {
                                    LogUtil.Info("adjust dir:{0}->{1} failed, last adjust:{2}", dir, newDir, last_adjust_);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }