Exemple #1
0
            //Culling determines which objects are visible to the camera. OnPreCull is called just before this process.
            //This gets called because we have a camera component, but we disable the camera here so it doesn't render.
            //We have the "dummy" camera so existing Unity game code can refer to a MainCamera object.
            //We update our viewer and eye transforms here because it is as late as possible before rendering happens.
            //OnPreRender is not called because we disable the camera here.
            void OnPreCull()
            {
                // Disable dummy camera during rendering
                // Enable after frame ends
                _camera.enabled = false;

                //for each viewer, update each eye, which will update each surface
                for (uint viewerIndex = 0; viewerIndex < _viewerCount; viewerIndex++)
                {
                    VRViewer viewer = Viewers[viewerIndex];

                    //update the client
                    UpdateClient();

                    //update poses once DisplayConfig is ready
                    if (_checkDisplayStartup)
                    {
                        //update the viewer's head pose
                        viewer.UpdateViewerHeadPose(DisplayConfig.GetViewerPose(viewerIndex));

                        //each viewer update its eyes
                        viewer.UpdateEyes();
                    }
                    else
                    {
                        _checkDisplayStartup = DisplayConfig.CheckDisplayStartup();
                    }
                }

                // Flag that we disabled the camera
                _disabledCamera = true;
            }
Exemple #2
0
            //Creates a head and eyes as configured in clientKit
            //Viewers and Eyes are siblings, children of DisplayController
            //Each eye has one child Surface which has a camera
            private void CreateHeadAndEyes()
            {
                /* ASSUME ONE VIEWER */
                //Create VRViewers, only one in this implementation
                _viewerCount = (uint)_displayConfig.GetNumViewers();
                if (_viewerCount != NUM_VIEWERS)
                {
                    Debug.LogError(_viewerCount + " viewers detected. This implementation supports exactly one viewer.");
                    return;
                }
                _viewers = new VRViewer[_viewerCount];
                //loop through viewers because at some point we could support multiple viewers
                //but this implementation currently supports exactly one
                for (uint viewerIndex = 0; viewerIndex < _viewerCount; viewerIndex++)
                {
                    //create a VRViewer
                    GameObject vrViewer = new GameObject("VRViewer" + viewerIndex);
                    vrViewer.AddComponent <AudioListener>();              //add an audio listener
                    VRViewer vrViewerComponent = vrViewer.AddComponent <VRViewer>();
                    vrViewerComponent.DisplayController = this;           //pass DisplayController to Viewers
                    vrViewerComponent.ViewerIndex       = viewerIndex;    //set the viewer's index
                    vrViewer.transform.parent           = this.transform; //child of DisplayController
                    vrViewer.transform.localPosition    = Vector3.zero;
                    _viewers[viewerIndex] = vrViewerComponent;

                    //create Viewer's VREyes
                    uint eyeCount = (uint)_displayConfig.GetNumEyesForViewer(viewerIndex); //get the number of eyes for this viewer
                    vrViewerComponent.CreateEyes(eyeCount);
                }
            }
Exemple #3
0
 // Use this for initialization
 void Start()
 {
     viewer = GetComponent <VRViewer>();
     ChangeCurrentBuilding(0);
     Cursor.visible   = false;
     Cursor.lockState = CursorLockMode.Locked;
 }
Exemple #4
0
 void Start()
 {
     //terrainScript = GetComponent<TerrainDeformer>();
     //terrainScript1 = GetComponent<TerrainDeformer1>();
     viewer            = GetComponent <VRViewer>();
     placeableBuilding = GetComponent <PlaceableBuilding>();
     hasPlaced         = false;
     spacePressed      = false;
     moveObject        = false;
     //Cursor.lockState = CursorLockMode.Confined;
 }
            // Update is called once per frame
            void Update()
            {
                if (viewerDirection == null)
                {
                    VRViewer viewer = FindObjectOfType <VRViewer>();
                    if (viewer != null)
                    {
                        viewerDirection = viewer.transform;
                    }
                }

                // Get the input vector from keyboard or analog stick
                Vector3 directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

                if (directionVector != Vector3.zero)
                {
                    // Get the length of the directon vector and then normalize it
                    // Dividing by the length is cheaper than normalizing when we already have the length anyway
                    var directionLength = directionVector.magnitude;
                    directionVector = directionVector / directionLength;
                    if (directionVector.sqrMagnitude > 1)
                    {
                        directionVector.Normalize();
                    }

                    // Make sure the length is no bigger than 1
                    directionLength = Mathf.Min(1, directionLength);

                    // Make the input vector more sensitive towards the extremes and less sensitive in the middle
                    // This makes it easier to control slow speeds when using analog sticks
                    directionLength = directionLength * directionLength;

                    // Multiply the normalized direction vector by the modified length
                    directionVector = directionVector * directionLength;
                }


                if (viewerDirection)
                {
                    // Apply the viewer direction to the CharacterMotor
                    Vector3 theForwardDirection = viewerDirection.TransformDirection(Vector3.forward);
                    theForwardDirection.y = 0;
                    theForwardDirection.Normalize();
                    motor.inputMoveDirection = viewerDirection.rotation * directionVector;
                    motor.inputJump          = Input.GetButton("Jump");
                }
            }
            // Creates a head and eyes as configured in clientKit
            // Viewers and Eyes are siblings, children of DisplayController
            // Each eye has one child Surface which has a camera
            private void CreateHeadAndEyes()
            {
                /* ASSUME ONE VIEWER */
                // Create VRViewers, only one in this implementation
                _viewerCount = (uint)_displayConfig.GetNumViewers();
                if (_viewerCount != NUM_VIEWERS)
                {
                    Debug.LogError(_viewerCount + " viewers detected. This implementation supports exactly one viewer.");
                    return;
                }
                _viewers = new VRViewer[_viewerCount];

                uint viewerIndex = 0;

                //Check if there are already VRViewers in the scene.
                //If so, create eyes for them.
                VRViewer[] viewersInScene = FindObjectsOfType <VRViewer>();
                if (viewersInScene != null && viewersInScene.Length > 0)
                {
                    for (viewerIndex = 0; viewerIndex < viewersInScene.Length; viewerIndex++)
                    {
                        VRViewer viewer = viewersInScene[viewerIndex];
                        // get the VRViewer gameobject
                        GameObject vrViewer = viewer.gameObject;
                        vrViewer.name = "VRViewer" + viewerIndex; //change its name to VRViewer0
                        //@todo optionally add components
                        if (vrViewer.GetComponent <AudioListener>() == null)
                        {
                            vrViewer.AddComponent <AudioListener>();       //add an audio listener
                        }
                        viewer.DisplayController         = this;           //pass DisplayController to Viewers
                        viewer.ViewerIndex               = viewerIndex;    //set the viewer's index
                        vrViewer.transform.parent        = this.transform; //child of DisplayController
                        vrViewer.transform.localPosition = Vector3.zero;
                        _viewers[viewerIndex]            = viewer;
                        if (viewerIndex == 0)
                        {
                            vrViewer.tag = "MainCamera"; //set the MainCamera tag for the first Viewer
                        }

                        // create Viewer's VREyes
                        uint eyeCount = (uint)_displayConfig.GetNumEyesForViewer(viewerIndex); //get the number of eyes for this viewer
                        viewer.CreateEyes(eyeCount);
                    }
                }

                // loop through viewers because at some point we could support multiple viewers
                // but this implementation currently supports exactly one
                for (; viewerIndex < _viewerCount; viewerIndex++)
                {
                    // create a VRViewer
                    GameObject vrViewer = new GameObject("VRViewer" + viewerIndex);
                    if (vrViewer.GetComponent <AudioListener>() == null)
                    {
                        vrViewer.AddComponent <AudioListener>(); //add an audio listener
                    }

                    VRViewer vrViewerComponent = vrViewer.AddComponent <VRViewer>();
                    vrViewerComponent.DisplayController = this;           //pass DisplayController to Viewers
                    vrViewerComponent.ViewerIndex       = viewerIndex;    //set the viewer's index
                    vrViewer.transform.parent           = this.transform; //child of DisplayController
                    vrViewer.transform.localPosition    = Vector3.zero;
                    _viewers[viewerIndex] = vrViewerComponent;
                    vrViewer.tag          = "MainCamera";

                    // create Viewer's VREyes
                    uint eyeCount = (uint)_displayConfig.GetNumEyesForViewer(viewerIndex); //get the number of eyes for this viewer
                    vrViewerComponent.CreateEyes(eyeCount);
                }
            }