Exemple #1
0
        private static void TestPanMovementWithStartBeforeEndReached(ICommunication communication)
        {
            Console.WriteLine("Start");
            var panTiltControl  = new EneoPanTiltControl(communication);
            var positionChecker = new PositionChecker(panTiltControl);

            panTiltControl.PositionChanged += PanTiltControl_OnPositionChanged;

            while (true)
            {
                panTiltControl.PanAbsolute(0);
                positionChecker.ComparePosition(new PanTiltPosition(0, 0), 0.5, 20, 100);

                panTiltControl.PanAbsolute(40);
                positionChecker.ComparePosition(new PanTiltPosition(40, 0), 0.5, 20, 100);

                panTiltControl.PanRelative(-40);
                Thread.Sleep(500);

                panTiltControl.PanRelative(40);
                Thread.Sleep(500);

                panTiltControl.PanAbsolute(0);

                Console.WriteLine("Loop done");
            }
        }
Exemple #2
0
    public void SetRandomPosition(float radius)
    {
        Vector2 newPosition = new Vector2(Random.Range(-radius, radius), Random.Range(-radius, radius));

        positionOnMap = PositionChecker.CheckPosition(positionOnMap, newPosition, radius, moveRadius);

        Vector2 newDirection = new Vector2(Random.Range(-radius, radius), Random.Range(-radius, radius));

        direction = PositionChecker.CheckPosition(positionOnMap, newPosition, radius, moveRadius);
    }
        private void TestLogic()
        {
            var limits = this._panTiltControl.GetLimits();

            if (limits.PanMin == 0 && limits.PanMax == 0 && limits.TiltMin == 0 && limits.TiltMax == 0)
            {
                this.textBoxResult.Invoke(o => o.Text += $"Cannot execute test invalid limits\r\n");
            }

            this.textBoxResult.Invoke(o => o.Text += $"Limits;Pan;{limits.PanMin};{limits.PanMax};Tilt;{limits.TiltMin};{limits.TiltMax}\r\n");
            var positionChecker = new PositionChecker(this._panTiltControl);

            this._panTiltControl.TiltAbsolute(0);
            for (var pan = limits.PanMin; pan < limits.PanMax; pan += 0.05)
            {
                pan = Math.Round(pan, 2);
                this._panTiltControl.PanAbsolute(pan);
                Thread.Sleep(2000);
                if (positionChecker.ComparePosition(new PanTiltPosition(pan, 0), 0.1))
                {
                    var position = this._panTiltControl.GetPosition();
                    this.textBoxResult.Invoke(o => o.Text += $"Good;pan;{pan};{position.Pan}\r\n");
                }
                else
                {
                    var position = this._panTiltControl.GetPosition();
                    this.textBoxResult.Invoke(o => o.Text += $"Failure;pan;{pan};{position.Pan}\r\n");
                }
            }

            this._panTiltControl.PanAbsolute(0);
            for (var tilt = limits.TiltMin; tilt < limits.TiltMax; tilt += 0.05)
            {
                tilt = Math.Round(tilt, 2);
                this._panTiltControl.TiltAbsolute(tilt);
                Thread.Sleep(2000);
                if (positionChecker.ComparePosition(new PanTiltPosition(0, tilt), 0.1))
                {
                    var position = this._panTiltControl.GetPosition();
                    this.textBoxResult.Invoke(o => o.Text += $"Good;tilt;{tilt};{position.Tilt}\r\n");
                }
                else
                {
                    var position = this._panTiltControl.GetPosition();
                    this.textBoxResult.Invoke(o => o.Text += $"Failure;tilt;{tilt};{position.Tilt}\r\n");
                }
            }
        }
Exemple #4
0
        private static void DriveRandomPositions(ICommunication communication, bool debug)
        {
            var panTiltControl  = new EneoPanTiltControl(communication, debug);
            var positionChecker = new PositionChecker(panTiltControl);

            panTiltControl.Start();

            var random = new Random();

            while (true)
            {
                var panForward  = true;
                var tiltForward = true;

                if (random.Next(0, 2) == 1)
                {
                    panForward = false;
                }

                if (random.Next(0, 2) == 1)
                {
                    tiltForward = false;
                }

                for (var i = 0; i < 1000; i++)
                {
                    var panDegreePerSecond  = random.Next(1, 40);
                    var tiltDegreePerSecond = random.Next(1, 15);

                    if (!panForward)
                    {
                        panDegreePerSecond = -panDegreePerSecond;
                    }

                    if (!tiltForward)
                    {
                        tiltDegreePerSecond = -tiltDegreePerSecond;
                    }

                    panTiltControl.MoveRelative(panDegreePerSecond, tiltDegreePerSecond);

                    Thread.Sleep(40);
                }

                panTiltControl.PanTiltAbsolute(0, 0);
                positionChecker.ComparePosition(new PanTiltPosition(0, 0), 0.5, 20, 200);
            }
        }
Exemple #5
0
    void Awake()
    {
        cam = Camera.main;

        pc  = GameObject.Find("Main Camera").GetComponent <PositionChecker> ();
        fin = finish.GetComponent <Finish> ();

        //stamina = 100;

        grounded = true;
        this.GetComponent <Animator> ().SetBool("grounded", true);

        crashed  = false;
        jumpOnce = false;

        jumpForce = new Vector2(50, 250);
    }
    public static void Check(ICharactersManager player1, ICharactersManager player2)
    {
        foreach (ICharacter player1Unit in player1.GetCharacters())
        {
            foreach (ICharacter player2Unit in player2.GetCharacters())
            {
                float dist1 = PositionChecker.GetDistance(player1Unit.GetPosition(), player1Unit.GetDirection(), player2Unit.GetPosition());

                //Debug.Log(dist1);
                if (PositionChecker.GetDistance(player1Unit.GetPosition(), player1Unit.GetDirection(), player2Unit.GetPosition()) < 1.0f)
                {
                    player2Unit.Health -= player1Unit.Damage;
                    //    Debug.Log("Player 2 Hit Player 1");
                }

                if (PositionChecker.GetDistance(player2Unit.GetPosition(), player2Unit.GetDirection(), player1Unit.GetPosition()) < 1.0f)
                {
                    player1Unit.Health -= player2Unit.Damage;
                    //  Debug.Log("Player 1 Hit Player 2");
                }
            }
        }
    }
Exemple #7
0
 void Start()
 {
     posCheck = this.GetComponent <PositionChecker> ();
 }
Exemple #8
0
 void Awake()
 {
     Instance = this;
     print(Screen.width + "" + Screen.height);
 }
    void Update()
    {
        if (_hasCreatingUnit)
        {
            _timeBeforeSpawn -= Time.deltaTime;
            if (_timeBeforeSpawn <= 0)
            {
                Quaternion unitRotation = new Quaternion();
                unitRotation.eulerAngles = _spawnRotation;
                unitRotation             = transform.rotation * unitRotation;

                UnitAI newUnit = GameObjectManager.CreateObject(_currentTaskData.Prefab, PositionChecker.FindNearestFreePosition(transform.TransformPoint(_spawnPoint)), unitRotation).GetComponent <UnitAI>();
                GameObjectManager.AddToPlayerObjectsList(OwnerPlayer, newUnit.transform);

                ////отправка юнита в пункт сбора
                //var message = new TaskDataMessage {
                //    TaskData = new FollowToPoint_Task.FollowToPoint_TaskData(AssemblyPoint ),
                //    NewQueue = true
                //};
                //newUnit.AddTask(message);

                DequeueUnitData();
            }
        }
    }
    public void MoveTo(Vector2 point)
    {
        Vector2 newPosition2 = PositionChecker.CheckPosition(characterData.GetPosition(), point, 15, 5);

        newPosition = new Vector3(newPosition2.x, 0, newPosition2.y);
    }
Exemple #11
0
 public void SetPosition(Vector2 newPosition)
 {
     positionOnMap = PositionChecker.CheckPosition(positionOnMap, newPosition, 15, moveRadius);
 }
Exemple #12
0
    public void SetRandomStartPosition(float radius, int partOfCircle)
    {
        Vector2 newPosition = new Vector2(Random.Range(-radius, radius), Random.Range(-radius, radius));

        positionOnMap = PositionChecker.CheckStartPosition(newPosition, radius, partOfCircle);
    }
Exemple #13
0
 public void SetPanTiltControl(IPanTiltControl panTiltControl)
 {
     this._panTiltControl  = panTiltControl;
     this._positionChecker = new PositionChecker(this._panTiltControl);
 }
    /// <param name="position">глобальная позиция</param>
    public static Vector3 FindNearestFreePosition(Vector3 position)
    {
        Node defaultSpawnNode = AstarPath.active.GetNearest(position);

        if (PositionChecker.NodeIsWalkable(defaultSpawnNode) && PositionChecker.PositionIsFree(position, 0.5f))
        {
            return(position);
        }


        int width = AstarPath.active.astarData.gridGraph.width;

        Node[] nodes           = AstarPath.active.astarData.gridGraph.nodes;
        int    centerNodeIndex = defaultSpawnNode.GetNodeIndex();
        int    index;
        int    indexX;//используется для провеки выхода индекса за границы диапазона 0..GridWidth
        int    columnHeight = 0, rowWidth = 0;

        //(спиральный поиск по часовой)
        for (int i = 0; i < 100; i++)
        {
            columnHeight++;

            indexX = centerNodeIndex % width + i + 1;
            if (indexX < width)
            {
                for (int j = -columnHeight; j <= columnHeight; j++)
                {
                    index = centerNodeIndex - j * width + i + 1;
                    Vector3 nodePos;
                    if (PositionChecker.NodePositionIsFree(nodes, index, out nodePos))
                    {
                        return(nodePos);
                    }
                }
            }


            for (int j = -rowWidth; j <= rowWidth; j++)
            {
                indexX = centerNodeIndex % width - j;
                if (indexX >= 0 && indexX < width)
                {
                    index = centerNodeIndex - (i + 1) * width - j;
                    Vector3 nodePos;
                    if (PositionChecker.NodePositionIsFree(nodes, index, out nodePos))
                    {
                        return(nodePos);
                    }
                }
            }

            indexX = centerNodeIndex % width - i - 1;
            if (indexX >= 0)
            {
                for (int j = -columnHeight; j <= columnHeight; j++)
                {
                    index = centerNodeIndex + j * width - i - 1;
                    Vector3 nodePos;
                    if (PositionChecker.NodePositionIsFree(nodes, index, out nodePos))
                    {
                        return(nodePos);
                    }
                }
            }

            for (int j = -rowWidth; j <= rowWidth; j++)
            {
                indexX = centerNodeIndex % width + j;
                if (indexX >= 0 && indexX < width)
                {
                    index = centerNodeIndex + (i + 1) * width + j;
                    Vector3 nodePos;
                    if (PositionChecker.NodePositionIsFree(nodes, index, out nodePos))
                    {
                        return(nodePos);
                    }
                }
            }

            rowWidth++;
        }
        return(position);
    }