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

Get rid of time normalization

parent 951f5ff0
No related branches found
No related tags found
No related merge requests found
...@@ -67,8 +67,7 @@ public class Gesture ...@@ -67,8 +67,7 @@ public class Gesture
foreach (Gesture gesture in gesturesToMean) foreach (Gesture gesture in gesturesToMean)
meanTime += gesture.states.Count; meanTime += gesture.states.Count;
meanTime /= gesturesToMean.Count; meanTime /= gesturesToMean.Count;
foreach (Gesture gesture in gesturesToMean)
gesture.NormalizeTime (meanTime);
//for each frame, compute position and rotation mean //for each frame, compute position and rotation mean
for (int i = 0; i < meanTime; i++) for (int i = 0; i < meanTime; i++)
...@@ -77,16 +76,21 @@ public class Gesture ...@@ -77,16 +76,21 @@ public class Gesture
Vector4 rotationMean = new Vector4 (0, 0, 0, 0); Vector4 rotationMean = new Vector4 (0, 0, 0, 0);
float timestampMean = 0.0f; float timestampMean = 0.0f;
int gestureCount = 0;
foreach (Gesture gesture in gesturesToMean) foreach (Gesture gesture in gesturesToMean)
{ {
timestampMean += gesture.states [i].timestamp; if (gesture.states.Count > i)
positionMean += gesture.states [i].position; {
rotationMean += gesture.states [i].rotation; timestampMean += gesture.states [i].timestamp;
positionMean += gesture.states [i].position;
rotationMean += gesture.states [i].rotation;
gestureCount ++;
}
} }
timestampMean /= gesturesToMean.Count; timestampMean /= gestureCount;
positionMean /= gesturesToMean.Count; positionMean /= gestureCount;
rotationMean /= gesturesToMean.Count; rotationMean /= gestureCount;
GestureState stateMean = new GestureState (); GestureState stateMean = new GestureState ();
stateMean.position = positionMean; stateMean.position = positionMean;
...@@ -114,50 +118,6 @@ public class Gesture ...@@ -114,50 +118,6 @@ public class Gesture
{ {
} }
public void NormalizeTime(int pointNumber)
{
if (pointNumber == states.Count)
return;
float timeNormalizationFactor = pointNumber * 1.0f / states.Count;
//Debug.Log ("Time normalization, factor: " + timeNormalizationFactor);
List<GestureState> normalizedStates = new List<GestureState>();
float timestampStep = (states [states.Count - 1].timestamp - states [0].timestamp) / (states.Count - 1);
float normalizedTimestamp = states [0].timestamp;
for (int i = 0; i < pointNumber; i++)
{
GestureState normalizedState = new GestureState ();
int stateID = (int)Mathf.Floor(i / timeNormalizationFactor);
GestureState currentState = states [stateID];
Vector3 normalizedPosition = states [stateID].position;
Vector3 normalizedRotation = states [stateID].rotation;
if (stateID > 0 && stateID < states.Count - 1)
{
GestureState nextState = states [stateID + 1];
float smallTimestamp = (normalizedTimestamp - currentState.timestamp);
if (smallTimestamp != 0) {
float smallFactor = (nextState.timestamp - currentState.timestamp) / smallTimestamp;
Vector3 positionToNextState = nextState.position - currentState.position;
normalizedPosition = currentState.position + positionToNextState * smallFactor;
Vector4 rotationToNextState = nextState.rotation - currentState.rotation;
normalizedRotation = currentState.rotation + rotationToNextState * smallFactor;
}
}
normalizedState.position = normalizedPosition;
normalizedState.rotation = normalizedRotation;
normalizedState.timestamp = normalizedTimestamp;
normalizedStates.Add (normalizedState);
normalizedTimestamp += timestampStep;
}
states = normalizedStates;
}
public void Load (string path) public void Load (string path)
{ {
states = GestureLoader.Load (path); states = GestureLoader.Load (path);
...@@ -171,7 +131,8 @@ public class Gesture ...@@ -171,7 +131,8 @@ public class Gesture
foreach(GestureState state in states) foreach(GestureState state in states)
{ {
string line = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14}", Time.unscaledTime, string line = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14}",
state.timestamp,
state.position.x, state.position.y, state.position.z, state.position.x, state.position.y, state.position.z,
state.rotation.x, state.rotation.y, state.rotation.z, state.rotation.w, state.rotation.x, state.rotation.y, state.rotation.z, state.rotation.w,
0, 0, 0, 0, 0, 0,
......
This diff is collapsed.
fileFormatVersion: 2 fileFormatVersion: 2
guid: cd6e7f3979fe7d040baa17c40e58d1b4 guid: cd6e7f3979fe7d040baa17c40e58d1b4
timeCreated: 1515945232 timeCreated: 1515945964
licenseType: Free licenseType: Free
TextScriptImporter: TextScriptImporter:
externalObjects: {} externalObjects: {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment