コード例 #1
0
 private void Update()
 {
     inGain  = Parameters[0];
     outGain = Parameters[1];
     bias    = Parameters[2];
     mode    = (GainMode)(int)Parameters[3];
 }
コード例 #2
0
    /**
     * Load in settings from config files.
     **/
    private void Awake()
    {
        //Dont load settings from config files in debug mode
        if (debug)
        {
            initialMode = mode;
            return;
        }

        //Get gain level from file
        StreamReader sr = new StreamReader(Application.dataPath + "/gainLevel.txt");
        string       line;

        if ((line = sr.ReadLine()) != null)
        {
            gainLevel = float.Parse(line);
        }
        else
        {
            Debug.Log("CANT READ");
            gainLevel = 1;
        }

        sr.Close();


        //Get gain mode from file
        sr = new StreamReader(Application.dataPath + "/mode.txt");
        if ((line = sr.ReadLine()) != null)
        {
            switch (line)
            {
            case "d":
                mode = GainMode.Directed;
                break;

            case "u":
                mode = GainMode.Uniform;
                break;

            default:
                gainLevel = 1;
                break;
            }
        }
        else
        {
            Debug.Log("CANT READ");
            gainLevel = 1;
        }

        sr.Close();

        initialMode = mode;
    }
コード例 #3
0
 public Gain()
 {
     mode      = GainMode.Manual;
     tolerance = 5;
     max       = 27;
     min       = 0;
     outliers  = 0;
     rate      = 100;
     target    = 50;
     value     = 0;
 }
コード例 #4
0
ファイル: Gain.cs プロジェクト: ddcc/EERILControlSystem
 public Gain()
 {
     mode = GainMode.Manual;
     tolerance = 5;
     max = 27;
     min = 0;
     outliers = 0;
     rate = 100;
     target = 50;
     value = 0;
 }
コード例 #5
0
 public void setGainMode(GainMode m)
 {
     mode = m;
 }
コード例 #6
0
    void Update()
    {
        //Grab the current velocity of the headset
        hmdVelocity = getHMDVel();
        float ySpeed = Mathf.Abs(hmdVelocity.y);

        hmdVelocity.y = 0;
        float hmdSpeed = new Vector2(hmdVelocity.x, hmdVelocity.z).magnitude;

        Vector3 hmdV = new Vector3(hmdVelocity.x, 0, hmdVelocity.z).normalized;

        //Initialise heading to be cam view direction
        Vector3 heading = cam.transform.forward;

        heading.y = 0;

        //When a sharp change in view direction occurs, this indicates two things [1] Circular motion is occuring, [2] The user has likley changed their direction of regard.  In either case, all prior direction data would no longer be valid, and so is discarded
        bool sharpAngleDetected = false;

        if (Mathf.Abs(Vector3.SignedAngle(prevViewDir, hmdV, Vector3.up)) > sharpAngleDelta)
        {
            directionWindow.reset();
            sharpAngleDetected = true;
        }
        //Cache the cam direction of this frame to be compared against next tick
        prevViewDir = heading;

        //Push current user velocity to the sliding window for direction calculation in subsequent frames
        directionWindow.push(hmdVelocity);

        //In directed mode, we enable and disable directional gain according to user speed.
        //At very low speeds we consider it not possible to accuratley determing heading over noise data, and so switch to uniform mode.
        if (initialMode == GainMode.Directed)
        {
            //At super low speeds, consider any directional data to be noise and delete it
            if (hmdSpeed < driectionCuttoffSpeed)
            {
                directionWindow.reset();
            }
            //Only use calcualted heading if we havent reset the windows, else just stick with cam forward dir set prior
            else
            {
                heading = getUserHeading();
            }

            //At slow speeds, use only uniform mode
            if (hmdSpeed < uniformCuttoffSpeed)
            {
                mode = GainMode.Uniform;
            }
            else
            {
                mode = GainMode.Directed;
            }
        }

        //Amount of gain to apply is some multiple of base gain level as determined by the ramping function
        float curScale = gainLevel;

        //If speed is below ramping cuttoff, then the gain is a function of user speed. For no gain (level=1) skip this, as ramping function will give NAN results
        if (hmdSpeed < rampingCutoffSpeed && gainLevel != 1)
        {
            curScale = RAMPING_CONST_A * Mathf.Exp(RAMPING_CONST_B * hmdSpeed) + 1;
        }


        //Check to see if y component of headset velocity exceeds a cuttoff, if it does, then motion is determined to be a result of user crouching, and as such no gain should be applied to this motion.
        if (ySpeed > 0.5f)
        {
            curScale = 1;
        }

        //If sharp angle was detected and the relevant flag is set to true then disable gain for this tick
        if (sharpAngleDetected && disableGainOnSharpAngle)
        {
            curScale = 1;
        }

        //Scaling is only applied in the xz plane to avoid exagerrated head bob.
        Vector3 scaling = new Vector3(curScale, 0, curScale);

        //If using directed gain then need to apply direction multipliers to scaling vector
        if (mode != GainMode.Uniform)
        {
            //Get directional multiplier to apply to scaling vector. This is the Abs direction projected into the xz plane.
            Vector3 directionMult = new Vector3(Mathf.Abs(heading.x), 1, Mathf.Abs(heading.z));

            //Multiplier the scaling vector by the directional multiplier vector
            scaling = Vector3.Scale(scaling, directionMult);

            //Only ever want scaling to be additive, dont want to reduce movement along non direction axis
            scaling.x = Mathf.Max(1, scaling.x);
            scaling.z = Mathf.Max(1, scaling.z);
        }

        //Calculate the base amount of movement in the real world
        Vector3 curPos = InputTracking.GetLocalPosition(XRNode.Head);
        Vector3 delta  = curPos - prevPosition;

        prevPosition = curPos;

        //Apply scaling to this movement delta and apply result of this to our position in the VE.
        Vector3 newPos = transform.position + Vector3.Scale(scaling, delta);

        //No scaling in y dir
        newPos.y           = curPos.y;
        transform.position = newPos;
    }