Beispiel #1
0
        private void GetControllers()
        {
            ControllerHub.DiscoverControllers();
            ICollection <Controller> controllers = ControllerHub.GetAll();

            foreach (Controller controller in controllers)
            {
                if ((controller.ProductID == 0x4001 || controller.ProductID == 0x5001) &&
                    (controller.ProductSubclass == 2 || controller.ProductSubclass == 3 ||
                     controller.ProductSubclass == 1 || controller.ProductSubclass == (unchecked ((int)0xffffffd9))))
                {
                    TabPage page = new TabPage(controller.Name);
                    page.Controls.Add(new TwoAxisControlPanel(controller));
                    this.tabControl1.TabPages.Add(page);
                }
                else if (controller.ProductID == 0x4000)
                {
                    TabPage page = new TabPage(controller.Name);
                    page.Controls.Add(new LEDControlPanel(controller));
                    this.tabControl1.TabPages.Add(page);
                }
            }

            if (tabControl1.TabPages.Count != 0)
            {
                tabControl1.SelectedIndex = 0;
            }
        }
Beispiel #2
0
        public static App Create(AppConfig appConfig)
        {
            string rootDirectoryPath        = getRootDirectoryPath();
            string sensorsDirectoryPath     = rootDirectoryPath + "\\Sensors";
            string controllersDirectoryPath = rootDirectoryPath + "\\Controllers";

            var sensorNames = appConfig.Sensors.Select(x => x.SensorName);

            var sensorLoader     = new SensorLoader(sensorsDirectoryPath);
            var controllerLoader = new ControllerLoader(controllersDirectoryPath);
            var sensorBuilders   = sensorLoader.Load(sensorNames);
            var controllers      = controllerLoader.Load();
            var sensors          = buildSensors(sensorBuilders, appConfig);

            var stateStore = new StateStore();

            stateStore.SetModes(appConfig.Modes);

            var sensorHub     = new SensorHub(sensors);
            var controllerHub = new ControllerHub(controllers);

            var app = new App(stateStore, sensorHub, controllerHub);

            app.Initialize(appConfig);
            return(app);
        }
Beispiel #3
0
    void TouchMouse()
    {
        // Get looking joy
        joyLook = ControllerHub.GetControllerTouch("TouchArea").GetAxis();

        // unmark this code and region "Smooth Rotation" if you use your Touch controller and want smooth rotation
        // ControllerHub.GetControllerTouch controller has own implementation for smoothing
        //SmoothedTouchMouseValues();
    }
Beispiel #4
0
        public App(IStateStore stateStore, SensorHub sensorHub, ControllerHub controllerHub)
        {
            _stateStore    = stateStore;
            _sensorHub     = sensorHub;
            _controllerHub = controllerHub;

            _sensorHub.StatusChanged   += _sensorHub_StatusChanged;
            _sensorHub.ModeChanged     += _sensorHub_ModeChanged;
            _sensorHub.ApplicationExit += _sensorHub_ApplicationExit;
        }
Beispiel #5
0
 void JoyKeyboard(bool yLocked = true)
 {
     if (yLocked)
     {
         joyMove = ControllerHub.GetControllerJoy("JoyArea").GetAxisRelated(camTransform);
     }
     else
     {
         joyMove = ControllerHub.GetControllerJoy("JoyArea").GetAxisRelated(camTransform, parallelToGroundLine: false);
     }
 }
Beispiel #6
0
    void FixedUpdate()
    {
        if (_camera != null)
        {
            joyMove = ControllerHub.GetControllerJoy("JoyArea").GetAxisRelated(_camera.transform);
            Debug.DrawRay(_transform.position, joyMove * 3, Color.red);
        }
        else
        {
            Debug.LogError("no camera attached to script " + this);
        }

        //cc.Move(new Vector3(joyMove.x,0,joyMove.y)*10*Time.fixedDeltaTime);
        cc.Move(joyMove * 10 * Time.fixedDeltaTime);
    }
Beispiel #7
0
    private void Update()
    {
        //******************** show  how to Controllers values for your code
        // Joy Values
        JoyAxisRaw            = ControllerHub.GetControllerJoy("JoyArea").GetAxis(); // .GetAxis("Raw");
        JoyAxisNormalized     = ControllerHub.GetControllerJoy("JoyArea").GetAxis("Normalized");
        JoyAxisWalkRun        = ControllerHub.GetControllerJoy("JoyArea").GetAxis("WalkRun");
        JoyAxisFourDirections = ControllerHub.GetControllerJoy("JoyArea").GetAxis("Four");

        JoyTouched = ControllerHub.GetControllerJoy("JoyArea").GetControllerInTouch();

        // Joy Values
        //Joy1AxisRaw = ControllerHub.GetControllerJoy("JoyArea (1)").GetAxis(); // .GetAxis("Raw");
        //Joy1Touched = ControllerHub.GetControllerJoy("JoyArea (1)").GetControllerInTouch();
        // Touch Values
        TouchAxis    = ControllerHub.GetControllerTouch("TouchArea").GetAxis();
        TouchTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
    }
Beispiel #8
0
        public void Disconnect()
        {
            var controllerOne = new Mock <IController>();

            controllerOne.Setup(x => x.Disconnect());

            var controllerTwo = new Mock <IController>();

            controllerTwo.Setup(x => x.Disconnect());

            var controllerHub = new ControllerHub(new List <IController> {
                controllerOne.Object, controllerTwo.Object
            });

            controllerHub.Disconnect();

            controllerOne.Verify(x => x.Disconnect(), Times.Once);
            controllerTwo.Verify(x => x.Disconnect(), Times.Once);
        }
Beispiel #9
0
    /*
     * [Tooltip("camera rotation with Lerp")]
     * [SerializeField] private bool smoothRotation = true;
     * private Vector3 joyLookPrevious = new Vector2();
     *
     * /// <summary>
     * /// If you want to add smooth to rotation
     * /// </summary>
     * void SmoothedTouchMouseValues()
     * {
     *  if (smoothRotation && (joyLook.x == 0 || joyLook.z == 0))
     *  {
     *      joyLook = Vector3.Lerp(joyLookPrevious, joyLook, Time.deltaTime * 10);
     *      joyLookPrevious = joyLook;
     *  }
     * }
     */
    #endregion

    void ZoomButtonsMouseWheel()
    {
        // Get zoom. Need to also get zoom from on screen controls
        joyZoom = ControllerHub.GetControllerTouch("TouchArea").GetMouseWheel();

        joyZoom = BtnZooming();

        if (joyZoom > 0)
        {
            joyZoom += zoomStep;
        }
        if (joyZoom < 0)
        {
            joyZoom -= zoomStep;
        }
        zoomFromController += joyZoom;

        zoomFromController = Mathf.Clamp(zoomFromController, zoomMax, zoomMin);
    }
Beispiel #10
0
        public void TurnOff()
        {
            var socket = new Socket(1, "Toster");

            var controllerOne = new Mock <IController>();

            controllerOne.Setup(x => x.TurnOff(socket));

            var controllerTwo = new Mock <IController>();

            controllerTwo.Setup(x => x.TurnOff(socket));

            var controllerHub = new ControllerHub(new List <IController> {
                controllerOne.Object, controllerTwo.Object
            });

            controllerHub.TurnOff(socket);

            controllerOne.Verify(x => x.TurnOff(socket), Times.Once);
            controllerTwo.Verify(x => x.TurnOff(socket), Times.Once);
        }
Beispiel #11
0
        private void enterBootloaderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab == null)
            {
                return;
            }

            NavitarControl control    = tabControl1.SelectedTab.Controls[0] as NavitarControl;
            Controller     controller = control.MyController;

            if (controller.Generation == 2)
            {
                ControllerGen2 secondGen = controller as ControllerGen2;

                // Get rid of tab
                TabPage page = tabControl1.SelectedTab;
                tabControl1.TabPages.Remove(page);
                page.Dispose();

                // Set wait cursor since operation takes a few seconds.
                Cursor.Current = Cursors.WaitCursor;

                // Enter bootloader
                secondGen.EnterBootloader();

                ControllerHub.RemoveController(secondGen);

                // Be patient while USB CDC device drops off bus.
                System.Threading.Thread.Sleep(2500);

                // Clear the wait cursor.
                Cursor.Current = Cursors.Default;
            }
            else
            {
                MessageBox.Show("Enter Bootloader command not supported for this controller.", "Feature Not Supported", MessageBoxButtons.OK);
            }
        }
Beispiel #12
0
    private void Awake()
    {
        Name = name;
        ControllerHub.AddToHub(gameObject);
        ControllerHub.AddJoyToHub(this);

        ControllerArea = gameObject.GetComponent <Image>();

        IfNotJoySetup();

        ControllerImageT = transform;
        JoyImageT        = JoyImage.transform;
        StickImageT      = StickImage.transform;

        JoyImageT.transform.SetParent(ControllerImageT);
        StickImage.transform.SetParent(ControllerImageT);

        defaultJoyImageGlobalPos = JoyImageT.position;
        defaultJoyImageLocalPos  = JoyImageT.localPosition;

        //joyCircleDiametr = JoyAreaT.localToWorldMatrix[0] * JoyAreaT.GetComponent<RectTransform>().rect.height;
        joyCircleDiametr = JoyImage.rectTransform.sizeDelta.x;
        joyCircleRadius  = joyCircleDiametr / 2;
    }
Beispiel #13
0
 void Awake()
 {
     Instance = this;
 }
Beispiel #14
0
    void CameraMoveUpdateThirdPersonFocused()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsetted = new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsetted); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                _autoLook = true;

                // // // // SemiWorkedTPCF(Vector3 bodyPos)

                //Vector3 _dirBodToTarget = (targetObjectTransform.position - bodyPos);
                Vector3 _dirCamToTarget = (targetObjectTransform.position - camTransform.position);

                //Vector3 _dirRotated = Vector3.RotateTowards(camTransform.forward, _dirBodToTarget, Vector3.Angle(camTransform.forward, _dirBodToTarget), 0.01f);

                Quaternion _rotation = Quaternion.LookRotation(_dirCamToTarget, camTransform.up);
                //Quaternion _rotation = Quaternion.LookRotation(_dirBodToTarget);
                //Quaternion _rotation = Quaternion.LookRotation(_dirRotated);

                zoomNow = ZoomNow();
                Vector3 position = _rotation * new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;
                //Vector3 position = _rotation * new Vector3(xEuler, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;


                //position = Clamp_Colision(bodyPos, position);
                camTransform.position = position;
                camTransform.rotation = Quaternion.LookRotation(targetObjectTransform.position - camTransform.position);
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
        }
    }
Beispiel #15
0
    void CameraMoveTestMethod3()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsettedY = new Vector3(0, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsettedY); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                /**************************************
                 * Vector3 side = Vector3.Cross (direction, Vector3.up)
                 * Vector3 up = Vector3.Cross (direction, side)
                 *************************************/
                _autoLook = true;

                Vector3 _dirBodyToTarg         = targetObjectTransform.position - bodyPos;
                Vector3 _targetPosVirtualPoint = targetObjectTransform.position;

                distanceBodyToTarget = Vector3.Distance(bodyPos, targetObjectTransform.position);
                // если обьект ближе этого расстояния, то точку слежения отдаляю на разницу
                float _closeLimit = 4;
                if (distanceBodyToTarget < _closeLimit)//2.83
                {
                    _targetPosVirtualPoint = _targetPosVirtualPoint + (_dirBodyToTarg).normalized * (_closeLimit - distanceBodyToTarget);
                }
                gismoTPCred = _targetPosVirtualPoint;
                // получаю желаемый поворот в эулерах (градусах)
                Vector3 _rotationEuler = Quaternion.LookRotation(_targetPosVirtualPoint - camTransform.position).eulerAngles;

                // получаю градусы между текущим вектором форвард камеры и вектором на таргет

                // получаю направление довотора вектора ???

                // клами поворота
                // float xEuler = Clamp_xEuler(camTransform.eulerAngles.x + joyLook.y);
                xEuler = Clamp_xEuler(_rotationEuler.x);



                // доворачиваю вектор форвард камеры на этот градус, в направлении на таргет
                // Quaternion rotation = Quaternion.Euler(xEuler, camTransform.eulerAngles.y + joyLook.x, 0f);
                Quaternion rotation = Quaternion.Euler(xEuler, _rotationEuler.y, 0f);
                //Quaternion rotation = Quaternion.Euler(xEuler, camTransform.eulerAngles.y, 0f);
                //Quaternion rotation = Quaternion.Euler(camTransform.eulerAngles.x, _rotationEuler.y, 0f);     // нет отслеживания по вертикали
                //Quaternion rotation = Quaternion.Euler(_rotationEuler.x, _rotationEuler.y, 0f); // нет клампа по вертикали

                zoomNow = ZoomNow();

                Vector3 position = rotation * new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;

                //position = Clamp_Colision(bodyPos, position);

                // считаю положение второй раз, если коллизии с перерасчетом на коллизии
                position = rotation * Clamp_CollisionOffset(bodyPos, position) + bodyPos;

                camTransform.rotation = rotation;
                camTransform.position = position;
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
        }
    }
Beispiel #16
0
    // TPCF по вектору от цели ищем положение с офсетом на теле
    void CameraMoveTestMethod2()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsettedY = new Vector3(0, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsettedY); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                /**************************************
                 * Vector3 side = Vector3.Cross (direction, Vector3.up)
                 * Vector3 up = Vector3.Cross (direction, side)
                 *************************************/
                _autoLook = true;

                float _disBodyToTarg = Vector3.Distance(_bodyPosOffsettedY, targetObjectTransform.position);

                //Vector3 _dirCamToTarget = (targetObjectTransform.position - camTransform.position).normalized;
                Vector3 _dirBodyToTarget = (targetObjectTransform.position - _bodyPosOffsettedY).normalized;

                Vector3 _dirTargToBody = (bodyPos - targetObjectTransform.position);
                Vector3 _right         = Vector3.Cross(_dirTargToBody, Vector3.up).normalized;
                // Vector3 _up = Vector3.Cross(_dirBodyToTarget, _right).normalized;
                Vector3 _up          = Vector3.Cross(-_dirTargToBody, _right).normalized;
                Vector3 _offsetedPos = bodyPos + _right * bodyOffsetThirdPerson.x + _up * bodyOffsetThirdPerson.y + _dirTargToBody.normalized * -ZoomNow();

                Debug.DrawRay(bodyPos, _right, Color.red);
                Debug.DrawRay(bodyPos, _up, Color.yellow);

                //Vector3 _ToTargetForC

                Vector3 _targetGismoPoint = _bodyPosOffsettedY + (_dirBodyToTarget * (_disBodyToTarg + 2));// targettingDistance;

                Quaternion rotation = Quaternion.LookRotation(targetObjectTransform.position - _offsetedPos);


                camTransform.rotation = rotation;
                camTransform.position = _offsetedPos;

                gismoTPCyellow = _targetGismoPoint;
                gismoTPCred    = _offsetedPos;
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
        }
    }
Beispiel #17
0
    // камера не глючит, если цель возле тела, но дрожит, если цель далеко. Вращается по градусам
    void CameraMoveTestMethod()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsettedY = new Vector3(0, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsettedY); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                _autoLook = true;
                //Vector3 _dirBodToTarget = (targetObjectTransform.position - bodyPos);
                Vector3 _dirCamToTarget  = (targetObjectTransform.position - camTransform.position);
                Vector3 _dirCamToTargetN = _dirCamToTarget.normalized;
                Vector3 _dirCamForw      = camTransform.forward;

                float _distCamToTarg = Vector3.Distance(camTransform.position, targetObjectTransform.position);

                angle = Vector3.Angle(_dirCamForw, _dirCamToTarget.normalized);

                Vector3 pointProjection = camTransform.position + camTransform.forward * _distCamToTarg;
                gismoCamPos       = pointProjection;
                gismoBodyOfsetPos = _bodyPosOffsettedY;
                float _distCamToProjection = Vector3.Distance(camTransform.position, pointProjection);

                _directProjectionToTarg = (targetObjectTransform.position - pointProjection);


                Debug.DrawRay(pointProjection, _directProjectionToTarg, Color.blue);
                Debug.DrawRay(camTransform.position, _dirCamToTargetN * (_distCamToTarg + 2), Color.red);
                Debug.DrawRay(camTransform.position, camTransform.forward * (_distCamToTarg + 2), Color.yellow);

                screenProjecPoint = gameObject.GetComponent <Camera>().WorldToScreenPoint(pointProjection);
                screenTargetPoint = gameObject.GetComponent <Camera>().WorldToScreenPoint(targetObjectTransform.position);
                screenBodyPoint   = gameObject.GetComponent <Camera>().WorldToScreenPoint(_bodyPosOffsettedY);

                Vector3 directionScrenProfectToTarget = (screenTargetPoint - screenProjecPoint).normalized;

                angleBody = -Vector2.Angle(screenProjecPoint - screenBodyPoint, Vector2.right);

                joyEmulator.y = -directionScrenProfectToTarget.y;
                joyEmulator.x = directionScrenProfectToTarget.x;

                // поворот вектора на градус (крестовина ординат меняется от + к х)
                //if (_distCamToTarg < _distCamToProjection)
                joyEmulator.x = RotateVector(joyEmulator, angleBody).x; // применяю по х поворот

                // для опытов ограничиваю один из векторов
                if (!readX)
                {
                    joyEmulator.x = 0;
                }
                if (!readY)
                {
                    joyEmulator.y = 0;
                }



                float xEuler = Clamp_xEuler(camTransform.eulerAngles.x + joyEmulator.y);
                xEulerPublic = xEuler;

                Quaternion rotation = Quaternion.Euler(xEuler, camTransform.eulerAngles.y + joyEmulator.x, 0f);
                zoomNow = ZoomNow();

                Vector3 position = rotation * new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;
                position = Clamp_Colision(bodyPos, position);

                camTransform.rotation = rotation;
                camTransform.position = position;
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
            gismoCamPos = camTransform.position;
        }
    }
Beispiel #18
0
 private void InvokedFunc2()
 {
     ControllerHub.ControllerSwitcher(true);
 }
Beispiel #19
0
 private void InvokedFunc3()
 {
     ControllerHub.ControllerSwitcher(false, "JoyArea");
 }
Beispiel #20
0
 private void InvokedFunc4()
 {
     ControllerHub.ControllerSwitcher(true, "JoyArea");
 }
Beispiel #21
0
    //*******************

    private void Awake()
    {
        ControllerHub.AddToHub(gameObject);
        ControllerHub.AddTouchToHub(this);
    }
Beispiel #22
0
 //******************** show  how to Enable/Disable Controllers while in game
 private void InvokedFunc1()
 {
     ControllerHub.ControllerSwitcher(false);
 }