Exemplo n.º 1
0
    public void SaveChaperone()
    {
        TweakAction     = TweakActionType.save;
        ChaperoneSaving = true;
        ChaperoneCalibrationState state = OpenVR.Chaperone.GetCalibrationState();

        if (state != ChaperoneCalibrationState.OK)
        {
            Debug.Log("GetCalibrationState() = " + state.ToString());
            return;
        }


        SteamVR_Utils.RigidTransform rt = new SteamVR_Utils.RigidTransform();
        rt.pos = PlaySpace.transform.position;
        rt.rot = PlaySpace.transform.rotation;

        HmdMatrix34_t mat = rt.ToHmdMatrix34();

        OpenVR.ChaperoneSetup.SetWorkingStandingZeroPoseToRawTrackingPose(ref mat);

        OpenVR.ChaperoneSetup.SetWorkingPlayAreaSize(PlaySpace.transform.localScale.x, PlaySpace.transform.localScale.z);

        HmdQuad_t[] pQuadsBuffer      = new HmdQuad_t[WallCount];
        ChaperonePlaneProperties wall = FirstWall;

        for (int index = 0; index < WallCount; index++)
        {
            Vector3 wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(0.5f, 0f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners0.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners0.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners0.v2 = -wallcorner.z;

            wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(0.5f, 1f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners1.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners1.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners1.v2 = -wallcorner.z;

            wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(-0.5f, 1f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners2.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners2.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners2.v2 = -wallcorner.z;

            wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(-0.5f, 0f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners3.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners3.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners3.v2 = -wallcorner.z;

            wall = wall.LeftWall;
        }
        OpenVR.ChaperoneSetup.SetWorkingCollisionBoundsInfo(pQuadsBuffer);
        OpenVR.ChaperoneSetup.CommitWorkingCopy(EChaperoneConfigFile.Live);//
        ReloadChaperone();
        ChaperoneSaving = false;
    }
Exemplo n.º 2
0
    public void ReloadChaperone()
    {
        TweakAction = TweakActionType.reload;
        Vector3       v0;
        Vector3       v1;
        Vector3       v3;
        float         x   = 0;
        float         y   = 0;
        HmdMatrix34_t mat = new HmdMatrix34_t();

        HmdQuad_t[] quads;
        ChaperonePlaneProperties wall, prevwall;

        ChaperoneLoading = true;

        //make sure we can get all the necessary information
        ChaperoneCalibrationState state = OpenVR.Chaperone.GetCalibrationState();

        if (state != ChaperoneCalibrationState.OK)
        {
            Debug.Log("GetCalibrationState() = " + state.ToString());
            return;
        }
        OpenVR.ChaperoneSetup.RevertWorkingCopy();
        if (!OpenVR.ChaperoneSetup.GetWorkingStandingZeroPoseToRawTrackingPose(ref mat))
        {
            Debug.Log("GetWorkingStandingZeroPoseToRawTrackingPose failed");
            return;
        }
        if (!OpenVR.ChaperoneSetup.GetWorkingPlayAreaSize(ref x, ref y))
        {
            Debug.Log("GetWorkingPlayAreaSize() failed");
            return;
        }
        if (!OpenVR.ChaperoneSetup.GetWorkingCollisionBoundsInfo(out quads))
        {
            Debug.Log("GetWorkingCollisionBoundsInfo() failed");
            return;
        }

        // Destroy walls/playspace if they already exist
        if (PlaySpace != null)
        {
            Destroy(PlaySpace.gameObject);
            PlaySpace = null;
        }
        if (FirstWall != null)
        {
            wall = FirstWall;
            for (int i = 0; i < WallCount; i++)
            {
                prevwall = wall.RightWall;
                Destroy(wall.gameObject);
                wall = prevwall;
            }
            FirstWall = null;
            WallCount = 0;
        }

        //this object will become the origin point
        SteamVR_Utils.RigidTransform rt = new SteamVR_Utils.RigidTransform(mat);
        transform.position   = rt.pos; //+ new Vector3(0, 1, 0);
        transform.rotation   = rt.rot;
        transform.localScale = Vector3.one;

        //create the rectangular playspace object
        PlaySpace = CreatePlane("ChapPlaySpace", false, PlaySpaceMaterial);
        PlaySpace.transform.parent = transform;

        //set the playspace transform
        PlaySpace.transform.localScale    = new Vector3(x, 1, y);
        PlaySpace.transform.localPosition = Vector3.zero;
        PlaySpace.transform.localRotation = Quaternion.identity;

        //Create the wall objects
        WallCount = quads.Length;
        prevwall  = null;
        foreach (HmdQuad_t quad in quads)
        {
            wall = CreatePlane("ChapWall", true, WallMaterial);
            wall.transform.parent = transform;

            // convert the necessary corners to a usable format
            v0 = new Vector3(quad.vCorners0.v0, quad.vCorners0.v1, -quad.vCorners0.v2);
            v1 = new Vector3(quad.vCorners1.v0, quad.vCorners1.v1, -quad.vCorners1.v2);
            v3 = new Vector3(quad.vCorners3.v0, quad.vCorners3.v1, -quad.vCorners3.v2);

            // set the walls transform
            wall.transform.localPosition = Vector3.Lerp(v0, v3, 0.5f);
            wall.transform.localScale    = new Vector3(Vector3.Distance(v0, v3), Vector3.Distance(v0, v1), 1);
            wall.transform.localRotation = Quaternion.LookRotation(v3 - v0, Vector3.up) * Quaternion.Euler(0, 90, 0);

            //each wall has a properties script with a link to the left and right wall. Also save a reference to the 1st wall
            if (prevwall != null)
            {
                prevwall.LeftWall = wall;
            }
            else
            {
                FirstWall = wall;
            }
            wall.RightWall = prevwall;
            prevwall       = wall;

            //Link first wall with last wall
            FirstWall.RightWall = wall;
            wall.LeftWall       = FirstWall;
        }
        ChaperoneLoading = false;
        TweakAction      = TweakActionType.none;
    }