Esempio n. 1
0
        /// <summary>
        /// Process all the raw data on the Playstation Move controller
        /// </summary>
        protected virtual void ProcessData()
        {
            UpdateButtons();
            {
                int x = 0, y = 0, z = 0;

                PsMoveApi.psmove_get_accelerometer(_motionController.Handle, out x, out y, out z);

                _motionController.RawAccelerometer = new Vector3(x, y, z);
            }

            {
                float x = 0, y = 0, z = 0;
                PsMoveApi.psmove_get_accelerometer_frame(_motionController.Handle, PSMoveFrame.SecondHalf, out x, out y, out z);

                _motionController.Accelerometer = new Vector3(x, y, z);
            }

            {
                int x = 0, y = 0, z = 0;
                PsMoveApi.psmove_get_gyroscope(_motionController.Handle, out x, out y, out z);


                _motionController.RawGyroscope = new Vector3(x, y, z);
            }

            {
                float x = 0, y = 0, z = 0;
                PsMoveApi.psmove_get_gyroscope_frame(_motionController.Handle, PSMoveFrame.SecondHalf, out x, out y, out z);

                _motionController.Gyroscope = new Vector3(x, y, z);
            }

            if (PsMoveApi.psmove_has_orientation(_motionController.Handle) == PSMoveBool.True)
            {
                float w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f;
                PsMoveApi.psmove_get_orientation(_motionController.Handle, out w, out x, out y, out z);
                Quaternion rot = new Quaternion(x, y, z, w);
                rot = rot * m_orientationFix;
#if YISUP
                Vector3 euler = rot.eulerAngles;
                rot = Quaternion.Euler(-euler.x, -euler.y, euler.z);
#endif

                m_orientation = rot;
                _motionController.Orientation = rot;
            }
            else
            {
                m_orientation = Quaternion.identity;
            }

            {
                int x = 0, y = 0, z = 0;
                PsMoveApi.psmove_get_magnetometer(_motionController.Handle, out x, out y, out z);

                // TODO: Should these values be converted into a more human-understandable range?
                _motionController.Magnetometer = new Vector3(x, y, z);
            }

            _motionController.BatteryLevel = PsMoveApi.psmove_get_battery(_motionController.Handle);

            _motionController.Temperature = PsMoveApi.psmove_get_temperature_in_celsius(_motionController.Handle);
            PsMoveApi.psmove_set_rumble(_motionController.Handle, (byte)(_motionController.Rumble / 255f));
        }