Skip to content
Snippets Groups Projects
Commit 0b83d6fd authored by florian.hassler's avatar florian.hassler
Browse files

better display for gesture detection

parent 4f1b7ace
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,32 @@ AnimatorState: ...@@ -71,6 +71,32 @@ AnimatorState:
m_MirrorParameter: m_MirrorParameter:
m_CycleOffsetParameter: m_CycleOffsetParameter:
m_TimeParameter: 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 --- !u!1107 &1107447109261544868
AnimatorStateMachine: AnimatorStateMachine:
serializedVersion: 5 serializedVersion: 5
...@@ -83,6 +109,9 @@ AnimatorStateMachine: ...@@ -83,6 +109,9 @@ AnimatorStateMachine:
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: 1102209914930564344} m_State: {fileID: 1102209914930564344}
m_Position: {x: 384, y: 120, z: 0} 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_ChildStateMachines: []
m_AnyStateTransitions: [] m_AnyStateTransitions: []
m_EntryTransitions: [] m_EntryTransitions: []
......
...@@ -9,12 +9,13 @@ Material: ...@@ -9,12 +9,13 @@ Material:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: point_left m_Name: point_left
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 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_LightmapFlags: 4
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: 3000
stringTagMap: {} stringTagMap:
RenderType: Transparent
disabledShaderPasses: [] disabledShaderPasses: []
m_SavedProperties: m_SavedProperties:
serializedVersion: 3 serializedVersion: 3
...@@ -59,19 +60,19 @@ Material: ...@@ -59,19 +60,19 @@ Material:
- _BumpScale: 1 - _BumpScale: 1
- _Cutoff: 0.5 - _Cutoff: 0.5
- _DetailNormalMapScale: 1 - _DetailNormalMapScale: 1
- _DstBlend: 0 - _DstBlend: 10
- _GlossMapScale: 1 - _GlossMapScale: 1
- _Glossiness: 0 - _Glossiness: 0
- _GlossyReflections: 0 - _GlossyReflections: 0
- _Metallic: 0 - _Metallic: 0
- _Mode: 0 - _Mode: 2
- _OcclusionStrength: 1 - _OcclusionStrength: 1
- _Parallax: 0.02 - _Parallax: 0.02
- _SmoothnessTextureChannel: 0 - _SmoothnessTextureChannel: 0
- _SpecularHighlights: 0 - _SpecularHighlights: 0
- _SrcBlend: 1 - _SrcBlend: 5
- _UVSec: 0 - _UVSec: 0
- _ZWrite: 1 - _ZWrite: 0
m_Colors: m_Colors:
- _Color: {r: 0, g: 0.55598927, b: 1, a: 1} - _Color: {r: 0, g: 0.55598927, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
...@@ -13,6 +13,7 @@ GameObject: ...@@ -13,6 +13,7 @@ GameObject:
- component: {fileID: 6982965154212898579} - component: {fileID: 6982965154212898579}
- component: {fileID: 6982965154212898578} - component: {fileID: 6982965154212898578}
- component: {fileID: 8761357492929044139} - component: {fileID: 8761357492929044139}
- component: {fileID: 2621446007440220247}
m_Layer: 9 m_Layer: 9
m_Name: GesturePoint m_Name: GesturePoint
m_TagString: gesture m_TagString: gesture
...@@ -108,3 +109,16 @@ Rigidbody: ...@@ -108,3 +109,16 @@ Rigidbody:
m_Interpolate: 0 m_Interpolate: 0
m_Constraints: 0 m_Constraints: 0
m_CollisionDetection: 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
...@@ -30,7 +30,7 @@ Transform: ...@@ -30,7 +30,7 @@ Transform:
m_GameObject: {fileID: 7550860099689547248} m_GameObject: {fileID: 7550860099689547248}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} 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_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
......
...@@ -1134,8 +1134,8 @@ RectTransform: ...@@ -1134,8 +1134,8 @@ RectTransform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1226245320} m_GameObject: {fileID: 1226245320}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 23.69} m_LocalPosition: {x: 0, y: 0, z: 940}
m_LocalScale: {x: 0.056603774, y: 0.056603774, z: 0.056603774} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 1097496874} - {fileID: 1097496874}
- {fileID: 189233416} - {fileID: 189233416}
...@@ -1147,7 +1147,7 @@ RectTransform: ...@@ -1147,7 +1147,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {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} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1312997771 --- !u!1 &1312997771
GameObject: GameObject:
......
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);
}
}
...@@ -7,29 +7,35 @@ using UnityEngine.XR; ...@@ -7,29 +7,35 @@ using UnityEngine.XR;
public class HandController : MonoBehaviour public class HandController : MonoBehaviour
{ {
public static HandController instance;
private const float RADIUS = 0.2f;
private LineRenderer lineRenderer;
public Text debugLeftHand; public Text debugLeftHand;
public Text debugRightHand; public Text debugRightHand;
public Text Msg; public Text Msg;
public Text SpeedText; public Text SpeedText;
private readonly Vector3 pointSize = new Vector3(0.04f, 0.04f, 0.04f);
public GameObject referencePointPrefab; public GameObject referencePointPrefab;
public GameObject gesturePointPrefab; 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> leftHandGesture = new List<Vector2>();
private List<Vector2> rightHandGesture = new List<Vector2>(); private List<Vector2> rightHandGesture = new List<Vector2>();
Vector2 LastPosition = Vector2.zero; private Vector2 LastPosition = Vector2.zero;
List<float> Speed = new List<float>(); //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 bool trackHand = false;
private List<GameObject> points = new List<GameObject>(); private List<GameObject> points = new List<GameObject>();
private List<GameObject> trace = new List<GameObject>();
private int CorrectPoint = 0; private int CorrectPoint = 0;
private void Awake() private void Awake()
...@@ -43,6 +49,7 @@ public class HandController : MonoBehaviour ...@@ -43,6 +49,7 @@ public class HandController : MonoBehaviour
{ {
Destroy(gameObject); Destroy(gameObject);
} }
} }
public void IncrementCorrectPoint() public void IncrementCorrectPoint()
...@@ -52,9 +59,10 @@ public class HandController : MonoBehaviour ...@@ -52,9 +59,10 @@ public class HandController : MonoBehaviour
private void Start() private void Start()
{ {
referencePointPrefab.transform.localScale = pointSize; referencePointPrefab.transform.localScale = referencePointScale;
gesturePointPrefab.transform.localScale = pointSize; gesturePointPrefab.transform.localScale = gesturePointScale;
Msg.text = ""; Msg.text = "";
DisplayReferenceCircle();
} }
...@@ -64,7 +72,8 @@ public class HandController : MonoBehaviour ...@@ -64,7 +72,8 @@ public class HandController : MonoBehaviour
if (LastPosition != Vector2.zero) if (LastPosition != Vector2.zero)
{ {
float movementPerFrame = Vector2.Distance(LastPosition, CurrentPosition); 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 ...@@ -79,17 +88,17 @@ public class HandController : MonoBehaviour
{ {
if (trackHand) if (trackHand)
{ {
Vector2 currentPosition = new Vector2(rightHandPosition.z, rightHandPosition.y);
// add hand position to respective arrays // add hand position to respective arrays
leftHandGesture.Add(new Vector2(leftHandPosition.z, leftHandPosition.y)); // leftHandGesture.Add(new Vector2(leftHandPosition.z, leftHandPosition.y));
rightHandGesture.Add(new Vector2(rightHandPosition.z, rightHandPosition.y)); if(Vector2.Distance(currentPosition,LastPosition)>MIN_DELTA)
Vector2 currentPosition = new Vector2(rightHandPosition.z, rightHandPosition.y); {
rightHandGesture.Add(currentPosition);
CalculateSpeed(currentPosition); CalculateSpeed(currentPosition);
LastPosition = currentPosition; LastPosition = currentPosition;
displayPoint(false, rightHandPosition); displayPoint(false, rightHandPosition);
}
} }
// display position for debug purpose // display position for debug purpose
...@@ -133,7 +142,7 @@ public class HandController : MonoBehaviour ...@@ -133,7 +142,7 @@ public class HandController : MonoBehaviour
void DisplayCircle(Vector3 center) void DisplayCheckCircle(Vector3 center)
{ {
int vertexCount = rightHandGesture.Count; int vertexCount = rightHandGesture.Count;
float deltaTheta = (2f * Mathf.PI) / vertexCount; float deltaTheta = (2f * Mathf.PI) / vertexCount;
...@@ -150,6 +159,25 @@ public class HandController : MonoBehaviour ...@@ -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() private void Display2DGesture()
{ {
...@@ -160,7 +188,7 @@ public class HandController : MonoBehaviour ...@@ -160,7 +188,7 @@ public class HandController : MonoBehaviour
objCenter.transform.position = center; objCenter.transform.position = center;
objCenter.GetComponent<Renderer>().material.color = new Color(1, 0, 0); objCenter.GetComponent<Renderer>().material.color = new Color(1, 0, 0);
points.Add(objCenter); points.Add(objCenter);
DisplayCircle(center); DisplayCheckCircle(center);
foreach (Vector2 point in rightHandGesture) foreach (Vector2 point in rightHandGesture)
{ {
...@@ -182,10 +210,7 @@ public class HandController : MonoBehaviour ...@@ -182,10 +210,7 @@ public class HandController : MonoBehaviour
private void DisplayAverageSpeed() private void DisplayAverageSpeed()
{ {
float average = 0f; SpeedText.text = "Speed" + (speedSum/rightHandGesture.Count).ToString();
foreach (float speed in Speed)
average += speed;
SpeedText.text = "Speed" + (average / Speed.Count).ToString();
} }
bool fullRotation = false; bool fullRotation = false;
...@@ -208,7 +233,6 @@ public class HandController : MonoBehaviour ...@@ -208,7 +233,6 @@ public class HandController : MonoBehaviour
trackHand = !trackHand; trackHand = !trackHand;
beginTracking(); beginTracking();
fullRotation = false; fullRotation = false;
} }
...@@ -226,8 +250,6 @@ public class HandController : MonoBehaviour ...@@ -226,8 +250,6 @@ public class HandController : MonoBehaviour
EndTracking(); EndTracking();
fullRotation = true; fullRotation = true;
} }
} }
...@@ -247,7 +269,8 @@ public class HandController : MonoBehaviour ...@@ -247,7 +269,8 @@ public class HandController : MonoBehaviour
Debug.Log("Start tracking Hand"); Debug.Log("Start tracking Hand");
leftHandGesture.Clear(); leftHandGesture.Clear();
rightHandGesture.Clear(); rightHandGesture.Clear();
Speed.Clear(); // Speed.Clear();
speedSum = 0;
} }
void EndTracking() void EndTracking()
{ {
...@@ -273,9 +296,7 @@ public class HandController : MonoBehaviour ...@@ -273,9 +296,7 @@ public class HandController : MonoBehaviour
SpeedText.text = GetAngle(rightHandGesture[0], rightHandGesture[rightHandGesture.Count - 1]).ToString(); SpeedText.text = GetAngle(rightHandGesture[0], rightHandGesture[rightHandGesture.Count - 1]).ToString();
//checkFullRotation(rightHandGesture[rightHandGesture.Count - 1]); //checkFullRotation(rightHandGesture[rightHandGesture.Count - 1]);
} }
} }
} }
public float GetAngle(Vector2 a, Vector2 b) public float GetAngle(Vector2 a, Vector2 b)
...@@ -373,6 +394,7 @@ public class HandController : MonoBehaviour ...@@ -373,6 +394,7 @@ public class HandController : MonoBehaviour
points.Clear(); points.Clear();
} }
/*
void HandTracking2() void HandTracking2()
{ {
debugLeftHand.text = debugLeftHand.text =
...@@ -393,6 +415,7 @@ public class HandController : MonoBehaviour ...@@ -393,6 +415,7 @@ public class HandController : MonoBehaviour
Debug.Log("Same X position"); Debug.Log("Same X position");
} }
} }
*/
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment