// Use this for initialization void Start() { if (ks_master == null) ks_master = this; raw_joint_pos[(int)Joints.HIP_CENTER] = new Vector3(0.0f, 0.0f, 0.0f); game_joint_pos[(int)Joints.HIP_CENTER] = new Vector3(0.0f, 0.0f, 0.0f); // adds all the game objects to the associated hashmap for the enum type if (skHead != null) add_skeleton_joint (Joints.HEAD, skHead); if (skSpine != null) add_skeleton_joint (Joints.SPINE, skSpine); if (skHipCenter != null) add_skeleton_joint (Joints.HIP_CENTER, skHipCenter); if (skShoulderCenter != null) add_skeleton_joint (Joints.SHOULDER_CENTER, skShoulderCenter); if (skLeftShoulder != null) add_skeleton_joint (Joints.SHOULDER_LEFT, skLeftShoulder); if (skLeftElbow != null) add_skeleton_joint (Joints.ELBOW_LEFT, skLeftElbow); if (skLeftWrist != null) add_skeleton_joint (Joints.WRIST_LEFT, skLeftWrist); if (skLeftHand != null) add_skeleton_joint (Joints.HAND_LEFT, skLeftHand); if (skRightShoulder != null) add_skeleton_joint (Joints.SHOULDER_RIGHT, skRightShoulder); if (skRightElbow != null) add_skeleton_joint (Joints.ELBOW_RIGHT, skRightElbow); if (skRightWrist != null) add_skeleton_joint (Joints.WRIST_RIGHT, skRightWrist); if (skRightHand != null) add_skeleton_joint (Joints.HAND_RIGHT, skRightHand); // get the bone lengths and positions of the default pose for the rigged character. foreach (KeyValuePair<Joints, GameObject> joint in skeleton) { if (joint.Key != Joints.HIP_CENTER) { bone_lengths[(int)joint.Key] = joint.Value.transform.localPosition.magnitude; model_joint_pos[(int)joint.Key] = joint.Value.transform.localPosition; } } // start the kinect skeleton server and the kinect skeleton client for this game client = new KinectSkeletonClient(); // starts the joint data update thread thr_joint_data_update = new Thread(this.run_joint_data_update); thr_joint_data_update.Start(); // some testing gestures // this should be moved out and in to a json file ideally. // ok // Gesture left_hand_up = new Gesture("left-hand-up", (int)ActionManager.actions.handUp); // left_hand_up.constraints.Add( new JointConstraint( this, // Joints.HAND_LEFT, // Joints.SHOULDER_LEFT, // JointConstraint.Relations.COMPONENT_DISTANCE, // JointConstraint.Operators.GREATER_THAN, // new Vector3(-10.0f, 1.2f, -10.0f) ) ); // Gesture left_hand_down = new Gesture("left-hand-down", (int)ActionManager.actions.handDown); // left_hand_down.constraints.Add ( new JointConstraint(this, // Joints.HAND_LEFT, // Joints.SPINE, // JointConstraint.Relations.COMPONENT_DISTANCE, // JointConstraint.Operators.LESS_THAN, // new Vector3(-10.0f, 0.0f, -10.0f) ) ); // ok // Gesture left_hand_left = new Gesture("left-hand-left", (int)ActionManager.actions.handLeft); // left_hand_left.constraints.Add ( new JointConstraint(this, // Joints.HAND_LEFT, // Joints.SHOULDER_LEFT, // JointConstraint.Relations.COMPONENT_DISTANCE, // JointConstraint.Operators.LESS_THAN, // new Vector3(-2.0f, 10.0f, 10.0f) ) ); // ok // Gesture left_hand_right = new Gesture("left-hand-right", (int)ActionManager.actions.handRight); // left_hand_right.constraints.Add ( new JointConstraint(this, // Joints.HAND_LEFT, // Joints.SHOULDER_LEFT, // JointConstraint.Relations.COMPONENT_DISTANCE, // JointConstraint.Operators.GREATER_THAN, // new Vector3(1.0f, -10.0f, -10.0f) ) ); // ok Gesture right_hand_up = new Gesture("right-hand-up", (int)ActionManager.actions.handUp); right_hand_up.constraints.Add( new JointConstraint(this, Joints.HAND_RIGHT, Joints.SHOULDER_RIGHT, JointConstraint.Relations.COMPONENT_DISTANCE, JointConstraint.Operators.GREATER_THAN, new Vector3(-10.0f, 1.2f, -10.0f) ) ); // ok // Gesture right_hand_left = new Gesture("right-hand-left", (int)ActionManager.actions.handLeft); // right_hand_left.constraints.Add ( new JointConstraint(this, // Joints.HAND_RIGHT, // Joints.SHOULDER_RIGHT, // JointConstraint.Relations.COMPONENT_DISTANCE, // JointConstraint.Operators.LESS_THAN, // new Vector3(-1.0f, 10.0f, 10.0f) ) ); // // ok // Gesture right_hand_right = new Gesture("right-hand-right", (int)ActionManager.actions.handRight); // right_hand_right.constraints.Add ( new JointConstraint(this, // Joints.HAND_RIGHT, // Joints.SHOULDER_RIGHT, // JointConstraint.Relations.COMPONENT_DISTANCE, // JointConstraint.Operators.GREATER_THAN, // new Vector3(2.0f, -10.0f, -10.0f) ) ); // Gesture super_charge_charging = new Gesture("super-charge-charging", (int)ActionManager.actions.superShoot); // super_charge_charging.constraints.Add ( new JointConstraint(this, // Joints.HAND_LEFT, // Joints.SHOULDER_LEFT, // JointConstraint.Relations.DISTANCE, // JointConstraint.Operators.LESS_THAN, // new Vector3(4.0f, 0.0f, 0.0f) ) ); // super_charge_charging.constraints.Add( new JointConstraint(this, // Joints.HAND_RIGHT, // Joints.SHOULDER_RIGHT, // JointConstraint.Relations.COMPONENT_DISTANCE, // JointConstraint.Operators.GREATER_THAN, // new Vector3(-10.0f, 1.2f, -10.0f) ) ); // gestures.Add("super-charge-charging", super_charge_charging); // gestures to handle either left knee raised or right knee raised Gesture switch_places_ll = new Gesture("switch-places-left-leg", (int)ActionManager.actions.switchPlaces); switch_places_ll.constraints.Add( new JointConstraint(this, Joints.KNEE_LEFT, Joints.HIP_CENTER, JointConstraint.Relations.COMPONENT_DISTANCE, JointConstraint.Operators.GREATER_THAN, new Vector3(-10.0f, -3.0f, -10.0f) ) ); Gesture switch_places_rl = new Gesture("switch-places-right-leg", (int)ActionManager.actions.switchPlaces); switch_places_rl.constraints.Add( new JointConstraint(this, Joints.KNEE_RIGHT, Joints.HIP_CENTER, JointConstraint.Relations.COMPONENT_DISTANCE, JointConstraint.Operators.GREATER_THAN, new Vector3(-10.0f, -3.0f, -10.0f) ) ); // AnimatedGesture stupid_wave = new AnimatedGesture("stupid-wave", 2); // stupid_wave.add_keyframe(right_hand, 1.0f, 0.0f); // stupid_wave.add_keyframe(left_hand, 1.0f, 0.0f); // animated_gestures.Add("stupid-wave", stupid_wave); // 2 gestures.Add("switch-places-ll", switch_places_ll); gestures.Add("switch-places-rl", switch_places_rl); // gestures.Add( "left-hand-up", left_hand_up ); gestures.Add("right-hand-up", right_hand_up); // 4 // gestures.Add ("left-hand-left", left_hand_left); // gestures.Add ("right-hand-left", right_hand_left); // gestures.Add ("left-hand-right", left_hand_right); // gestures.Add ("right-hand-right", right_hand_right); Mapping aim_x = new Mapping(this, Joints.HAND_LEFT, new Vector3(1, 0, 0)); aim_x.push_joint(Joints.HIP_CENTER, new Vector3(1, 0, 0), Mapping.Operators.SUBTRACT); aim_x.set_bound(4.5f); aim_x.normalize(); mappings.Add("aim_x", aim_x ); Mapping aim_y = new Mapping(this, Joints.HAND_LEFT, new Vector3(0, 1, 0)); aim_y.push_joint(Joints.SHOULDER_RIGHT, new Vector3(0, 1, 0), Mapping.Operators.SUBTRACT); aim_y.set_bound(4.5f); aim_y.normalize(); mappings.Add("aim_y", aim_y ); }