This commit is contained in:
Pascal Serrarens 2024-03-18 09:25:36 +01:00
commit f1ef79a103
2 changed files with 13 additions and 12 deletions

View File

@ -86,7 +86,7 @@ namespace Passer.Tracking {
} }
if (OculusDevice.GetHandState(OculusDevice.Step.Render, isLeft ? OculusDevice.Hand.HandLeft : OculusDevice.Hand.HandRight, ref handState)) { if (OculusDevice.GetHandState(OculusDevice.Step.Render, isLeft ? OculusDevice.Hand.HandLeft : OculusDevice.Hand.HandRight, ref handState)) {
if (handState.Status == 0) { if ((handState.Status & OculusDevice.HandStatus.HandTracked) == 0) {
status = Tracker.Status.Present; status = Tracker.Status.Present;
DisableRenderer(); DisableRenderer();
return; return;

View File

@ -112,7 +112,7 @@ namespace Passer {
// This is not working, because Unity may set this to the wrong object autonomously // This is not working, because Unity may set this to the wrong object autonomously
//touchedObject = data.pointerCurrentRaycast.gameObject; //touchedObject = data.pointerCurrentRaycast.gameObject;
//if (touchedObject == null) {// object is a 3D object, as we do not use Physicsraycaster, use the focusObject //if (touchedObject == null) {// object is a 3D object, as we do not use Physicsraycaster, use the focusObject
touchedObject = focusObject; touchedObject = focusObject;
//} //}
DebugLog("Touch " + touchedObject); DebugLog("Touch " + touchedObject);
@ -121,8 +121,10 @@ namespace Passer {
focusing = true; focusing = true;
return; return;
} }
else
ProcessFocus();
if (!clicking) { // first activation if (!clicking) { // first activation
touchedObject = data.pointerCurrentRaycast.gameObject; touchedObject = data.pointerCurrentRaycast.gameObject;
if (touchedObject == null) // object is a 3D object, as we do not use Physicsraycaster, use the focusObject if (touchedObject == null) // object is a 3D object, as we do not use Physicsraycaster, use the focusObject
@ -528,18 +530,15 @@ namespace Passer {
if (Camera.main == null || pointer.type != PointerType.Touch) if (Camera.main == null || pointer.type != PointerType.Touch)
return; return;
//if (eventSystem == null)
// eventSystem = Object.FindObjectOfType<EventSystem>();
//if (eventSystem == null)
// return;
pointer.data.position = Camera.main.WorldToScreenPoint(pointer.pointerTransform.position); pointer.data.position = Camera.main.WorldToScreenPoint(pointer.pointerTransform.position);
float distanceToPointer = Vector3.Distance(Camera.main.transform.position, pointer.pointerTransform.position);
System.Collections.Generic.List<RaycastResult> m_RaycastResultCache = new System.Collections.Generic.List<RaycastResult>(); System.Collections.Generic.List<RaycastResult> m_RaycastResultCache = new System.Collections.Generic.List<RaycastResult>();
eventSystem.RaycastAll(pointer.data, m_RaycastResultCache); eventSystem.RaycastAll(pointer.data, m_RaycastResultCache);
RaycastResult raycastResult = FindFirstRaycast(m_RaycastResultCache); RaycastResult raycastResult = FindFirstRaycast(m_RaycastResultCache, distanceToPointer);
m_RaycastResultCache.Clear(); m_RaycastResultCache.Clear();
if (raycastResult.gameObject != null) { if (raycastResult.gameObject != null) {
if (pointer.type == PointerType.Touch) { if (pointer.type == PointerType.Touch) {
float distance = DistanceTipToTransform(pointer.pointerTransform, raycastResult.gameObject.transform); float distance = DistanceTipToTransform(pointer.pointerTransform, raycastResult.gameObject.transform);
@ -559,9 +558,12 @@ namespace Passer {
} }
} }
private new RaycastResult FindFirstRaycast(System.Collections.Generic.List<RaycastResult> raycastResults) { private RaycastResult FindFirstRaycast(System.Collections.Generic.List<RaycastResult> raycastResults, float pointerDistance) {
foreach (RaycastResult result in raycastResults) { foreach (RaycastResult result in raycastResults) {
if (result.isValid && result.worldPosition != Vector3.zero) { float resultDistance = Vector3.Distance(Camera.main.transform.position, result.worldPosition);
if (result.isValid &&
result.worldPosition != Vector3.zero &&
Mathf.Abs(resultDistance - pointerDistance) < 0.02F) {
return result; return result;
} }
} }
@ -580,7 +582,6 @@ namespace Passer {
} }
private float DistanceTipToTransform(Transform fingerTip, Transform transform) { private float DistanceTipToTransform(Transform fingerTip, Transform transform) {
//Debug.DrawLine(fingerTip.position, transform.position);
return (-transform.InverseTransformPoint(fingerTip.position).z * transform.lossyScale.z) - 0.01F; return (-transform.InverseTransformPoint(fingerTip.position).z * transform.lossyScale.z) - 0.01F;
} }
} }