diff --git a/Assets/Gesture/GestureLoader.cs b/Assets/Gesture/GestureLoader.cs index 3bc7e5f9535b38c154475a45353c3d80fd2924fe..b5154ac101c74973e1ca7da4147a75fce12c6db7 100644 --- a/Assets/Gesture/GestureLoader.cs +++ b/Assets/Gesture/GestureLoader.cs @@ -10,6 +10,9 @@ public class GestureLoader CSVOutputGrid csvGrid = CSVReader.SplitCsvGrid (reader.ReadToEnd ()); string[,] csvStrings = csvGrid.grid; + bool loadLeftHand = true; + bool handDetermined = false; + List<GestureState> states = new List<GestureState>(); for (int i = 0; i < csvGrid.linesLength; i++) { @@ -22,16 +25,36 @@ public class GestureLoader //we need timestamp, x, y, z of palm string[] line = csvStrings[0,i].Split (' '); + //determine which hand to load + if (!handDetermined && float.Parse (line [1]) == 0) + { + loadLeftHand = false; + handDetermined = true; + } + //for now we only save the left palm's coordinates GestureState state = new GestureState (); state.timestamp = float.Parse(line [0]); - state.position.x = float.Parse(line [1]); - state.position.y = float.Parse(line [2]); - state.position.z = float.Parse(line [3]); - state.rotation.x = float.Parse(line [4]); - state.rotation.y = float.Parse(line [5]); - state.rotation.z = float.Parse(line [6]); - state.rotation.w = float.Parse(line [7]); + if (loadLeftHand) + { + state.position.x = float.Parse (line [1]); + state.position.y = float.Parse (line [2]); + state.position.z = float.Parse (line [3]); + state.rotation.x = float.Parse (line [4]); + state.rotation.y = float.Parse (line [5]); + state.rotation.z = float.Parse (line [6]); + state.rotation.w = float.Parse (line [7]); + } + else + { + state.position.x = float.Parse (line [8]); + state.position.y = float.Parse (line [9]); + state.position.z = float.Parse (line [10]); + state.rotation.x = float.Parse (line [11]); + state.rotation.y = float.Parse (line [12]); + state.rotation.z = float.Parse (line [13]); + state.rotation.w = float.Parse (line [14]); + } states.Add (state); } reader.Close(); diff --git a/Assets/Replay/LiveComparer.cs b/Assets/Replay/LiveComparer.cs index 939d34ec8cbdbfb029513c9ffc1c4eea309503bc..d2b8241a3b476a24ad6640edefc9b02ec99585ed 100644 --- a/Assets/Replay/LiveComparer.cs +++ b/Assets/Replay/LiveComparer.cs @@ -24,6 +24,7 @@ public class LiveComparer : MonoBehaviour Vector4 leftPalmRotation = Vector3.zero; Vector3 rightPalmPosition = Vector3.zero; Vector4 rightPalmRotation = Vector3.zero; + bool compareLeftHand = false; Vector3 offsetPosition = Vector3.zero; @@ -42,7 +43,7 @@ public class LiveComparer : MonoBehaviour if (replay.currentFrame >= 0 && replay.currentFrame < 100) { if (replay.currentFrame == 0) - UpdateOffsetPosition (); + InitializeComparison (); ComputeFrameScore (); @@ -71,6 +72,21 @@ public class LiveComparer : MonoBehaviour backgroundCircle.transform.Rotate(new Vector3(0, -backGroundAngleOffset, 0)); //offset for target } + void InitializeComparison() + { + UpdateOffsetPosition (); + FindHandToCompare (); + } + + void FindHandToCompare() + { + //if left hand palm has non null values, chose it for comparison. Otherwise chose the right hand + if (leftPalmPosition.x != 0 && leftPalmPosition.y != 0 && leftPalmPosition.z != 0) + compareLeftHand = true; + else + compareLeftHand = false; + } + void UpdateOffsetPosition () { offsetPosition = replay.gestureToReplay.states [replay.currentFrame].position - leftPalmPosition; @@ -82,7 +98,21 @@ public class LiveComparer : MonoBehaviour frameScore = scoreOffset; float scoreFactor = 100.0f; - Vector3 differencePosition = offsetPosition + leftPalmPosition - replay.gestureToReplay.states [replay.currentFrame].position; + Vector3 palmPosition = Vector3.zero; + Vector3 palmRotation = Vector3.zero; + + if (compareLeftHand) + { + palmPosition = leftPalmPosition; + palmRotation = leftPalmRotation; + } + else + { + palmPosition = rightPalmPosition; + palmRotation = rightPalmRotation; + } + + Vector3 differencePosition = offsetPosition + palmPosition - replay.gestureToReplay.states [replay.currentFrame].position; Vector4 differenceRotation = leftPalmRotation - replay.gestureToReplay.states [replay.currentFrame].rotation; Vector3 variancePosition = replay.gestureVariance.states [replay.currentFrame].position; Vector4 varianceRotation = replay.gestureVariance.states [replay.currentFrame].rotation;