Пример #1
0
        /*
         * Desc: Used by the MoveServer to parse 'a' packets to the controller.
         * msg format: a, msgNo, c, currButtons, analogVal, ax, ay, az, gx, gy, gz, mx, my, mz, orientationEnabled, qw, qx, qy, qz, r, g, b
         */
        public Boolean updatePhysicalData(String[] physicalData)
        {
            int c = int.Parse(physicalData[2]);

            if (c == controllerNumber)
            {
                if (!active)
                {
                    active = true;
                }

                // Set our new values from the packet.
                prevButtons  = currButtons;
                currButtons  = byte.Parse(physicalData[3]);
                triggerValue = int.Parse(physicalData[4]);

                accelerometerRaw.Set(float.Parse(physicalData[5]), float.Parse(physicalData[6]), float.Parse(physicalData[7]));
                gyroscopeRaw.Set(float.Parse(physicalData[8]), float.Parse(physicalData[9]), float.Parse(physicalData[10]));
                magnetometerRaw.Set(float.Parse(physicalData[11]), float.Parse(physicalData[12]), float.Parse(physicalData[13]));

                orientationEnabled = (physicalData[14] == "1" ? true : false);

                if (orientationEnabled == true)
                {
                    quaternion.Set(-float.Parse(physicalData[16]), -float.Parse(physicalData[17]), float.Parse(physicalData[18]), float.Parse(physicalData[15]));
                }
                moveColor.r = int.Parse(physicalData[19]);
                moveColor.g = int.Parse(physicalData[20]);
                moveColor.b = int.Parse(physicalData[21]);

                // Process the new values.
                double newTime = System.DateTime.Now.Ticks * .0000001;
                if (currTime_a != -1)
                {
                    delta_t_a = newTime - currTime_a;
                }
                currTime_a = newTime;

                gyroscopeSmoothed.updateRaw(gyroscopeRaw);
                accelerometerSmoothed.updateRaw(accelerometerRaw);
                magnetometerSmoothed.updateRaw(magnetometerRaw);

                pressedButtons  = (byte)(pressedButtons | (~prevButtons & currButtons));
                releasedButtons = (byte)(releasedButtons | (prevButtons & ~currButtons));

                return(true);
            }
            return(false);
        }
Пример #2
0
        /*
         * Desc: Used by the MoveServer to parse 'b' packets to the controller.
         * msg format: b msgNo controller tx ty tz ux uy trackingMove
         */
        public Boolean updatePositionData(String[] positionData)
        {
            int c = int.Parse(positionData[2]);

            if (c == controllerNumber)
            {
                if (!active)
                {
                    active = true;
                }
                // Used to set the controllers properties

                // Set our new values from the packet.
                Vector3 prevPosRaw = positionRaw;

                positionRaw.Set(float.Parse(positionData[3]) / 100f, float.Parse(positionData[4]) / 100f, float.Parse(positionData[5]) / 100f);
                //Debug.Log(positionRaw.ToString());
                positionNorm.Set(float.Parse(positionData[6]), float.Parse(positionData[7]), 0);

                currentlyTracked = positionData[8] == "0" ? false : true;

                // Process the new values.
                double newTime = System.DateTime.Now.Ticks * .0000001;
                if (currTime_b != -1)
                {
                    delta_t_b = newTime - currTime_b;
                }
                currTime_b = newTime;

                // Store the last smoothed position for velocity calc.
                Vector3 prevPosSmooth = positionSmoothed.getSmoothedVector();

                positionSmoothed.updateRaw(positionRaw);
                positionNormSmooothed.updateRaw(positionNorm);

                // Calculate velocity.
                velocityRaw.Set((float)((positionRaw.x - prevPosRaw.x) / delta_t_b), (float)((positionRaw.x - prevPosRaw.x) / delta_t_b), (float)((positionRaw.x - prevPosRaw.x) / delta_t_b));
                if (prevPosSmooth != null)
                {
                    Vector3 posSmooth = positionSmoothed.getSmoothedVector();
                    velocitySmoothed.Set((float)((posSmooth.x - prevPosSmooth.x) / delta_t_b), (float)((posSmooth.x - prevPosSmooth.x) / delta_t_b), (float)((posSmooth.x - prevPosSmooth.x) / delta_t_b));
                }
                return(true);
            }
            return(false);
        }