diff --git a/test_vr_unity/Assets/Gestures/star_animator_controller.controller b/test_vr_unity/Assets/Gestures/star_animator_controller.controller index cbeea12ca4ff9ddcbd799de4eebf0e56643e73ca..95bc6b7d07b6ea7650545f023d8c8f09912dc92f 100644 --- a/test_vr_unity/Assets/Gestures/star_animator_controller.controller +++ b/test_vr_unity/Assets/Gestures/star_animator_controller.controller @@ -71,6 +71,32 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1102 &1102327395289407918 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: vanish + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: e72c455b90639c24f996040ed2db1045, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: --- !u!1107 &1107447109261544868 AnimatorStateMachine: serializedVersion: 5 @@ -83,6 +109,9 @@ AnimatorStateMachine: - serializedVersion: 1 m_State: {fileID: 1102209914930564344} m_Position: {x: 384, y: 120, z: 0} + - serializedVersion: 1 + m_State: {fileID: 1102327395289407918} + m_Position: {x: 419, y: 185, z: 0} m_ChildStateMachines: [] m_AnyStateTransitions: [] m_EntryTransitions: [] diff --git a/test_vr_unity/Assets/Materials/point_left.mat b/test_vr_unity/Assets/Materials/point_left.mat index 774b264ec46a722b87c33ad482f743b6a9072682..159fee2f27b9555f9c263d0995fac9c526ea551a 100644 --- a/test_vr_unity/Assets/Materials/point_left.mat +++ b/test_vr_unity/Assets/Materials/point_left.mat @@ -9,12 +9,13 @@ Material: m_PrefabAsset: {fileID: 0} m_Name: point_left m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} - m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF + m_ShaderKeywords: _ALPHABLEND_ON _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} + m_CustomRenderQueue: 3000 + stringTagMap: + RenderType: Transparent disabledShaderPasses: [] m_SavedProperties: serializedVersion: 3 @@ -59,19 +60,19 @@ Material: - _BumpScale: 1 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 - - _DstBlend: 0 + - _DstBlend: 10 - _GlossMapScale: 1 - _Glossiness: 0 - _GlossyReflections: 0 - _Metallic: 0 - - _Mode: 0 + - _Mode: 2 - _OcclusionStrength: 1 - _Parallax: 0.02 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 0 - - _SrcBlend: 1 + - _SrcBlend: 5 - _UVSec: 0 - - _ZWrite: 1 + - _ZWrite: 0 m_Colors: - _Color: {r: 0, g: 0.55598927, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/test_vr_unity/Assets/Prefabs/GesturePoint.prefab b/test_vr_unity/Assets/Prefabs/GesturePoint.prefab index 1ffb023af42736dee13172f8ff328e3a5d10753a..ea0981e2b92b28e0faa0521a06b1d2901cf06e67 100644 --- a/test_vr_unity/Assets/Prefabs/GesturePoint.prefab +++ b/test_vr_unity/Assets/Prefabs/GesturePoint.prefab @@ -13,6 +13,7 @@ GameObject: - component: {fileID: 6982965154212898579} - component: {fileID: 6982965154212898578} - component: {fileID: 8761357492929044139} + - component: {fileID: 2621446007440220247} m_Layer: 9 m_Name: GesturePoint m_TagString: gesture @@ -108,3 +109,16 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 0 m_CollisionDetection: 0 +--- !u!114 &2621446007440220247 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6982965154212898577} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e4cf536771403b74d9d7126c71e1ac2f, type: 3} + m_Name: + m_EditorClassIdentifier: + fade: 1 diff --git a/test_vr_unity/Assets/Prefabs/ReferencePoint.prefab b/test_vr_unity/Assets/Prefabs/ReferencePoint.prefab index 5308224d1f6575ddddce4b4a1228f35deb224828..8c9d573efe7320db78de290ced358dded7f94830 100644 --- a/test_vr_unity/Assets/Prefabs/ReferencePoint.prefab +++ b/test_vr_unity/Assets/Prefabs/ReferencePoint.prefab @@ -30,7 +30,7 @@ Transform: m_GameObject: {fileID: 7550860099689547248} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.04, y: 0.04, z: 0.04} + m_LocalScale: {x: 0.06, y: 0.06, z: 0.06} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 diff --git a/test_vr_unity/Assets/Scenes/TestOculusTouch.unity b/test_vr_unity/Assets/Scenes/TestOculusTouch.unity index 622046d877a7422d162f9368aad4ae3cce5c733a..035883a46c6fa7a4104ab34e3dba407bcddfa9ec 100644 --- a/test_vr_unity/Assets/Scenes/TestOculusTouch.unity +++ b/test_vr_unity/Assets/Scenes/TestOculusTouch.unity @@ -1134,8 +1134,8 @@ RectTransform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1226245320} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 23.69} - m_LocalScale: {x: 0.056603774, y: 0.056603774, z: 0.056603774} + m_LocalPosition: {x: 0, y: 0, z: 940} + m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1097496874} - {fileID: 189233416} @@ -1147,7 +1147,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 2070, y: 318} + m_SizeDelta: {x: 2000, y: 318} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1312997771 GameObject: diff --git a/test_vr_unity/Assets/Scripts/testTouch/FadeOut.cs b/test_vr_unity/Assets/Scripts/testTouch/FadeOut.cs new file mode 100644 index 0000000000000000000000000000000000000000..fd9ad477acc147872e671d3dbb7326d9881e3123 --- /dev/null +++ b/test_vr_unity/Assets/Scripts/testTouch/FadeOut.cs @@ -0,0 +1,38 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FadeOut : MonoBehaviour +{ + + Color clStart; + Color clEnd; + Renderer rend; + float duration = 1.5f; + public bool fade = true; + // Start is called before the first frame update + void Start() + { + if (fade) + { + rend = GetComponent<Renderer>(); + clStart = rend.material.color; + StartCoroutine(FadeOutAnimation()); + } + } + + IEnumerator FadeOutAnimation() + { + float startTime = Time.time; + while (Time.time < startTime + duration) + { + rend.material.color = new Color(clStart.r, + clStart.g, + clStart.b, + Mathf.Lerp(1.0f, 0.0f, (Time.time - startTime) / duration)); + yield return null; + } + Destroy(gameObject); + } + +} diff --git a/test_vr_unity/Assets/Scripts/testTouch/HandController.cs b/test_vr_unity/Assets/Scripts/testTouch/HandController.cs index 89135d69cb2bf77358d4404eaed6642c315ae93e..3c5b0fe1698b7d2596edc86db38ac8af5ec27dea 100644 --- a/test_vr_unity/Assets/Scripts/testTouch/HandController.cs +++ b/test_vr_unity/Assets/Scripts/testTouch/HandController.cs @@ -7,29 +7,35 @@ using UnityEngine.XR; public class HandController : MonoBehaviour { - - public static HandController instance; - private const float RADIUS = 0.2f; - private LineRenderer lineRenderer; - - public Text debugLeftHand; public Text debugRightHand; public Text Msg; public Text SpeedText; - - private readonly Vector3 pointSize = new Vector3(0.04f, 0.04f, 0.04f); public GameObject referencePointPrefab; public GameObject gesturePointPrefab; + + + public static HandController instance; + + private const float RADIUS = 0.15f; + private const float MIN_DELTA = 0.01f; + private List<Vector2> leftHandGesture = new List<Vector2>(); private List<Vector2> rightHandGesture = new List<Vector2>(); - Vector2 LastPosition = Vector2.zero; - List<float> Speed = new List<float>(); + private Vector2 LastPosition = Vector2.zero; + //List<float> Speed = new List<float>(); + + private readonly Vector3 referencePointScale= new Vector3(0.06f, 0.06f, 0.06f); + private readonly Vector3 gesturePointScale = new Vector3(0.04f, 0.04f, 0.04f); + float speedSum = 0; private bool trackHand = false; + private List<GameObject> points = new List<GameObject>(); + private List<GameObject> trace = new List<GameObject>(); + private int CorrectPoint = 0; private void Awake() @@ -43,6 +49,7 @@ public class HandController : MonoBehaviour { Destroy(gameObject); } + } public void IncrementCorrectPoint() @@ -52,9 +59,10 @@ public class HandController : MonoBehaviour private void Start() { - referencePointPrefab.transform.localScale = pointSize; - gesturePointPrefab.transform.localScale = pointSize; + referencePointPrefab.transform.localScale = referencePointScale; + gesturePointPrefab.transform.localScale = gesturePointScale; Msg.text = ""; + DisplayReferenceCircle(); } @@ -64,7 +72,8 @@ public class HandController : MonoBehaviour if (LastPosition != Vector2.zero) { float movementPerFrame = Vector2.Distance(LastPosition, CurrentPosition); - Speed.Add(movementPerFrame / Time.deltaTime); + //Speed.Add(movementPerFrame / Time.deltaTime); + speedSum += movementPerFrame / Time.deltaTime; } } @@ -79,17 +88,17 @@ public class HandController : MonoBehaviour { if (trackHand) { - - //add hand position to respective arrays - leftHandGesture.Add(new Vector2(leftHandPosition.z, leftHandPosition.y)); - rightHandGesture.Add(new Vector2(rightHandPosition.z, rightHandPosition.y)); Vector2 currentPosition = new Vector2(rightHandPosition.z, rightHandPosition.y); - CalculateSpeed(currentPosition); - LastPosition = currentPosition; - - displayPoint(false, rightHandPosition); - + // add hand position to respective arrays + // leftHandGesture.Add(new Vector2(leftHandPosition.z, leftHandPosition.y)); + if(Vector2.Distance(currentPosition,LastPosition)>MIN_DELTA) + { + rightHandGesture.Add(currentPosition); + CalculateSpeed(currentPosition); + LastPosition = currentPosition; + displayPoint(false, rightHandPosition); + } } // display position for debug purpose @@ -133,7 +142,7 @@ public class HandController : MonoBehaviour - void DisplayCircle(Vector3 center) + void DisplayCheckCircle(Vector3 center) { int vertexCount = rightHandGesture.Count; float deltaTheta = (2f * Mathf.PI) / vertexCount; @@ -150,6 +159,25 @@ public class HandController : MonoBehaviour } } + void DisplayReferenceCircle() + { + Vector3 center = new Vector3(0.1f, -0.3f, 0.35f); + int vertexCount = 30; + float deltaTheta = (2f * Mathf.PI) / vertexCount; + float theta = 0f; + + for (int i = 0; i <= vertexCount; i++) + { + Vector3 pos = new Vector3(center.x , center.y + RADIUS * Mathf.Sin(theta), center.z+ RADIUS * Mathf.Cos(theta)); + GameObject o = GameObject.Instantiate(gesturePointPrefab); + o.GetComponent<Renderer>().material.color = Color.gray; + o.GetComponent<FadeOut>().fade = false; + o.transform.position = pos; + o.transform.localScale= gesturePointScale; + theta += deltaTheta; + } + } + private void Display2DGesture() { @@ -160,7 +188,7 @@ public class HandController : MonoBehaviour objCenter.transform.position = center; objCenter.GetComponent<Renderer>().material.color = new Color(1, 0, 0); points.Add(objCenter); - DisplayCircle(center); + DisplayCheckCircle(center); foreach (Vector2 point in rightHandGesture) { @@ -182,10 +210,7 @@ public class HandController : MonoBehaviour private void DisplayAverageSpeed() { - float average = 0f; - foreach (float speed in Speed) - average += speed; - SpeedText.text = "Speed" + (average / Speed.Count).ToString(); + SpeedText.text = "Speed" + (speedSum/rightHandGesture.Count).ToString(); } bool fullRotation = false; @@ -208,7 +233,6 @@ public class HandController : MonoBehaviour trackHand = !trackHand; beginTracking(); fullRotation = false; - } @@ -226,8 +250,6 @@ public class HandController : MonoBehaviour EndTracking(); fullRotation = true; } - - } @@ -247,7 +269,8 @@ public class HandController : MonoBehaviour Debug.Log("Start tracking Hand"); leftHandGesture.Clear(); rightHandGesture.Clear(); - Speed.Clear(); + // Speed.Clear(); + speedSum = 0; } void EndTracking() { @@ -273,9 +296,7 @@ public class HandController : MonoBehaviour SpeedText.text = GetAngle(rightHandGesture[0], rightHandGesture[rightHandGesture.Count - 1]).ToString(); //checkFullRotation(rightHandGesture[rightHandGesture.Count - 1]); } - } - } public float GetAngle(Vector2 a, Vector2 b) @@ -373,6 +394,7 @@ public class HandController : MonoBehaviour points.Clear(); } +/* void HandTracking2() { debugLeftHand.text = @@ -393,6 +415,7 @@ public class HandController : MonoBehaviour Debug.Log("Same X position"); } } + */ }