Exemplo n.º 1
0
    // Data analysis (called in OnTargetDestroyed)
    private void analyze()
    {
        // get filtered acceleration (from start to when target destroyed)
        List <Vector3> accData = tiltManager.filtAccRecord;

        // on-device analysis (not implemented 2016-01-28)
        float   targetDirectionRad = float.Parse(experimentalParameters["Target Direction"]) * Mathf.Deg2Rad;
        Vector3 unitVecToTarget    = new Vector3(Mathf.Cos(targetDirectionRad), Mathf.Sin(targetDirectionRad), 0f);
        int     tMaxDev            = 0;
        float   maxDev             = 0f;
        int     tMaxVel            = 0;
        float   maxVel             = 0f;

        int nRecord = accData.Count;

        float[] deviationFromStraight = new float[nRecord];
        float[] angularDeviation      = new float[nRecord];
        float[] playerVelocity        = new float[nRecord];

        for (int iRecord = 0; iRecord < nRecord; iRecord++)
        {
            // hi-freq (200Hz for Nexus, same as acceleration) cursor data (not presented to subjects) from filtered acceleration
            Vector3 playerPos = cursor.Acc2CursorPosition(accData[iRecord]);

            // angular deviation
            float xx = Mathf.Cos(-targetDirectionRad) * playerPos.x - Mathf.Sin(-targetDirectionRad) * playerPos.y;
            float yy = Mathf.Sin(-targetDirectionRad) * playerPos.x + Mathf.Cos(-targetDirectionRad) * playerPos.y;
            angularDeviation[iRecord] = Mathf.Atan2(yy, xx) * Mathf.Rad2Deg;

            // deviation from a straight line to the target
            Vector3 projectionVec = Vector3.Project(unitVecToTarget, playerPos);
            Vector3 orthogonalVec = playerPos - projectionVec;
            float   dev           = orthogonalVec.magnitude;
            deviationFromStraight[iRecord] = dev;
            if (dev > maxDev)
            {
                tMaxDev = iRecord;
                maxDev  = dev;
            }

            // player velocity
            // Debug.Log("index: " + iRecord);
            float vel;
            if (iRecord == 0)
            {
                vel = 0f;
            }
            else
            {
                Vector3 prevPlayerPos = cursor.Acc2CursorPosition(accData[iRecord - 1]);
                vel = (playerPos - prevPlayerPos).magnitude / float.Parse(Config.instance.configParameters["Sampling Interval"]);;
            }
            playerVelocity[iRecord] = vel;

            if (vel > maxVel)
            {
                tMaxVel = iRecord;
                maxVel  = vel;
            }
        }

        // maximum deviation
        maxDev = maxDev * Mathf.Sign(angularDeviation[tMaxDev]);
        float angDev = angularDeviation[tMaxVel];

        // result dictionary
        Dictionary <string, string> result = new Dictionary <string, string>();

        result.Add("tMaxDevFromStraight", tMaxDev.ToString("N0"));
        result.Add("MaxDevFromStraight", maxDev.ToString("N3"));
        result.Add("tMaxVel", tMaxVel.ToString("N0"));
        result.Add("MaxAngDevAtTMaxVel", angDev.ToString("N3"));

        // output
        resultOfTrial = result;
        experimentManager.AddResultToList(result);
    }