Skip to content
Snippets Groups Projects
Commit 9939fdda authored by Alexis Iakovenko's avatar Alexis Iakovenko
Browse files

Determine which hand to compare or load automatically

parent e1a40582
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment