void InterpretGestures() { //note: for the rush segments, we care more about current state //than changes in state, but other games will be slightly different //Debug.Log(arm_states.Count-1); if (arm_states.Count == 0) { return; } ArmsSnapshot cur_state = arm_states[arm_states.Count - 1]; /*float left_out; * float right_out; * float arm_length = cur_state.GetLength();*/ //order is hand, elbow, shoulder //we're going to generate angles on elbow joint and shoulder joint if (!train) { List <float> angles = cur_state.GenerateAngles(); foreach (BayesianClassifier classifier in classifiers) { if (best < classifier.GetProbablity(angles)) { best = classifier.GetProbablity(angles); Debug.Log(classifier.pose_name + " " + best); } //Debug.Log(classifier.pose_name + " " + classifier.GetProbablity(angles)); if (classifier.GetProbablity(angles) > .001) { Debug.Log("POSE DETECTED: " + classifier.pose_name); } } } /* //reset droplet movements * droplet.back = droplet.left = droplet.right = droplet.up = droplet.down = 0f; * * //left_out and right_out are going to be on a scale from 0 to 1 * // 0 all the way in, 1 all the way out * left_out = (cur_state.left_joints[2].position.x - cur_state.left_joints[0].position.x)/arm_length; * right_out = (cur_state.right_joints[0].position.x - cur_state.right_joints[2].position.x)/arm_length; * * * //back, left, right * //back - both hands forward * if(left_out < 0.5 && right_out < 0.5){ * droplet.back = 1 - (left_out + right_out)/2; * state = "stop"; * } * //left - both arms out, left down, right up * else if(cur_state.left_joints[0].position.y < cur_state.left_joints[2].position.y - 3*arm_length/4 * && cur_state.right_joints[0].position.y > cur_state.right_joints[2].position.y - arm_length/4){ * droplet.left = (cur_state.left_joints[2].position.y - cur_state.left_joints[0].position.y)/arm_length; * state = "left"; * } * //right - both arms out, left up, right down * else if(cur_state.left_joints[0].position.y > cur_state.left_joints[2].position.y - arm_length/4 * && cur_state.right_joints[0].position.y < cur_state.right_joints[2].position.y - 3*arm_length/4){ * droplet.right = (cur_state.right_joints[2].position.y - cur_state.right_joints[0].position.y)/arm_length; * state = "right"; * } * * //INVERTED controls - up and down * else if(cur_state.left_joints[0].position.y < cur_state.left_joints[2].position.y - 3*arm_length/4 * && cur_state.right_joints[0].position.y < cur_state.right_joints[2].position.y - 3*arm_length/4){ * //set their up movement based on extremity of their arm motion * float displacement = (cur_state.left_joints[2].position.y - cur_state.left_joints[0].position.y); * droplet.up = displacement/arm_length; * state = "up"; * } * * * else if(cur_state.left_joints[0].position.y > cur_state.left_joints[2].position.y - arm_length/4 * && cur_state.right_joints[0].position.y > cur_state.right_joints[2].position.y - arm_length/4){ * float displacement = (cur_state.left_joints[0].position.y - cur_state.left_joints[2].position.y); * droplet.down = displacement/arm_length; * state = "down"; * } * else * state = "none"; * * //RESET APPLICATION CONTROLS * Vector3 arm = cur_state.right_joints[0].position - cur_state.right_joints[2].position; * Vector3 down = new Vector3(cur_state.right_joints[2].position.x, * cur_state.right_joints[2].position.y-1, * cur_state.right_joints[2].position.z) - cur_state.right_joints[2].position; * Vector3 larm = cur_state.left_joints[0].position - cur_state.left_joints[2].position; * Vector3 ldown = new Vector3(cur_state.left_joints[2].position.x, * cur_state.left_joints[2].position.y-1, * cur_state.left_joints[2].position.z) - cur_state.left_joints[2].position; * * * //get angle between the vectors * float angle = Vector3.Angle(down, arm); * //Debug.Log(right_out + " Angle is " + angle + " " + reset_timer + " " + Time.deltaTime); * float langle = Vector3.Angle(ldown, larm); * * //arm must be seventy percent extended and shoulder to hand is twenty to forty degrees from downwards * if(right_out > .5 && (5 < angle && angle < 60) && langle < 15 ){ * reset_timer += Time.deltaTime; * state = "reset"; * } * else * reset_timer = 0f; * * * * * //there is an arm forward and it is tilted skyward, go up * if(left_out < 0.3f){ * if(cur_state.left_joints[0].position.y > cur_state.left_joints[2].position.y) * droplet.up = 1f; * else if(cur_state.left_joints[0].position.y < cur_state.left_joints[2].position.y) * droplet.down = 1f; * } * //there is an arm forward and tilted down, go down * else if(right_out < 0.3f){ * if(cur_state.right_joints[0].position.y > cur_state.right_joints[2].position.y) * droplet.up = 1f; * else if(cur_state.right_joints[0].position.y < cur_state.right_joints[2].position.y) * droplet.down = 1f; * }*/ }
void OnGUI() { if (train) { train_name = GUI.TextField(new Rect(25, 100, 100, 25), train_name); if (recording) { if (GUI.Button(new Rect(Screen.width - 150, 50, 100, 50), "Rec")) { recorded_states.Add(new ArmsSnapshot(left_arm, right_arm)); } if (GUI.Button(new Rect(25, 25, 100, 50), "Stop and Save")) { RecordValues(); recording = false; } if (GUI.Button(new Rect(150, 25, 100, 50), "Stop (Don't Save)")) { recording = false; } } else { if (GUI.Button(new Rect(25, 25, 100, 50), "Record")) { recording = true; } } if (GUI.Button(new Rect(275, 25, 100, 50), "Stop Training")) { train = false; } } else { if (GUI.Button(new Rect(25, 25, 100, 50), "Train")) { train = true; } if (GUI.Button(new Rect(150, 25, 100, 50), "Update Library")) { ReadFile(); } ArmsSnapshot cur_state = arm_states[arm_states.Count - 1]; List <float> angles = cur_state.GenerateAngles(); string line = ""; foreach (float angle in angles) { line += angle + " "; } GUI.Label(new Rect(50, Screen.height - 100, 200, 50), line); for (int i = 0; i < classifiers.Count; i++) { if (classifiers[i].GetProbablity(angles) > best_prob) { identification = i; best_data = angles; best_changed = true; best_prob = classifiers[i].GetProbablity(angles); best_name = classifiers[i].pose_name; } string l = classifiers[i].pose_name + " " + classifiers[i].GetProbablity(angles); GUI.Label(new Rect(50, Screen.height - 150 - 50 * i, 200, 50), l); } } if (best_changed) { GUI.Label(new Rect(50, 200, 500, 50), "Best " + best_name + " is " + best_prob + ". Accept?"); if (GUI.Button(new Rect(50, 250, 100, 25), "Accept")) { classifiers[identification].AddData(best_data); best_changed = false; RecordValues(); } if (GUI.Button(new Rect(50, 250, 100, 25), "Reject")) { best_changed = false; } best_prob = 0; } }