示例#1
0
        void Start()
        {
            m_trackingText.text = "";
            FindController();
            if (m_controller != null)
            {
                m_leapConnected = m_controller.IsConnected;
            }

            if (m_startInScreenTopViewMode)
            {
                Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, false);
                goScreenTop();
            }
            else if (XRSupportUtil.IsXRDevicePresent())
            {
                Screen.SetResolution(640, 480, false);
                goVR();
            }
            else
            {
                Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, false);
                goDesktop();
            }

            m_deltaTime       = new SmoothedFloat();
            m_deltaTime.delay = 0.1f;
        }
示例#2
0
        protected void LateUpdate()
        {
            if (!_isRecording && (recordWhen & RecordOn.HMDPresence) != 0 && XRSupportUtil.IsUserPresent())
            {
                BeginRecording();
            }

            if ((Hands.Left != null || Hands.Right != null) && (recordWhen & RecordOn.HandPresence) != 0)
            {
                BeginRecording();
            }

            if (Input.GetKeyDown(beginRecordingKey))
            {
                BeginRecording();
            }

            if (Input.GetKeyDown(finishRecordingKey))
            {
                finishRecording(new ProgressBar());
            }

            if (_isRecording)
            {
                recordData();
            }
        }
        private IEnumerator endOfFrameWaiter()
        {
            WaitForEndOfFrame waiter = new WaitForEndOfFrame();
            long endOfFrameTicks     = _stopwatch.ElapsedTicks;

            while (true)
            {
                yield return(waiter);

                long newTicks = _stopwatch.ElapsedTicks;
                AddSample("Frame Delta", GraphUnits.Miliseconds, newTicks - endOfFrameTicks);
                AddSample("Framerate", GraphUnits.Framerate, newTicks - endOfFrameTicks);
                endOfFrameTicks = newTicks;

                AddSample("Render Delta", GraphUnits.Miliseconds, _renderTicks);

                float gpuTime = XRSupportUtil.GetGPUTime();

                AddSample("GPU Time", GraphUnits.Miliseconds, gpuTime);

                if (_provider != null)
                {
                    AddSample("Tracking Latency", GraphUnits.Miliseconds, (_provider.GetLeapController().Now() - _provider.CurrentFrame.Timestamp) * 0.001f);
                }
            }
        }
示例#4
0
 void Start()
 {
     if (XRSupportUtil.IsXRDevicePresent() &&
         XRSupportUtil.IsXREnabled() &&
         _deviceOffsets != null)
     {
         string deviceName       = XRSupportUtil.GetLoadedDeviceName();
         var    deviceHeightPair = _deviceOffsets.FirstOrDefault(d => deviceName.ToLower().Contains(d.DeviceName.ToLower()));
         if (deviceHeightPair != null)
         {
             transform.Translate(Vector3.up * deviceHeightPair.HeightOffset);
         }
     }
 }
示例#5
0
        void updateTrackingData()
        {
            if (_isXRNodeSet)
            {
                var position = XRSupportUtil.GetXRNodeLocalPosition((int)xrNode);
                var rotation = XRSupportUtil.GetXRNodeLocalRotation((int)xrNode);

                // Unfortunately, the only alternative to checking the controller's position and
                // rotation for whether or not it is tracked is to request an allocated string
                // array of all currently-connected joysticks, which would allocate garbage
                // every frame, so it's unusable.
                _isTrackingController = position != Vector3.zero && rotation != Quaternion.identity;

                Transform rigTransform = MainCameraProvider.mainCamera.transform.parent;
                if (rigTransform != null)
                {
                    position = rigTransform.TransformPoint(position);
                    rotation = rigTransform.TransformRotation(rotation);
                }

                OnTrackingDataUpdate(position, rotation);
            }
        }
示例#6
0
 private bool checkShouldEnableHeadMounted()
 {
     if (XRSupportUtil.IsXREnabled())
     {
         var parentCamera = GetComponentInParent <Camera>();
         if (parentCamera != null && parentCamera.stereoTargetEye != StereoTargetEyeMask.None)
         {
             if (!_isHeadMounted)
             {
                 if (Application.isPlaying)
                 {
                     Debug.LogError("VR is enabled and the LeapServiceProvider is the child of a "
                                    + "camera targeting one or both stereo eyes; You should "
                                    + "check the isHeadMounted option on the LeapServiceProvider "
                                    + "if the Leap is mounted or attached to your VR headset!",
                                    this);
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
        private void createPortalCamera(LayerMask mask, out Camera camera, out List <int> layers)
        {
            if (_portalCameraAnchor == null)
            {
                var portalCameraObj = new GameObject("Portal Cameras");
                portalCameraObj.hideFlags = HideFlags.NotEditable;

                _portalCameraAnchor = portalCameraObj.transform;
                _portalCameraAnchor.transform.parent = _mainCamera.transform.parent;
                _portalCameraAnchor.SetSiblingIndex(_mainCamera.transform.GetSiblingIndex() + 1);
                _portalCameraAnchor.localPosition = Vector3.zero;
                _portalCameraAnchor.localRotation = Quaternion.identity;
                _portalCameraAnchor.localScale    = Vector3.one;
            }

            GameObject cameraObj = new GameObject("Portal Camera");//TODO: better naming

            cameraObj.hideFlags               = HideFlags.NotEditable;
            cameraObj.transform.parent        = _portalCameraAnchor;
            cameraObj.transform.localPosition = _mainCamera.transform.localPosition;
            cameraObj.transform.localRotation = _mainCamera.transform.localRotation;
            cameraObj.transform.localScale    = _mainCamera.transform.localScale;

            camera               = cameraObj.AddComponent <Camera>();
            camera.clearFlags    = CameraClearFlags.Nothing;
            camera.cullingMask   = mask;
            camera.nearClipPlane = _mainCamera.nearClipPlane;
            camera.farClipPlane  = _mainCamera.farClipPlane;
            camera.allowHDR      = _mainCamera.allowHDR;
            camera.allowMSAA     = _mainCamera.allowMSAA;
            if (!XRSupportUtil.IsXREnabled())
            {
                camera.fieldOfView = _mainCamera.fieldOfView;
            }

            layers = getLayersFromMask(mask);
        }
示例#8
0
        //Update the Head Yaw for Calculating "Shoulder Positions"
        void Update()
        {
            Frame curFrame = LeapDataProvider.CurrentFrame.TransformedCopy(LeapTransform.Identity);



            Quaternion HeadYaw = Quaternion.Euler(0f, XRSupportUtil.GetXRNodeHeadLocalRotation().eulerAngles.y, 0f);

            CurrentRotation = Quaternion.Slerp(CurrentRotation, HeadYaw, 0.1f);

            for (int whichHand = 0; whichHand < 2; whichHand++)
            {
                if (whichHand > curFrame.Hands.Count - 1)
                {
                    if (Cursors[whichHand].activeInHierarchy)
                    {
                        Cursors[whichHand].SetActive(false);
                    }
                    continue;
                }
                else
                {
                    if (!Cursors[whichHand].activeInHierarchy)
                    {
                        Cursors[whichHand].SetActive(true);
                    }
                }

                Vector3 ProjectionOrigin = Vector3.zero;
                switch (curFrame.Hands[whichHand].IsRight)
                {
                case true:
                    ProjectionOrigin = XRSupportUtil.GetXRNodeHeadLocalPosition() + CurrentRotation * new Vector3(0.15f, -0.13f, 0.1f);
                    break;

                case false:
                    ProjectionOrigin = XRSupportUtil.GetXRNodeHeadLocalPosition() + CurrentRotation * new Vector3(-0.15f, -0.13f, 0.1f);
                    break;
                }

                Vector3 Offset = curFrame.Hands[whichHand].Fingers[1].Bone(Bone.BoneType.TYPE_METACARPAL).Center.ToVector3() - ProjectionOrigin;

                Cursors[whichHand].transform.position = Vector3.Lerp(Cursors[whichHand].transform.position, ProjectionOrigin + (Offset * MotionScalingFactor), CursorSmoothingFactor);

                if (curFrame.Hands[whichHand].PinchDistance < 30f)
                {
                    if (!prevPinching[whichHand])
                    {
                        prevPinching[whichHand] = true;
                        Cursors[whichHand].GetComponent <MeshRenderer>().material.color = Color.green;

                        Collider[] Colliders = Physics.OverlapSphere(Cursors[whichHand].transform.position, CollisionSphereDiameter);

                        for (int i = 0; i < Mathf.Min(10, Colliders.Length); i++)
                        {
                            // We need to hit a rigidbody that is not kinematic
                            if (!Colliders[i].attachedRigidbody || Colliders[i].attachedRigidbody.isKinematic)
                            {
                                return;
                            }

                            if (!SpringJoints[whichHand, i])
                            {
                                SpringJoints[whichHand, i] = Cursors[whichHand].AddComponent <SpringJoint>();
                                Cursors[whichHand].GetComponent <Rigidbody>().isKinematic = true;
                            }

                            SpringJoints[whichHand, i].transform.position = Cursors[whichHand].transform.position;
                            SpringJoints[whichHand, i].anchor             = Vector3.zero;

                            SpringJoints[whichHand, i].spring        = Spring;
                            SpringJoints[whichHand, i].damper        = Damper;
                            SpringJoints[whichHand, i].maxDistance   = Distance;
                            SpringJoints[whichHand, i].connectedBody = Colliders[i].attachedRigidbody;

                            StartCoroutine(DragObject(whichHand, i));
                        }
                    }
                }
                else if (curFrame.Hands[whichHand].PinchDistance > 40f)
                {
                    if (prevPinching[whichHand])
                    {
                        prevPinching[whichHand] = false;
                        Cursors[whichHand].GetComponent <MeshRenderer>().material.color = Color.white;

                        //constraint breaks implicitly when prevPinching is set to false
                    }
                }
            }
        }