/// <summary> /// Requests renewed data from the CyberGlove and populates the finger objects with this /// new data. /// </summary> protected virtual void pollJointData() { // Calculate the size of the array. int max = NR_FINGERS * NR_JOINTS + 2; // Create an array of doubles, that will later be filled with joint data. double[] arr = new double[max]; // Poll() fills arr with data and returns the size of the new array. // If that size is not 22, something weird is going on. int size = Poll(this.vhtHand, arr, max); // Fill the hand with data. populate(arr); // Update the position. PositionRecord pr = PositionParser.GetMatch(this); // Huge ugly if test... // Call the event if this position is recognized, and it's not the same // as the last recognized function. if (pr != null && pr != CurrentPosition && pr != LastPosition) { LastPosition = pr; PositionHasChanged(this, pr); // Check whether any motions have been detected... // There can be multiple matches. List <MotionRecord> matches = MotionParser.GetMatches(pr); foreach (MotionRecord mr in matches) { MotionHasDetected(this, mr); } } CurrentPosition = pr; DataHasUpdated(this); }
/// <summary> /// Polls for updated data. Because this is an emulator, the next line in the /// record will be used. /// </summary> protected override void pollJointData() { // Clone the current item into this hand, and increase the index Populate(sequence[currentPos++]); // Update the position. PositionRecord pr = PositionParser.GetMatch(this); // Huge ugly if test... // Call the event if this position is recognized, and it's not the same // as the last recognized function. if (pr != null && pr != CurrentPosition && pr != LastPosition) { LastPosition = pr; PositionHasChanged(this, pr); // Check whether any motions have been detected... // There can be multiple matches. List <MotionRecord> matches = MotionParser.GetMatches(pr); foreach (MotionRecord mr in matches) { MotionHasDetected(this, mr); } } CurrentPosition = pr; DataHasUpdated(this); // Check whether we need to stop polling now. checkIfEnded(); }
/// <summary> /// Main method for execution of the test program. /// </summary> /// <param name="args">Command line arguments.</param> static void Main(string[] args) { // Read TestSettings.ini first. initSettings(); try { // Make a new hand object that we will be using throughout this program. // This can either be an emulated one or an actual object. hand = emulating ? new HandEmulator(MOCK) : new Hand(); // Make the hand poll 24 times per second. hand.FPS = 24; // Add event handlers to the position and motion events. hand.PositionChanged += positionChanged; hand.MotionDetected += MotionDetected; Console.WriteLine("Initialisation went fine."); } catch (ConnectionFailedException e) { // In connection can't be made, so not much can be done. // Exit time! Console.WriteLine(e.Message); Console.ReadKey(true); return; } try { // Parse the positions file's contents and print a debugstring. PositionParser positionParser = new PositionParser(POSITIONS); positionParser.Parse(); Console.WriteLine(positionParser.DebugString); // Parse the motions file. MotionParser motionParser = new MotionParser(MOTIONS); motionParser.Parse(); } catch (ArgumentException e) { Console.WriteLine("ArgumentException: " + e.Message); } catch (MalformedException e) { Console.WriteLine("MalformedException in {0}: {1}", e.Path, e.Message); } // Begin the main part of the program. First create the input // command parser. initCommandParser(); // Ask for input. Console.Write(">>> "); string input = Console.ReadLine(); string cmd = null; do { // After the first space, some parameters may follow. Separate the input // in the command, and the parameters. string[] parts = input.Split(new char[] { ' ' }, 2); cmd = parts[0]; if (commandParser.ContainsKey(cmd)) { // Invoke the function represented by this command. bool rv = (bool)commandParser[cmd].DynamicInvoke(parts.Length > 1 ? parts[1] : ""); // Based on the function's return value, give some feedback. Console.WriteLine("Command exited " + (rv ? "without" : "with") + " errors."); } else { // Give the user some feedback about the list of existing commands. unknownCommand(); } // Read next input command. Console.Write(">>> "); input = Console.ReadLine(); } while (true); }
public void ControlEntity(float delta) { this.motion = MotionParser.GetMoveInput(); this.target = Vector2.Zero; this._state = this._state.ParseInput(delta, this.motion, this.target); }