// Overridden so that we can process the two types of pointer separately // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to // get data for ray pointers and canvas mouse pointers. /// <summary> /// State for a pointer controlled by a world space ray. E.g. gaze pointer /// </summary> /// <returns></returns> protected MouseState GetGazePointerData() { // Get the OVRRayPointerEventData reference OVRRayPointerEventData leftData; GetPointerData(kMouseLeftId, out leftData, true); leftData.Reset(); //Now set the world space ray. This ray is what the user uses to point at UI elements leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward); leftData.scrollDelta = GetExtraScrollDelta(); //Populate some default values leftData.button = PointerEventData.InputButton.Left; leftData.useDragThreshold = true; // Perform raycast to find intersections with world eventSystem.RaycastAll(leftData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); leftData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster; // We're only interested in intersections from OVRRaycasters if (ovrRaycaster) { // The Unity UI system expects event data to have a screen position // so even though this raycast came from a world space ray we must get a screen // space position for the camera attached to this raycaster for compatability leftData.position = ovrRaycaster.GetScreenPosition(raycast); // Find the world position and normal the Graphic the ray intersected RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>(); if (graphicRect != null) { // Set are gaze indicator with this world position and normal Vector3 worldPos = raycast.worldPosition; Vector3 normal = GetRectTransformNormal(graphicRect); OVRGazePointer.instance.SetPosition(worldPos, normal); // Make sure it's being shown OVRGazePointer.instance.RequestShow(); } } OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster; if (physicsRaycaster) { leftData.position = physicsRaycaster.GetScreenPos(raycast.worldPosition); OVRGazePointer.instance.RequestShow(); OVRGazePointer.instance.SetPosition(raycast.worldPosition, raycast.worldNormal); } // Stick default data values in right and middle slots for compatability // copy the apropriate data into right and middle slots OVRRayPointerEventData rightData; GetPointerData(kMouseRightId, out rightData, true); CopyFromTo(leftData, rightData); rightData.button = PointerEventData.InputButton.Right; OVRRayPointerEventData middleData; GetPointerData(kMouseMiddleId, out middleData, true); CopyFromTo(leftData, middleData); middleData.button = PointerEventData.InputButton.Middle; m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData); m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData); m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData); return(m_MouseState); }
// The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to // get data for ray pointers and canvas mouse pointers. /// <summary> /// State for a pointer controlled by a world space ray. E.g. gaze pointer /// </summary> /// <returns></returns> virtual protected MouseState GetGazePointerData() { // Get the OVRRayPointerEventData reference OVRPointerEventData leftData; GetPointerData(kMouseLeftId, out leftData, true); leftData.Reset(); //Now set the world space ray. This ray is what the user uses to point at UI elements leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward); OVRInput.Controller controller = OVRInput.GetConnectedControllers() & (OVRInput.Controller.LTrackedRemote | OVRInput.Controller.RTrackedRemote); if (lineRenderer != null) { lineRenderer.enabled = trackingSpace != null && controller != OVRInput.Controller.None; } if (trackingSpace != null && controller != OVRInput.Controller.None) { controller = ((controller & OVRInput.Controller.LTrackedRemote) != OVRInput.Controller.None) ? OVRInput.Controller.LTrackedRemote : OVRInput.Controller.RTrackedRemote; Quaternion orientation = OVRInput.GetLocalControllerRotation(controller); Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(controller); Matrix4x4 localToWorld = trackingSpace.localToWorldMatrix; Vector3 worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); Vector3 worldOrientation = localToWorld.MultiplyVector(orientation * Vector3.forward); leftData.worldSpaceRay = new Ray(worldStartPoint, worldOrientation); if (lineRenderer != null) { lineRenderer.SetPosition(0, worldStartPoint); lineRenderer.SetPosition(1, worldStartPoint + worldOrientation * 500.0f); } } else { leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward); } leftData.scrollDelta = GetExtraScrollDelta(); //leftdata.scrolldelta = getextrascrolldelta(); //Populate some default values leftData.button = PointerEventData.InputButton.Left; leftData.useDragThreshold = true; // Perform raycast to find intersections with world eventSystem.RaycastAll(leftData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); leftData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster; // We're only interested in intersections from OVRRaycasters if (ovrRaycaster) { // The Unity UI system expects event data to have a screen position // so even though this raycast came from a world space ray we must get a screen // space position for the camera attached to this raycaster for compatability leftData.position = ovrRaycaster.GetScreenPosition(raycast); // Find the world position and normal the Graphic the ray intersected RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>(); if (graphicRect != null) { // Set are gaze indicator with this world position and normal Vector3 worldPos = raycast.worldPosition; Vector3 normal = GetRectTransformNormal(graphicRect); OVRGazePointer.instance.SetPosition(worldPos, normal); // Make sure it's being shown OVRGazePointer.instance.RequestShow(); if (lineRenderer != null) { lineRenderer.SetPosition(1, raycast.worldPosition); } } } // Now process physical raycast intersections OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster; if (physicsRaycaster) { Vector3 position = raycast.worldPosition; if (performSphereCastForGazepointer) { // Here we cast a sphere into the scene rather than a ray. This gives a more accurate depth // for positioning a circular gaze pointer List <RaycastResult> results = new List <RaycastResult>(); physicsRaycaster.Spherecast(leftData, results, OVRGazePointer.instance.GetCurrentRadius()); if (results.Count > 0 && results[0].distance < raycast.distance) { position = results[0].worldPosition; } } leftData.position = physicsRaycaster.GetScreenPos(raycast.worldPosition); // Show the cursor while pointing at an interactable object OVRGazePointer.instance.RequestShow(); if (lineRenderer != null) { lineRenderer.SetPosition(1, raycast.worldPosition); } if (matchNormalOnPhysicsColliders) { OVRGazePointer.instance.SetPosition(position, raycast.worldNormal); } else { OVRGazePointer.instance.SetPosition(position); } } // Stick default data values in right and middle slots for compatability // copy the apropriate data into right and middle slots OVRPointerEventData rightData; GetPointerData(kMouseRightId, out rightData, true); CopyFromTo(leftData, rightData); rightData.button = PointerEventData.InputButton.Right; OVRPointerEventData middleData; GetPointerData(kMouseMiddleId, out middleData, true); CopyFromTo(leftData, middleData); middleData.button = PointerEventData.InputButton.Middle; m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData); m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData); m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData); return(m_MouseState); }
// The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to // get data for ray pointers and canvas mouse pointers. /// <summary> /// State for a pointer controlled by a world space ray. E.g. gaze pointer /// </summary> /// <returns></returns> virtual protected MouseState GetGazePointerData() { // Get the OVRRayPointerEventData reference OVRPointerEventData leftData; GetPointerData(kMouseLeftId, out leftData, true); leftData.Reset(); //Now set the world space ray. This ray is what the user uses to point at UI elements leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward); leftData.scrollDelta = GetExtraScrollDelta(); //Populate some default values leftData.button = PointerEventData.InputButton.Left; leftData.useDragThreshold = true; // Perform raycast to find intersections with world eventSystem.RaycastAll(leftData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); leftData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); m_Cursor.SetCursorRay(rayTransform); OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster; // We're only interested in intersections from OVRRaycasters if (ovrRaycaster) { // The Unity UI system expects event data to have a screen position // so even though this raycast came from a world space ray we must get a screen // space position for the camera attached to this raycaster for compatability leftData.position = ovrRaycaster.GetScreenPosition(raycast); // Find the world position and normal the Graphic the ray intersected RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>(); if (graphicRect != null) { // Set are gaze indicator with this world position and normal Vector3 worldPos = raycast.worldPosition; Vector3 normal = GetRectTransformNormal(graphicRect); m_Cursor.SetCursorStartDest(rayTransform.position, worldPos, normal, raycast.gameObject); } } // Now process physical raycast intersections OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster; if (physicsRaycaster) { Vector3 position = raycast.worldPosition; if (performSphereCastForGazepointer) { // Here we cast a sphere into the scene rather than a ray. This gives a more accurate depth // for positioning a circular gaze pointer List <RaycastResult> results = new List <RaycastResult>(); physicsRaycaster.Spherecast(leftData, results, m_SpherecastRadius); if (results.Count > 0 && results[0].distance < raycast.distance) { position = results[0].worldPosition; } } leftData.position = physicsRaycaster.GetScreenPos(raycast.worldPosition); m_Cursor.SetCursorStartDest(rayTransform.position, position, raycast.worldNormal); } // Stick default data values in right and middle slots for compatability // copy the apropriate data into right and middle slots OVRPointerEventData rightData; GetPointerData(kMouseRightId, out rightData, true); CopyFromTo(leftData, rightData); rightData.button = PointerEventData.InputButton.Right; OVRPointerEventData middleData; GetPointerData(kMouseMiddleId, out middleData, true); CopyFromTo(leftData, middleData); middleData.button = PointerEventData.InputButton.Middle; m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData); m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData); m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData); return(m_MouseState); }
protected virtual PointerInputModule.MouseState GetGazePointerData() { OVRPointerEventData ovrpointerEventData; this.GetPointerData(-1, out ovrpointerEventData, true); ovrpointerEventData.Reset(); ovrpointerEventData.worldSpaceRay = new Ray(this.rayTransform.position, this.rayTransform.forward); ovrpointerEventData.scrollDelta = this.GetExtraScrollDelta(); ovrpointerEventData.button = PointerEventData.InputButton.Left; ovrpointerEventData.useDragThreshold = true; base.eventSystem.RaycastAll(ovrpointerEventData, this.m_RaycastResultCache); RaycastResult raycastResult = BaseInputModule.FindFirstRaycast(this.m_RaycastResultCache); ovrpointerEventData.pointerCurrentRaycast = raycastResult; this.m_RaycastResultCache.Clear(); OVRRaycaster ovrraycaster = raycastResult.module as OVRRaycaster; if (ovrraycaster) { ovrpointerEventData.position = ovrraycaster.GetScreenPosition(raycastResult); RectTransform component = raycastResult.gameObject.GetComponent <RectTransform>(); if (component != null) { Vector3 worldPosition = raycastResult.worldPosition; Vector3 rectTransformNormal = OVRInputModule.GetRectTransformNormal(component); OVRGazePointer.instance.SetPosition(worldPosition, rectTransformNormal); OVRGazePointer.instance.RequestShow(); } } OVRPhysicsRaycaster ovrphysicsRaycaster = raycastResult.module as OVRPhysicsRaycaster; if (ovrphysicsRaycaster) { Vector3 worldPosition2 = raycastResult.worldPosition; if (this.performSphereCastForGazepointer) { List <RaycastResult> list = new List <RaycastResult>(); ovrphysicsRaycaster.Spherecast(ovrpointerEventData, list, OVRGazePointer.instance.GetCurrentRadius()); if (list.Count > 0 && list[0].distance < raycastResult.distance) { worldPosition2 = list[0].worldPosition; } } ovrpointerEventData.position = ovrphysicsRaycaster.GetScreenPos(raycastResult.worldPosition); OVRGazePointer.instance.RequestShow(); if (this.matchNormalOnPhysicsColliders) { OVRGazePointer.instance.SetPosition(worldPosition2, raycastResult.worldNormal); } else { OVRGazePointer.instance.SetPosition(worldPosition2); } } OVRPointerEventData ovrpointerEventData2; this.GetPointerData(-2, out ovrpointerEventData2, true); this.CopyFromTo(ovrpointerEventData, ovrpointerEventData2); ovrpointerEventData2.button = PointerEventData.InputButton.Right; OVRPointerEventData ovrpointerEventData3; this.GetPointerData(-3, out ovrpointerEventData3, true); this.CopyFromTo(ovrpointerEventData, ovrpointerEventData3); ovrpointerEventData3.button = PointerEventData.InputButton.Middle; this.m_MouseState.SetButtonState(PointerEventData.InputButton.Left, this.GetGazeButtonState(), ovrpointerEventData); this.m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, ovrpointerEventData2); this.m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, ovrpointerEventData3); return(this.m_MouseState); }