/// <summary> ***************************** /// Creates a new sprite List at each touch location. /// </summary> /// <param name="touches">Where the touch is</param> private int InsertEcoliAtTouchPosition(ReadOnlyTouchPointCollection touches) { //eventually each sprite has to be different and have it's own list? int count = 0; foreach (TouchPoint touch in touches) { // Creates a ecoli list for each touch that has been recognized as a finger, // or for any touch if finger recognition is not supported. //needs to create a new list of spirtes with a n ecoli heading it and a tail behind it, with an id? if (touch.IsFingerRecognized || InteractiveSurface.PrimarySurfaceDevice.IsFingerRecognitionSupported == false) { //make a new linkedlist for the ecoli and a trail LinkedList <SpriteData> ecoli = new LinkedList <SpriteData>(); //Add a new functin? Find out what color Ecoli and display the right color sprite and color tail //?? ARE WE SITLL DOING THIS?? If it's the cleaner or the toxic one then Black or white tail? //spriteOrigin = new Vector2(touch.X, touch.Y); SpriteData sprite = new SpriteData(new Vector2(touch.X, touch.Y), touch.Orientation, 1.0f); //would add the color ecoli.AddLast(sprite); // always add to the end //just add? nope. //Finally add LinkedList onto List of LinkedList so that it can be included when drawn ecoliList.Add(ecoli); //Is it helpful to be counting? count++; } } return(count); }
/// <summary> /// Allows the app to run logic such as updating the world, /// checking for collisions, gathering input and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (ApplicationServices.WindowAvailability != WindowAvailability.Unavailable) { // get the current state ReadOnlyTouchPointCollection touches = touchTarget.GetState(); spriteOrigin = orginPlaceHolder; //Actually, first update the position of the E.coli MoveEcoli(gameTime); // first update the state of any existing sprites ShrinkSprites((float)gameTime.ElapsedGameTime.Milliseconds / (float)millisecondsToDisappear); // next update the sprites list with new additions InsertSpritesAtTouchPositions(touches); // finally remove any invisible sprites RemoveInvisibleSprites(); orginPlaceHolder = spriteOrigin; } base.Update(gameTime); }
/// <summary> UPDATE /// Allows the app to run logic such as updating the world, /// checking for collisions, gathering input and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (ApplicationServices.WindowAvailability != WindowAvailability.Unavailable) { // get the current state ReadOnlyTouchPointCollection touches = touchTarget.GetState(); //might benefit from a for each list in here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ? //// next update the sprites list with new additions //InsertSpritesAtTouchPositions(touches); //Actually, first update the position of the E.coli MoveEcoli(gameTime); // Add an ecoli if the user touches surface InsertEcoliAtTouchPosition(touches); //First add a trail to where the ecoli has moved Do I need variable? InsertTrailAfterEcoli(); //spriteOrigin = orginPlaceHolder; // first update the state of any existing sprites ShrinkSprites((float)gameTime.ElapsedGameTime.Milliseconds / (float)millisecondsToDisappear); // finally remove any invisible sprites RemoveInvisibleSprites(); } base.Update(gameTime); }
public void processContactManipulator(TouchPoint c, ReadOnlyTouchPointCollection currentContacts, ReadOnlyTouchPointCollection previousContacts) { List <Manipulator2D> removedManipulators = new List <Manipulator2D>(); if (previousContacts != null) { // Find all the contacts that were removed since the last check. foreach (TouchPoint contact in previousContacts) { // Create a temporary variable for the following method call. TouchPoint tempContact; // Determine if the Contact object from the previous list is in the current list. if (!currentContacts.TryGetTouchPointFromId(contact.Id, out tempContact)) { // The contact was not found in the list of current contacts, so it has been removed. // Copy the Contact object information to a new Manipulator object and add // the Manipulator object to the removedManipulators list. removedManipulators.Add(new Manipulator2D(contact.Id, contact.X, contact.Y)); } } } List <Manipulator2D> currentManipulator = new List <Manipulator2D>(); currentManipulator.Add(new Manipulator2D(c.Id, c.X, c.Y)); if (_contactProcessors.ContainsKey(c.Id)) { //_contactProcessors[c.Id].ProcessManipulators(currentManipulator, removedManipulators); _contactProcessors[c.Id].ProcessManipulators(Timestamp, removedManipulators); } }
/// <summary> /// Sends a /tuio/2Dobj message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current acitve Contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DObj(List <TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurfaceDevice.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle objectBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DObj.sourceMessage(); objectBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DObj.aliveMessage(contacts); objectBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; float angularVelocity = 0.0f; float angularAcceleration = 0.0f; if (previousContacts.Contains(c.Id)) { computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration); } float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, InteractiveSurface.PrimarySurfaceDevice.); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); //if (c.Tag.Value) { OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Value, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration); objectBundle.Append(setMessage); } /*else if (c.Tag.Series) * { * OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Series, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration); * objectBundle.Append(setMessage); * }*/ } OSCMessage frameMessage = TUIO_2DObj.frameMessage(_Frame); objectBundle.Append(frameMessage); _Frame++; _OSCSender.Send(objectBundle); }
public void SendData(ReadOnlyTouchPointCollection contacts) { List <string> touches = new List <string>(); Dictionary <int, TouchPoint> frame = new Dictionary <int, TouchPoint>(); foreach (TouchPoint contact in contacts) { bool down, drag, up; if (prevFrame.ContainsKey(contact.Id)) { TouchPoint c = prevFrame[contact.Id]; down = false; up = false; drag = (c.X != contact.X || c.Y != contact.Y); prevFrame.Remove(contact.Id); frame.Add(contact.Id, contact); touches.Add(ToJSON(contact, down, drag, up)); } else { down = true; drag = true; up = false; if (contact.IsFingerRecognized) { frame.Add(contact.Id, contact); touches.Add(ToJSON(contact, down, drag, up)); } } } foreach (TouchPoint contact in prevFrame.Values) { // add touch up contacts touches.Add(ToJSON(contact, false, false, true)); } string json = "{ touches : [ "; bool first = true; foreach (string t in touches) { if (first) { first = false; } else { json += ", "; } json += t; } json += "] }"; BroadcastData(json); this.prevFrame = frame; }
public List<BlobPair> getBlobPairListFromTouchCollection(ReadOnlyTouchPointCollection touches) { List<TouchPoint> blobTouchPointList = new List<TouchPoint>(); List<TouchPoint> bigBlobList = new List<TouchPoint>(); List<TouchPoint> smallBlobList = new List<TouchPoint>(); List<BlobPair> blobPairList = new List<BlobPair>(); //Firstly get every touch point that is a blob and put it in a list. foreach (TouchPoint t in touches) { if (isBlob(t)) { blobTouchPointList.Add(t); } } //Order the touchpoints from largest major axis to smallest. blobTouchPointList = blobTouchPointList.OrderByDescending(x => x.MajorAxis).ToList(); for (int i = 0; i < blobTouchPointList.Count; i++) { if (i >= blobTouchPointList.Count / 2){ smallBlobList.Add(blobTouchPointList.ElementAt(i)); }else{ bigBlobList.Add(blobTouchPointList.ElementAt(i)); } } if (smallBlobList.Count != bigBlobList.Count) { return blobPairList; } List<Tuple<float, TouchPoint, TouchPoint>> vectorDistances = new List<Tuple<float, TouchPoint, TouchPoint>>(); for (int i = 0; i < bigBlobList.Count; i++) { for (int j = 0; j < smallBlobList.Count; j++) { TouchPoint one = bigBlobList.ElementAt(i); TouchPoint two = smallBlobList.ElementAt(j); Vector2 lineBetweenBlobs = new Vector2(one.X - two.X, one.Y - two.Y); vectorDistances.Add(new Tuple<float,TouchPoint,TouchPoint>(lineBetweenBlobs.Length(), one, two)); } } vectorDistances = vectorDistances.OrderBy(x => x.Item1).ToList(); for (int i = 0; i < bigBlobList.Count; i++ ) { Vector2 lineVector = new Vector2(vectorDistances[i].Item2.CenterX - vectorDistances[i].Item3.CenterX, vectorDistances[i].Item2.CenterY - vectorDistances[i].Item3.CenterY); BlobPair tangible = new BlobPair(vectorDistances[i].Item2, vectorDistances[i].Item3, lineVector); if( tangible.Probability > JengaConstants.PROBABILITY_THRESHOLD) blobPairList.Add(tangible); } return blobPairList; }
public static OSCMessage aliveMessage(ReadOnlyTouchPointCollection contacts) { OSCMessage message = new OSCMessage("/tuio/2Dcur"); message.Append("alive"); for (int i = 0; i < contacts.Count; i++) { message.Append(contacts[i].Id); } return message; }
public void SendData(ReadOnlyTouchPointCollection contacts) { List<string> touches = new List<string>(); Dictionary<int, TouchPoint> frame = new Dictionary<int, TouchPoint>(); foreach (TouchPoint contact in contacts) { bool down, drag, up; if (prevFrame.ContainsKey(contact.Id)) { TouchPoint c = prevFrame[contact.Id]; down = false; up = false; drag = (c.X != contact.X || c.Y != contact.Y); prevFrame.Remove(contact.Id); frame.Add(contact.Id, contact); touches.Add(ToJSON(contact, down, drag, up)); } else { down = true; drag = true; up = false; if (contact.IsFingerRecognized) { frame.Add(contact.Id, contact); touches.Add(ToJSON(contact, down, drag, up)); } } } foreach (TouchPoint contact in prevFrame.Values) { // add touch up contacts touches.Add(ToJSON(contact, false, false, true)); } string json = "{ touches : [ "; bool first = true; foreach (string t in touches) { if (first) { first = false; } else { json += ", "; } json += t; } json += "] }"; BroadcastData(json); this.prevFrame = frame; }
public static OSCMessage aliveMessage(ReadOnlyTouchPointCollection contacts) { OSCMessage message = new OSCMessage("/tuio/2Dobj"); message.Append("alive"); for (int i = 0; i < contacts.Count; i++) { message.Append(contacts[i].Id); } return(message); }
private void manageTouches(ReadOnlyTouchPointCollection touches) { foreach (TouchPoint touch in touches) { if (touch.IsTagRecognized) { InputIdentifier inputIdentifier = new InputIdentifier(InputIdentifier.TYPE.tag, -1, (ulong)touch.Tag.Value); OnChanged(inputIdentifier, new Point(touch.CenterX, touch.CenterY), touch.Orientation); } } }
protected override void Update(GameTime gameTime) { if (ApplicationServices.WindowAvailability != WindowAvailability.Unavailable) { // get the current state ReadOnlyTouchPointCollection touches = touchTarget.GetState(); server.SendData(touches); } base.Update(gameTime); }
private void updateCommanders(float dt, bool phase2, int playingPlayer, Dictionary <long, List <int> > allowedZones) { lock (_commanders) { ReadOnlyTouchPointCollection touches = MyGame.TouchTarget.GetState(); foreach (TouchPoint touch in touches) { int zone = _map.getZoneAt(Utils.touchPointToV2(touch)); int zoneOwner = _map.getZoneOwner(zone); foreach (Commander command in _commanders) { if (touch.Tag != null && command.TagValue == touch.Tag.Value && !command.PositionLocked) { //phase 2, we can put commanders in every zone we own if (phase2) { if (zoneOwner == command.Owner) { command.Position = Utils.touchPointToV2(touch); command.CurrentZone = zone; } } else//phase 3 { //the currently playing player can move in every reachable zone if (playingPlayer == command.Owner && (allowedZones[command.TagValue].Contains(zone) || zone == command.CurrentZone)) { command.Position = Utils.touchPointToV2(touch); command.CurrentZone = zone; } //other players can only stay in their current zone else { if (zone == command.CurrentZone) { command.Position = Utils.touchPointToV2(touch); command.CurrentZone = zone; } } } } } } foreach (Commander command in _commanders) { command.update(dt); } } }
public void SendData(ReadOnlyTouchPointCollection contacts) { contactData += "<frame>"; foreach (TouchPoint touch in contacts) { ConvertContactDataToString(touch); } contactData += "</frame>"; BroadcastData(contactData); contactData = ""; }
/// <summary> /// Sends a /tuio/2Dblb message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current active contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DBlb(List <TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle blobBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DBlb.sourceMessage(); blobBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DBlb.aliveMessage(contacts); blobBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; double w = c.MajorAxis / surface.Width; double h = c.MinorAxis / surface.Height; double f = c.PhysicalArea / (surface.Width * surface.Height); float angularVelocity = 0.0f; float angularAcceleration = 0.0f; if (previousContacts.Contains(c.Id)) { computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration); } float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, surface); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); OSCMessage setMessage = TUIO_2DBlb.setMessage(c.Id, (float)x, (float)y, (float)c.Orientation, (float)w, (float)h, (float)(w * h), X, Y, angularVelocity, motionAcceleration, angularAcceleration); blobBundle.Append(setMessage); } OSCMessage frameMessage = TUIO_2DBlb.frameMessage(_Frame); blobBundle.Append(frameMessage); _Frame++; _OSCSender.Send(blobBundle); }
//Wait for all commanders (2 for each player) to be placed on the table, 5 seconds skippable countdown after that private void placeCommanderUpdate(float dt) { if (_currentDialog == null) { //display popup initCommandersInstructionsDialog(); } commonUpdate(dt); if (_currentDialog.IsShown) { updateDialogBox(dt); return; } KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter) && keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space)) { cheatAddCommanders(); } ReadOnlyTouchPointCollection touches = MyGame.TouchTarget.GetState(); foreach (TouchPoint touch in touches) { if (touch.IsTagRecognized && touch.Tag.Value >= _firstTagValue && touch.Tag.Value < _firstTagValue + MyGame.NUMBER_OF_PLAYER * 2) { //if tag is a commander tag, add or update the commander int owner = getOwnerForTag(touch.Tag.Value); //check if the tag is in the right zone int zone = _map.getZoneAt(Utils.touchPointToV2(touch)); if (zone >= 0 && _map.getZoneOwner(zone) == owner) { addCommanderTag(touch, owner); } } } if (areCommandersReady()) { //tell the server this phase is over ServerCom.Instance.sendSimpleMessage("commandersPlaced"); //switch update method _updateAction = emptyUpdate; Console.WriteLine("commanders Placed message sent"); } updateCommanders(dt, true, -1, null); }
public void processTouchPoints(ReadOnlyTouchPointCollection touches, GameTime gameTime) { blobPairs = getBlobPairListFromTouchCollection(touches); _inputProcessor.processTouchPoints(touches, blobPairs, gameTime); /* foreach (BlobPair bp in blobPairs) { Console.WriteLine(bp.thisBlobPairTangible.Name + " : " + bp.Probability); //Console.WriteLine("LARGE BLOB: " + bp.BigBlob.MajorAxis + " : " + bp.BigBlob.MinorAxis + // " SMALL BLOB: " + bp.SmallBlob.MajorAxis + " : " + bp.SmallBlob.MinorAxis // + " DISTANCE: " + bp.DistanceBetweenBlobCentres); }*/ }
//TODO /* * Launch Game button (4 players mandatory) * QR code with node server adress (computer ip) * Handle player connection * */ public void update(float dt) { _radialUI.update(dt); //_restartButton.update(dt); ReadOnlyTouchPointCollection touches = MyGame.TouchTarget.GetState(); /*foreach (TouchPoint touch in touches) * { * if (_restartButton.isTouchOn(Utils.touchPointToV2(touch))) * { * //Change Rooms * * } * }*/ }
/// <summary> /// Creates a new sprite at each touch location. /// </summary> private int InsertSpritesAtTouchPositions(ReadOnlyTouchPointCollection touches) { int count = 0; foreach (TouchPoint touch in touches) { // Create a sprite for each touch that has been recognized as a finger, // or for any touch if finger recognition is not supported. if (touch.IsFingerRecognized || InteractiveSurface.PrimarySurfaceDevice.IsFingerRecognitionSupported == false) { SpriteData sprite = new SpriteData(new Vector2(touch.X, touch.Y), touch.Orientation, 1.0f); sprites.AddLast(sprite); // always add to the end count++; } } return count; }
/// <summary> /// Creates a new sprite at each touch location. /// </summary> private int InsertSpritesAtTouchPositions(ReadOnlyTouchPointCollection touches) { //eventually each sprite has to be different an dhave it's own list? int count = 0; foreach (TouchPoint touch in touches) { // Create a sprite for each touch that has been recognized as a finger, // or for any touch if finger recognition is not supported. if (touch.IsFingerRecognized || InteractiveSurface.PrimarySurfaceDevice.IsFingerRecognitionSupported == false) { SpriteData sprite = new SpriteData(new Vector2(touch.X, touch.Y), touch.Orientation, 1.0f); sprites.AddLast(sprite); // always add to the end count++; } } return(count); }
/// <summary> /// Extract the Manipulation Data and write it into our Dictionary /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnAffine2DDelta(object sender, Manipulation2DDeltaEventArgs e) { ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState(); foreach (TouchPoint c in currentContacts) { if (c.X == e.OriginX && c.Y == e.OriginY) { // BugFix // Apparently this event handling is not thread-safe // Once the surface is reporting a bunch of touches (~30 in testing) // It will try to add a moving touch multiple times to this dictionary. // // I've fixed this by only taking the last touch // and just skip all the inbetween touches. _contactManipulationData[c.Id] = e; } } }
/// <summary> /// Sends a /tuio/2Dcur message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current active contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DCur(List <TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle cursorBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DCur.sourceMessage(); cursorBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DCur.aliveMessage(contacts); cursorBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, surface); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); OSCMessage setMessage = TUIO_2DCur.setMessage(c.Id, (float)x, (float)y, X, Y, motionAcceleration); cursorBundle.Append(setMessage); } OSCMessage frameMessage = TUIO_2DCur.frameMessage(_Frame); cursorBundle.Append(frameMessage); _Frame++; _OSCSender.Send(cursorBundle); }
//TODO /* * Launch Game button (4 players mandatory) * QR code with node server adress (computer ip) * Handle player connection * */ public void update(float dt) { if (_dialog != null && _dialog.IsShown) { _dialog.update(dt); return; } _startButton.update(dt); ReadOnlyTouchPointCollection touches = MyGame.TouchTarget.GetState(); foreach (TouchPoint touch in touches) { if (_startButton.isTouchOn(Utils.touchPointToV2(touch)) && canStartGame()) { //Change Rooms startGameCallback(); } } }
public override void update(float dt) { ReadOnlyTouchPointCollection touches = MyGame.TouchTarget.GetState(); foreach (TouchPoint touch in touches) { processTouch(touch, dt); } if (_touchReleased) { _touchId = -1; _angleOffset = 0f; _angularVelocity -= _angularVelocity * _weigth * dt; _angle += _angularVelocity * dt; } else { _touchReleased = true; } }
/// <summary> /// Process zone pick for player /// Return true when all zone have bee picked for this player /// </summary> /// <param name="player">the player currently picking</param> /// <param name="nbOfZones">the number of zones this player is allowed to pick</param> /// <param name="dt"></param> /// <returns></returns> private bool pickZonesForPlayer(int player, int nbOfZones, float dt) { if (_pickZoneDialog.IsShown) { _pickZoneData.zonePicked[player] = new List <int>(); updateDialogBox(dt); return(false); } else if (_afterButtonTimer < _afterButtonDuration) { _afterButtonTimer += dt; return(false); } ReadOnlyTouchPointCollection touches = MyGame.TouchTarget.GetState(); foreach (TouchPoint touch in touches) { Vector2 touchVec = Utils.touchPointToV2(touch); int touchedZone = _map.getZoneAt(touchVec); if (canPickZone(touchedZone) && _pickZoneData.zonePicked[player].Count < nbOfZones) { //The server wants zone from 0 to 15 _pickZoneData.zonePicked[player].Add(touchedZone - 1); _map.setZoneOwner(touchedZone, player); if (_pickZoneData.zonePicked[player].Count == nbOfZones) { return(true); } } } return(false); }
/// <summary> /// /// </summary> /// <param name="dt">time since last frame in seconds</param> private void updatePlayersUI(float dt) { ReadOnlyTouchPointCollection touches = MyGame.TouchTarget.GetState(); foreach (TouchPoint touch in touches) { checkForUIDrag(touch, dt); if (touch.IsTagRecognized) { if (!MyGame.MapArea.Contains((int)touch.X, (int)touch.Y)) { int owner = getOwnerForTag(touch.Tag.Value); _miniUIs[owner].Position = Utils.touchPointToV2(touch); } } } for (int i = 0; i < _miniUIs.Count; ++i) { SmallPlayerUI ui = _miniUIs[i]; ui.update(dt); } }
/// <summary> ***************************** /// Creates a new sprite List at each touch location. /// </summary> /// <param name="touches">Where the touch is</param> private int InsertEcoliAtTouchPosition(ReadOnlyTouchPointCollection touches) { //eventually each sprite has to be different and have it's own list? int count = 0; foreach (TouchPoint touch in touches) { // Creates a ecoli list for each touch that has been recognized as a finger, // or for any touch if finger recognition is not supported. //needs to create a new list of spirtes with a n ecoli heading it and a tail behind it, with an id? if (touch.IsFingerRecognized || InteractiveSurface.PrimarySurfaceDevice.IsFingerRecognitionSupported == false) { //make a new linkedlist for the ecoli and a trail LinkedList<SpriteData> ecoli = new LinkedList<SpriteData>(); //Add a new functin? Find out what color Ecoli and display the right color sprite and color tail //?? ARE WE SITLL DOING THIS?? If it's the cleaner or the toxic one then Black or white tail? //spriteOrigin = new Vector2(touch.X, touch.Y); SpriteData sprite = new SpriteData(new Vector2(touch.X, touch.Y), touch.Orientation, 1.0f); //would add the color ecoli.AddLast(sprite); // always add to the end //just add? nope. //Finally add LinkedList onto List of LinkedList so that it can be included when drawn ecoliList.Add(ecoli); //Is it helpful to be counting? count++; } } return count; }
/// <summary> /// Main application Logic /// We retrieve the current Contacts and send TUIO messages accordingly /// You can specify via appConfig if you want a Finger Contact to be sent as /tuio/2Dcur or /tuio/2Dblb /// Sending it as /tuio/2Dblb conserves the Contact size, rotation, angular velocity and angular acceleration /// </summary> protected override void Update(GameTime gameTime) { if (isApplicationActivated || isApplicationPreviewed) { _contactManipulationData.Clear(); // Want to identify all the contacts added or removed since the last update. List <TouchPoint> addedContacts = new List <TouchPoint>(); List <TouchPoint> removedContacts = new List <TouchPoint>(); List <TouchPoint> changedContacts = new List <TouchPoint>(); List <TouchPoint> aliveContacts = new List <TouchPoint>(); List <TouchPoint> addedFingers = new List <TouchPoint>(); List <TouchPoint> removedFingers = new List <TouchPoint>(); List <TouchPoint> changedFingers = new List <TouchPoint>(); List <TouchPoint> aliveFingers = new List <TouchPoint>(); List <TouchPoint> addedTags = new List <TouchPoint>(); List <TouchPoint> removedTags = new List <TouchPoint>(); List <TouchPoint> changedTags = new List <TouchPoint>(); List <TouchPoint> aliveTags = new List <TouchPoint>(); List <TouchPoint> addedBlobs = new List <TouchPoint>(); List <TouchPoint> removedBlobs = new List <TouchPoint>(); List <TouchPoint> changedBlobs = new List <TouchPoint>(); List <TouchPoint> aliveBlobs = new List <TouchPoint>(); ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState(); // Write all unactive previous Contacts into the according removed-Lists if (previousContacts != null) { foreach (TouchPoint contact in previousContacts) { //Console.WriteLine("Touch: " + contact.X + ", " + contact.Y); TouchPoint c = null; currentContacts.TryGetTouchPointFromId(contact.Id, out c); if (c == null) { removedContacts.Add(contact); if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { Console.WriteLine("Removing Finger: " + contact.Id); removedFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { removedBlobs.Add(contact); } else if (contact.IsTagRecognized) { removedTags.Add(contact); } else { removedBlobs.Add(contact); } } } // Throw away unused Manipulation Processors cleanManipulationProcessorList(removedContacts); foreach (TouchPoint contact in currentContacts) { aliveContacts.Add(contact); // Put the Contact into the according List if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { aliveFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { aliveBlobs.Add(contact); } else if (contact.IsTagRecognized) { aliveTags.Add(contact); } else { aliveBlobs.Add(contact); } TouchPoint c = null; previousContacts.TryGetTouchPointFromId(contact.Id, out c); if (c != null) { if (c.ToString() != contact.ToString()) { changedContacts.Add(contact); // Invoke the processing of a Contact's Manipulation Processor processContactManipulator(contact, currentContacts, previousContacts); // Put the Contact into the according List if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { changedFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { changedBlobs.Add(contact); } else if (contact.IsTagRecognized) { changedTags.Add(contact); } else { changedBlobs.Add(contact); } } } else { addedContacts.Add(contact); // Add a Manipulation Processor to each contact // This is done for extracting the contact velocity directly from Surface SDK addManipulationProcessor(contact); if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { addedFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { addedBlobs.Add(contact); } else if (contact.IsTagRecognized) { addedTags.Add(contact); } else { addedBlobs.Add(contact); } } } // Send the TUIO messages //////////////////////////// //Console.WriteLine("Sending..."); //sendTUIO_2DCur(changedFingers, previousContacts); //sendTUIO_2DObj(changedTags, previousContacts); //sendTUIO_2DBlb(changedBlobs, previousContacts); ////////////////////////////////////////////////////// if (addedFingers.Count != 0 || changedFingers.Count != 0 || removedFingers.Count != 0) { sendTUIO_2DCur(aliveFingers, previousContacts); } if (addedTags.Count != 0 || changedTags.Count != 0 || removedTags.Count != 0) { sendTUIO_2DObj(aliveTags, previousContacts); } } else { foreach (TouchPoint c in currentContacts) { addedContacts.Add(c); if (c.IsFingerRecognized) { addedFingers.Add(c); } if (c.IsTagRecognized) { addedTags.Add(c); } } } previousContacts = currentContacts; foreach (TouchPoint c in changedContacts) { updateHistoryData(c.Id, c.FrameTimestamp); } foreach (TouchPoint c in removedContacts) { cleanHistory(c.Id); } } base.Update(gameTime); }
/// <summary> /// Update for touches. /// </summary> /// <param name="gameTime"></param> /// <param name="touches"></param> public void Update(GameTime gameTime, ReadOnlyTouchPointCollection touches) { if (TouchesPrevState == null) { TouchesPrevState = touches; } foreach (TouchPoint touch in touches) { var result = from oldtouch in TouchesPrevState where Helper.Geometry.Contains(touch.Bounds, oldtouch.X, oldtouch.Y) && touch.Id == oldtouch.Id select oldtouch; var sameTouch = result.FirstOrDefault(); if (sameTouch != null) { continue; } // Check for settings changed State initial = this.ScreenState; State after = this.ScreenState; foreach (Button b in EnabledButtons) { if (b.OnTouchTapGesture(touch)) // selected >=1 topic { if (b is SettingButton && ((SettingButton)b).Setting.Equals("TOPIC")) after = State.ChooseDifficulty; else if (b is SettingButton && ((SettingButton)b).Setting.Equals("DIFFICULTY")) after = State.ConfirmOptions; } } if (EnabledButtons.Contains(PlayButton)) PlayButton.OnTouchTapGesture(touch); if (after > initial) { // Activate animations foreach (Button b in EnabledButtons) { if (b is SettingButton) { b.IsTranslating = true; } } this.SetState(after); } } TouchesPrevState = touches; foreach (Button b in EnabledButtons) { b.Update(gameTime); } }
public void processTouchPoints(ReadOnlyTouchPointCollection touches, List<BlobPair> blobPairs, GameTime gameTime) { bool corkScrewOnTable = false; bool fineCameraOnTable = false; try { foreach (BlobPair bp in blobPairs) { switch (bp.thisBlobPairTangible.Name) { case ("Jenga Block"): processBlockTangible(bp); break; case ("Cork Screw"): processCorkScrewTangible(bp); corkScrewOnTable = true; break; case ("Fine Camera"): processFineCamera(bp); fineCameraOnTable = true; break; } } } catch (NullReferenceException e) { } if (!corkScrewOnTable) this.lastCorkScrewOrientation = -1; if (!fineCameraOnTable) this.lastFineCameraInformation = null; //========================================================================== foreach (TouchPoint t in touches) { if (t.IsTagRecognized) { switch (t.Tag.Value) { case JengaConstants.STACK_SIDE_0: _viewManager.rotateToSide(0,t); break; case JengaConstants.STACK_SIDE_1: _viewManager.rotateToSide(1, t); break; case JengaConstants.STACK_SIDE_2: _viewManager.rotateToSide(2, t); break; case JengaConstants.STACK_SIDE_3: _viewManager.rotateToSide(3, t); break; case JengaConstants.STACK_SIDE_4: _viewManager.rotateToSide(4, t); break; } } } //========================================================================== //Get center positions of all finger touchpoints float x = 0, y = 0; int count = 0; int firstID = -1; foreach (TouchPoint activeTouchPoint in touches) { if (activeTouchPoint.IsFingerRecognized){ x += activeTouchPoint.X; y += activeTouchPoint.Y; firstID = activeTouchPoint.Id; count++; } } x = x / count; y = y / count; Tuple<SolidThing, Quaternion, float, Vector3> middleBlock = null; if (count > 0) middleBlock = getTouchedBlock(x, y); //Rotation or zoom block if (selectedBrick != null && middleBlock != null && selectedBrick.Item1.Equals(middleBlock.Item1) && activeTouchPoints.Count > 1) { //holdingTouchPointID = -1; List<Manipulator2D> manipulatorList = new List<Manipulator2D>(); foreach (TouchPoint t in touches) { if (t.IsFingerRecognized) manipulatorList.Add(new Manipulator2D(t.Id, t.X, t.Y)); } Manipulator2D[] manipulators = null; manipulators = manipulatorList.ToArray(); try { rotateOrZoom = true; manipulationProcessor.Pivot.X = selectedBrick.Item1.Position.X; manipulationProcessor.Pivot.Y = selectedBrick.Item1.Position.Y; manipulationProcessor.ProcessManipulators(Timestamp, manipulators); //TODO FIXED COLLECTION MODIFIED } catch (NullReferenceException e) { } catch (InvalidOperationException e) { } } //Otherwise if we arent moving the block, move camera else if (holdingTouchPointID == -1) { rotateOrZoom = false; if (activeTouchPoints.Count > 0 && count > 0) { Manipulator2D[] manipulators = null; manipulators = new Manipulator2D[]{new Manipulator2D(firstID, x, y)}; try { manipulationProcessor.ProcessManipulators(Timestamp, manipulators); } catch (NullReferenceException e) { } catch (InvalidOperationException e) { } } } }
public void processTouchPoints(ReadOnlyTouchPointCollection touches) { lastTouchPosition = touchPosition; int tagID = -1; if (touches.Count >= 1) { for (int i = 0; i < touches.Count; i++) { if (touches[i].IsTagRecognized) { tagID = (int)touches[i].Tag.Value; break; } } if (tagID != -1) { touchPosition = touches[0]; //First time touch if (lastTouchPosition == null) { Segment s; s.P1 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.CenterX, touchPosition.CenterY, 0f), viewManager.Projection, viewManager.View, Matrix.Identity); s.P2 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.CenterX, touchPosition.CenterY, 1f), viewManager.Projection, viewManager.View, Matrix.Identity); float scalar; Vector3 point; var c = physics.BroadPhase.Intersect(ref s, out scalar, out point); if (c != null && c is BodySkin) { pickedObject = ((BodySkin)c).Owner; pickedForce = new WorldPointConstraint(pickedObject, point); physics.Add(pickedForce); pickedDistance = scalar; pickedObject.IsActive = true; } lastOrientation = touches.Count == 1 ? touches[0].Orientation : touches[1].Orientation; } else if (pickedObject != null) { Segment s; s.P1 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.CenterX, touchPosition.CenterY, 0f), viewManager.Projection, viewManager.View, Matrix.Identity); s.P2 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.CenterX, touchPosition.CenterY, 1f), viewManager.Projection, viewManager.View, Matrix.Identity); Vector3 diff, point; Vector3.Subtract(ref s.P2, ref s.P1, out diff); Vector3.Multiply(ref diff, pickedDistance, out diff); Vector3.Add(ref s.P1, ref diff, out point); pickedForce.WorldPoint = point; pickedObject.IsActive = true; //SolidThing po = (SolidThing)pickedObject; //Console.Out.WriteLine("UNFREEEEEEEEEEEEZE"); switch (tagID) { //Pin a block case 0: pickedObject.Freeze(); break; //unPin a block case 1: pickedObject.Unfreeze(); break; //Rotate a block case 2: pickedForce.orientation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1.0f), touchPosition.Orientation); break; //Move a block towards or away from camera case 3: TouchPoint tagPoint = touches[0]; float deltaRotation = MathHelper.ToDegrees(lastOrientation) - MathHelper.ToDegrees(tagPoint.Orientation); Vector3 direction = new Vector3(0, 0, 1.0f); direction.Normalize(); pickedForce.WorldPoint = Vector3.Add(pickedForce.WorldPoint, Vector3.Multiply(direction, deltaRotation * 0.01f)); break; //Rotate stack onto top view /*case 4: viewManager.rotateToSide(4, touch); break; //Corkscrew closer or further away case 5: viewManager.rotateToSide(5); break; case 6: viewManager.rotateToSide(6); break; case 7: viewManager.rotateToSide(7); break; case 8: viewManager.rotateToSide(8); break; */ } } else if (pickedObject != null) { physics.Remove(pickedForce); pickedObject = null; } } } else if (pickedObject != null) { physics.Remove(pickedForce); pickedObject = null; touchPosition = null; lastTouchPosition = null; } else { touchPosition = null; } }
/// <summary> /// Sends a /tuio/2Dobj message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current acitve Contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DObj(List<TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurfaceDevice.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle objectBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DObj.sourceMessage(); objectBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DObj.aliveMessage(contacts); objectBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; float angularVelocity = 0.0f; float angularAcceleration = 0.0f; if( previousContacts.Contains( c.Id )) { computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration); } float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, InteractiveSurface.PrimarySurfaceDevice.); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); //if (c.Tag.Value) { OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Value, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration); objectBundle.Append(setMessage); } /*else if (c.Tag.Series) { OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Series, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration); objectBundle.Append(setMessage); }*/ } OSCMessage frameMessage = TUIO_2DObj.frameMessage(_Frame); objectBundle.Append(frameMessage); _Frame++; _OSCSender.Send(objectBundle); }
public void Frame() { if (openCOVER != null) { // Want to identify all the contacts added or removed since the last update. List <TouchPoint> addedContacts = new List <TouchPoint>(); List <TouchPoint> removedContacts = new List <TouchPoint>(); List <TouchPoint> changedContacts = new List <TouchPoint>(); // Get a list of the current contacts ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState(); // Compare the contacts in the current list to the list saved from the last update if (previousContacts != null) { foreach (TouchPoint contact in previousContacts) { TouchPoint c = null; currentContacts.TryGetTouchPointFromId(contact.Id, out c); if (c == null) { removedContacts.Add(contact); //if(contact.IsFingerRecognized) //removedManipulators.Add(new Manipulator(contact.Id, contact.CenterX, contact.CenterY)); } } foreach (TouchPoint contact in currentContacts) { TouchPoint c = null; previousContacts.TryGetTouchPointFromId(contact.Id, out c); if (c != null) { changedContacts.Add(contact); //if (contact.IsFingerRecognized) //currentManipulators.Add(new Manipulator(contact.Id, contact.CenterX, contact.CenterY)); } else { addedContacts.Add(contact); //if (contact.IsFingerRecognized) //currentManipulators.Add(new Manipulator(contact.Id, contact.CenterX, contact.CenterY)); } } } else { foreach (TouchPoint c in currentContacts) { addedContacts.Add(c); //if (c.IsFingerRecognized) //currentManipulators.Add(new Manipulator(c.Id, c.CenterX, c.CenterY)); } } //manipulationProcessor.ProcessManipulators(currentManipulators, removedManipulators); //currentManipulators.Clear(); //removedManipulators.Clear(); previousContacts = currentContacts; // Hit test and assign all new contacts foreach (TouchPoint c in addedContacts) { openCOVER.addedContact(c); } // Update the captors of all the pre-existing contacts foreach (TouchPoint c in changedContacts) { openCOVER.changedContact(c); } // Clean up all old contacts foreach (TouchPoint co in removedContacts) { openCOVER.removedContact(co); } openCOVER.frame(); } }
private void getcords(ReadOnlyTouchPointCollection touches) { // for each touch points, get the links near that point. // Add them into the hash table with element as key, coordinate as value. foreach (TouchPoint touch in touches){ if (((double)touch.CenterX != prev_x) && ((double)touch.CenterY != prev_y)) { prev_x = (double)touch.CenterX; prev_y = (double)touch.CenterY; Console.WriteLine(prev_x + "," + prev_y); Point coord = new Point((double)touch.CenterX - 209, (double)touch.CenterY - 128); coord_pack_Q.Enqueue(coord); if (coord_pack_Q.Count() == 50) // track only 50 points for the history. { Console.WriteLine("cluster limit reached"); coord_pack_Q.Dequeue(); // pull the oldest element } if (touch.IsFingerRecognized) //clicked? { Console.WriteLine("Finger detected"); sendCoord(touch); webBrowser1.Navigating -= webBrowser1_Navigating; if (dom_cord.Count > 0) { found = true; } proceed_estimation(); } } } }
/// <summary> /// Reads the latest state of the keyboard and gamepad and mouse/touchpad. /// </summary> public void Update(GameTime gameTime) { _lastKeyboardState = _currentKeyboardState; _lastGamePadState = _currentGamePadState; _lastMouseState = _currentMouseState; if (_handleVirtualStick) { _lastVirtualState = _currentVirtualState; } _currentKeyboardState = Keyboard.GetState(); #if !WINDOWS_PHONE _currentGamePadState = GamePad.GetState(PlayerIndex.One); #endif _currentMouseState = Mouse.GetState(); if (_handleVirtualStick) { #if XBOX _currentVirtualState= GamePad.GetState(PlayerIndex.One); #elif WINDOWS if (GamePad.GetState(PlayerIndex.One).IsConnected) { _currentVirtualState = GamePad.GetState(PlayerIndex.One); } else { _currentVirtualState = HandleVirtualStickWin(); } #elif WINDOWS_PHONE _currentVirtualState = HandleVirtualStickWP7(); #endif } #if WINDOWS if (TouchTarget != null) { //Surface touches touches = TouchTarget.GetState(); if (touches.Count > 0) { _currentMouseState = new MouseState((int)touches[0].X, (int)touches[0].Y, 0, ButtonState.Pressed, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); } } #endif _touchState = TouchPanel.GetState(); if (_touchState.Count > 0) { TouchLocation location = _touchState[0]; _currentMouseState = new MouseState((int)location.Position.X, (int)location.Position.Y, 0, ButtonState.Pressed, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); } _gestures.Clear(); while (TouchPanel.IsGestureAvailable) { _gestures.Add(TouchPanel.ReadGesture()); } // Update cursor Vector2 oldCursor = _cursor; if (_currentGamePadState.IsConnected && _currentGamePadState.ThumbSticks.Left != Vector2.Zero) { Vector2 temp = _currentGamePadState.ThumbSticks.Left; _cursor += temp * new Vector2(300f, -300f) * (float)gameTime.ElapsedGameTime.TotalSeconds; //Mouse.SetPosition((int)_cursor.X, (int)_cursor.Y); } else { _cursor.X = _currentMouseState.X; _cursor.Y = _currentMouseState.Y; } _cursor.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width); _cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height); if (_cursorIsValid && oldCursor != _cursor) { _cursorMoved = true; } else { _cursorMoved = false; } #if WINDOWS if (_viewport.Bounds.Contains(_currentMouseState.X, _currentMouseState.Y)) { _cursorIsValid = true; } else { _cursorIsValid = false; } #elif WINDOWS_PHONE //if (_currentMouseState.LeftButton == ButtonState.Pressed) //{ // _cursorIsValid = true; //} //else //{ // _cursorIsValid = false; //} #endif }
/// <summary> /// Touch Update Method called at 30fps /// </summary> /// <param name="gameTime"></param> /// <param name="touches"></param> public void Update(GameTime gameTime, ReadOnlyTouchPointCollection touches) { if (TouchesPrevState == null) { TouchesPrevState = touches; } foreach (TouchPoint touch in touches) { for (int playerIndex = 0; playerIndex < PLAYER_COUNT; playerIndex++) { foreach (BingoTile bt in PlayerTiles[playerIndex]) { bt.OnTouchReveal(touch); } } var result = from oldtouch in TouchesPrevState where Helper.Geometry.Contains(touch.Bounds, oldtouch.X, oldtouch.Y) && touch.Id == oldtouch.Id select oldtouch; var sameTouch = result.FirstOrDefault(); if (sameTouch != null) { continue; } //Check for tile touched for (int playerIndex = 0; playerIndex < PLAYER_COUNT; playerIndex++) { int tileNum = 0; foreach (BingoTile bt in PlayerTiles[playerIndex]) { bt.OnTouchTapGesture(touch); PlayerData[playerIndex].tileAnswered(bt.Answered, tileNum); tileNum++; } } //Check for question touched if (Question.OnTouchTapGesture(touch)) { int questionID = Question.getID(); this.QuestionChanged = true; //Notify tiles of new question ID for (int playerIndex = 0; playerIndex < PLAYER_COUNT; playerIndex++) { foreach (BingoTile bt in PlayerTiles[playerIndex]) { // Get possible answer images DataTable dt = DBhelper.queryDBRows("select ImageID from Answers where QuestionID = " + questionID.ToString()); List<int> list = new List<int>(); for (int i = 0; i < dt.Rows.Count; i++) { list.Add(Int32.Parse(dt.Rows[i].ItemArray[0].ToString())); } bt.UpdateQuestion(list); } } } } TouchesPrevState = touches; QuestionChanged = false; for (int playerIndex = 0; playerIndex < PLAYER_COUNT; playerIndex++) { foreach (BingoTile bt in PlayerTiles[playerIndex]) { bt.Update(gameTime); } } if (Question != null) Question.Update(gameTime); }
/// <summary> /// Sends a /tuio/2Dblb message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current active contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DBlb(List<TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle blobBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DBlb.sourceMessage(); blobBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DBlb.aliveMessage(contacts); blobBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; double w = c.MajorAxis / surface.Width; double h = c.MinorAxis / surface.Height; double f = c.PhysicalArea / (surface.Width * surface.Height); float angularVelocity = 0.0f; float angularAcceleration = 0.0f; if (previousContacts.Contains(c.Id)) { computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration); } float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, surface); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); OSCMessage setMessage = TUIO_2DBlb.setMessage(c.Id, (float)x, (float)y, (float)c.Orientation, (float)w, (float)h, (float)(w * h), X, Y, angularVelocity, motionAcceleration, angularAcceleration); blobBundle.Append(setMessage); } OSCMessage frameMessage = TUIO_2DBlb.frameMessage(_Frame); blobBundle.Append(frameMessage); _Frame++; _OSCSender.Send(blobBundle); }
/// <summary> /// Reads the latest state of the keyboard and gamepad and mouse/touchpad. /// </summary> public void Update(GameTime gameTime) { _lastKeyboardState = _currentKeyboardState; _lastGamePadState = _currentGamePadState; _lastMouseState = _currentMouseState; if (_handleVirtualStick) { _lastVirtualState = _currentVirtualState; } _currentKeyboardState = Keyboard.GetState(); #if !WINDOWS_PHONE _currentGamePadState = GamePad.GetState(PlayerIndex.One); #endif _currentMouseState = Mouse.GetState(); if (_handleVirtualStick) { #if XBOX _currentVirtualState = GamePad.GetState(PlayerIndex.One); #elif WINDOWS if (GamePad.GetState(PlayerIndex.One).IsConnected) { _currentVirtualState = GamePad.GetState(PlayerIndex.One); } else { _currentVirtualState = HandleVirtualStickWin(); } #elif WINDOWS_PHONE _currentVirtualState = HandleVirtualStickWP7(); #endif } #if WINDOWS if (TouchTarget != null) { //Surface touches touches = TouchTarget.GetState(); if (touches.Count > 0) { _currentMouseState = new MouseState((int)touches[0].X, (int)touches[0].Y, 0, ButtonState.Pressed, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); } } #endif _touchState = TouchPanel.GetState(); if (_touchState.Count > 0) { TouchLocation location = _touchState[0]; _currentMouseState = new MouseState((int)location.Position.X, (int)location.Position.Y, 0, ButtonState.Pressed, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); } _gestures.Clear(); while (TouchPanel.IsGestureAvailable) { _gestures.Add(TouchPanel.ReadGesture()); } // Update cursor Vector2 oldCursor = _cursor; if (_currentGamePadState.IsConnected && _currentGamePadState.ThumbSticks.Left != Vector2.Zero) { Vector2 temp = _currentGamePadState.ThumbSticks.Left; _cursor += temp * new Vector2(300f, -300f) * (float)gameTime.ElapsedGameTime.TotalSeconds; //Mouse.SetPosition((int)_cursor.X, (int)_cursor.Y); } else { _cursor.X = _currentMouseState.X; _cursor.Y = _currentMouseState.Y; } _cursor.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width); _cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height); if (_cursorIsValid && oldCursor != _cursor) { _cursorMoved = true; } else { _cursorMoved = false; } #if WINDOWS if (_viewport.Bounds.Contains(_currentMouseState.X, _currentMouseState.Y)) { _cursorIsValid = true; } else { _cursorIsValid = false; } #elif WINDOWS_PHONE //if (_currentMouseState.LeftButton == ButtonState.Pressed) //{ // _cursorIsValid = true; //} //else //{ // _cursorIsValid = false; //} #endif }
public void processTouchPoints(ReadOnlyTouchPointCollection touches, List<BlobPair> blobPairs, GameTime gameTime) { lastTouchPosition = touchPosition; int tagID = -1; int tagValue = -1; Boolean manipulatorControl = false; if (touches.Count == 2 && touches[0].IsFingerRecognized && touches[1].IsFingerRecognized) { manipulatorControl = true; Manipulator2D[] manipulators; manipulators = new Manipulator2D[] { new Manipulator2D(1, touches[1].X, touches[1].Y), new Manipulator2D(3, touches[0].X, touches[0].Y) }; manipulationProcessor.Pivot.X = touches[0].X; manipulationProcessor.Pivot.Y = touches[0].Y; manipulationProcessor.ProcessManipulators(Timestamp, manipulators); } else { manipulationProcessor.CompleteManipulation(Timestamp); } if (touches.Count >= 1) { for (int i = 0; i < touches.Count; i++) { if (touches[i].IsTagRecognized) { tagID = touches[i].Id; tagValue = (int)touches[i].Tag.Value; break; } } /*switch (tagValue) { case 4: viewManager.rotateToSide(4,t); break; case 5: viewManager.rotateToSide(5,t); break; case 6: viewManager.rotateToSide(6,t); break; case 7: viewManager.rotateToSide(7,t); break; case 8: viewManager.rotateToSide(8,t); break; } */ touchPosition = touches[0]; //First time touch if (lastTouchPosition == null) { Segment s; s.P1 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 0f), viewManager.Projection, viewManager.View, Matrix.Identity); s.P2 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 1f), viewManager.Projection, viewManager.View, Matrix.Identity); float scalar; Vector3 point; var c = physics.BroadPhase.Intersect(ref s, out scalar, out point); if (c != null && c is BodySkin && !(((SolidThing)((BodySkin)c).Owner).getThingType() == 1) && !(((SolidThing)((BodySkin)c).Owner).getThingType() == 2)) { pickedObject = ((BodySkin)c).Owner; orientation = pickedObject.Orientation; pickedDistance = scalar; pickedObject.IsActive = true; pickedObjectOffset = pickedObject.Position - point; pickedObject.IsWeightless = true; } //lastOrientation = touches.Count == 1 ? touches[0].Orientation : touches[1].Orientation; lastOrientation = touches[0].Orientation; } else if (pickedObject != null) { Segment s; s.P1 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 0f), viewManager.Projection, viewManager.View, Matrix.Identity); s.P2 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 1f), viewManager.Projection, viewManager.View, Matrix.Identity); Vector3 diff, point; Vector3.Subtract(ref s.P2, ref s.P1, out diff); Vector3.Multiply(ref diff, pickedDistance, out diff); Vector3.Add(ref s.P1, ref diff, out point); pickedObject.SetVelocity(Vector3.Zero, Vector3.Zero); if (!manipulatorControl) { Vector3 position = Vector3.Add(point, pickedObjectOffset); pickedObject.SetWorld(position, orientation); } pickedObject.IsActive = true; SolidThing pickedObjectST = (SolidThing)pickedObject; switch (tagValue) { //Pin a block case 0: pickedObject.Unfreeze(); pickedObject.Freeze(); break; //unPin a block case 1: if (pickedObjectST.getThingType() == 1) { break; } else { pickedObject.Unfreeze(); break; } //Rotate a block case 2: pickedObject.SetWorld(pickedObject.Position, Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1.0f), touchPosition.Orientation)); break; //Move a block towards or away from camera case 3: TouchPoint tagPoint = touches.GetTouchPointFromId(tagID); float deltaRotation = MathHelper.ToDegrees(lastOrientation) - MathHelper.ToDegrees(tagPoint.Orientation); Vector3 direction = new Vector3(0, 0, 1.0f); direction.Normalize(); pickedObject.SetWorld(Vector3.Add(pickedObject.Position, Vector3.Multiply(direction, deltaRotation * 0.03f))); lastOrientation = tagPoint.Orientation; break; } } else if (pickedObject != null) { pickedObject.IsWeightless = false; pickedObject = null; } } else if (pickedObject != null) { pickedObject.IsWeightless = false; pickedObject = null; touchPosition = null; lastTouchPosition = null; } else { touchPosition = null; } }
public void processContactManipulator(TouchPoint c, ReadOnlyTouchPointCollection currentContacts, ReadOnlyTouchPointCollection previousContacts) { List<Manipulator2D> removedManipulators = new List<Manipulator2D>(); if (previousContacts != null) { // Find all the contacts that were removed since the last check. foreach (TouchPoint contact in previousContacts) { // Create a temporary variable for the following method call. TouchPoint tempContact; // Determine if the Contact object from the previous list is in the current list. if (!currentContacts.TryGetTouchPointFromId(contact.Id, out tempContact)) { // The contact was not found in the list of current contacts, so it has been removed. // Copy the Contact object information to a new Manipulator object and add // the Manipulator object to the removedManipulators list. removedManipulators.Add(new Manipulator2D(contact.Id, contact.X, contact.Y)); } } } List<Manipulator2D> currentManipulator = new List<Manipulator2D>(); currentManipulator.Add(new Manipulator2D(c.Id, c.X, c.Y)); if (_contactProcessors.ContainsKey(c.Id)) { //_contactProcessors[c.Id].ProcessManipulators(currentManipulator, removedManipulators); _contactProcessors[c.Id].ProcessManipulators(Timestamp, removedManipulators); } }
/// <summary>Not used anymore /// Creates a new sprite at each touch location. /// </summary> private int InsertSpritesAtTouchPositions(ReadOnlyTouchPointCollection touches) { //eventually each sprite has to be different and have it's own list? int count = 0; foreach (TouchPoint touch in touches) { // Create a sprite for each touch that has been recognized as a finger, // or for any touch if finger recognition is not supported. //needs to create a new list of spirtes with a n ecoli heading it and a tail behind it, with an id? if (touch.IsFingerRecognized || InteractiveSurface.PrimarySurfaceDevice.IsFingerRecognitionSupported == false) { //spriteOrigin = new Vector2(touch.X, touch.Y); SpriteData sprite = new SpriteData(new Vector2(touch.X, touch.Y), touch.Orientation, 1.0f); sprites.AddLast(sprite); // always add to the end count++; } } return count; }
/// <summary> /// Sends a /tuio/2Dcur message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current active contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DCur(List<TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle cursorBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DCur.sourceMessage(); cursorBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DCur.aliveMessage(contacts); cursorBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, surface); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); OSCMessage setMessage = TUIO_2DCur.setMessage(c.Id, (float)x, (float)y, X, Y, motionAcceleration); cursorBundle.Append(setMessage); } OSCMessage frameMessage = TUIO_2DCur.frameMessage(_Frame); cursorBundle.Append(frameMessage); _Frame++; _OSCSender.Send(cursorBundle); }
public void Frame() { if (openCOVER != null) { // Want to identify all the contacts added or removed since the last update. List<TouchPoint> addedContacts = new List<TouchPoint>(); List<TouchPoint> removedContacts = new List<TouchPoint>(); List<TouchPoint> changedContacts = new List<TouchPoint>(); // Get a list of the current contacts ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState(); // Compare the contacts in the current list to the list saved from the last update if (previousContacts != null) { foreach (TouchPoint contact in previousContacts) { TouchPoint c = null; currentContacts.TryGetTouchPointFromId(contact.Id, out c); if (c == null) { removedContacts.Add(contact); //if(contact.IsFingerRecognized) //removedManipulators.Add(new Manipulator(contact.Id, contact.CenterX, contact.CenterY)); } } foreach (TouchPoint contact in currentContacts) { TouchPoint c = null; previousContacts.TryGetTouchPointFromId(contact.Id, out c); if (c != null) { changedContacts.Add(contact); //if (contact.IsFingerRecognized) //currentManipulators.Add(new Manipulator(contact.Id, contact.CenterX, contact.CenterY)); } else { addedContacts.Add(contact); //if (contact.IsFingerRecognized) //currentManipulators.Add(new Manipulator(contact.Id, contact.CenterX, contact.CenterY)); } } } else { foreach (TouchPoint c in currentContacts) { addedContacts.Add(c); //if (c.IsFingerRecognized) //currentManipulators.Add(new Manipulator(c.Id, c.CenterX, c.CenterY)); } } //manipulationProcessor.ProcessManipulators(currentManipulators, removedManipulators); //currentManipulators.Clear(); //removedManipulators.Clear(); previousContacts = currentContacts; // Hit test and assign all new contacts foreach (TouchPoint c in addedContacts) { openCOVER.addedContact(c); } // Update the captors of all the pre-existing contacts foreach (TouchPoint c in changedContacts) { openCOVER.changedContact(c); } // Clean up all old contacts foreach (TouchPoint co in removedContacts) { openCOVER.removedContact(co); } openCOVER.frame(); } }
/// <summary> /// Main application Logic /// We retrieve the current Contacts and send TUIO messages accordingly /// You can specify via appConfig if you want a Finger Contact to be sent as /tuio/2Dcur or /tuio/2Dblb /// Sending it as /tuio/2Dblb conserves the Contact size, rotation, angular velocity and angular acceleration /// </summary> protected override void Update(GameTime gameTime) { if (isApplicationActivated || isApplicationPreviewed) { _contactManipulationData.Clear(); // Want to identify all the contacts added or removed since the last update. List<TouchPoint> addedContacts = new List<TouchPoint>(); List<TouchPoint> removedContacts = new List<TouchPoint>(); List<TouchPoint> changedContacts = new List<TouchPoint>(); List<TouchPoint> aliveContacts = new List<TouchPoint>(); List<TouchPoint> addedFingers = new List<TouchPoint>(); List<TouchPoint> removedFingers = new List<TouchPoint>(); List<TouchPoint> changedFingers = new List<TouchPoint>(); List<TouchPoint> aliveFingers = new List<TouchPoint>(); List<TouchPoint> addedTags = new List<TouchPoint>(); List<TouchPoint> removedTags = new List<TouchPoint>(); List<TouchPoint> changedTags = new List<TouchPoint>(); List<TouchPoint> aliveTags = new List<TouchPoint>(); List<TouchPoint> addedBlobs = new List<TouchPoint>(); List<TouchPoint> removedBlobs = new List<TouchPoint>(); List<TouchPoint> changedBlobs= new List<TouchPoint>(); List<TouchPoint> aliveBlobs = new List<TouchPoint>(); ReadOnlyTouchPointCollection currentContacts = contactTarget.GetState(); // Write all unactive previous Contacts into the according removed-Lists if (previousContacts != null) { foreach (TouchPoint contact in previousContacts) { //Console.WriteLine("Touch: " + contact.X + ", " + contact.Y); TouchPoint c = null; currentContacts.TryGetTouchPointFromId(contact.Id, out c); if (c == null) { removedContacts.Add(contact); if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { removedFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { removedBlobs.Add(contact); } else if (contact.IsTagRecognized) { removedTags.Add(contact); } else { removedBlobs.Add(contact); } } } // Throw away unused Manipulation Processors cleanManipulationProcessorList(removedContacts); foreach (TouchPoint contact in currentContacts) { aliveContacts.Add(contact); // Put the Contact into the according List if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { aliveFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { aliveBlobs.Add(contact); } else if (contact.IsTagRecognized) { aliveTags.Add(contact); } else { aliveBlobs.Add(contact); } TouchPoint c = null; previousContacts.TryGetTouchPointFromId(contact.Id, out c); if (c != null) { if (c.ToString() != contact.ToString()) { changedContacts.Add(contact); // Invoke the processing of a Contact's Manipulation Processor processContactManipulator(contact, currentContacts, previousContacts); // Put the Contact into the according List if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { changedFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { changedBlobs.Add(contact); } else if (contact.IsTagRecognized) { changedTags.Add(contact); } else { changedBlobs.Add(contact); } } } else { addedContacts.Add(contact); // Add a Manipulation Processor to each contact // This is done for extracting the contact velocity directly from Surface SDK addManipulationProcessor(contact); if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == false || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { addedFingers.Add(contact); } if (contact.IsFingerRecognized && (Properties.Settings.Default.SendFingersAsBlobs == true || Properties.Settings.Default.SendFingersAlsoAsBlobs == true)) { addedBlobs.Add(contact); } else if (contact.IsTagRecognized) { addedTags.Add(contact); } else { addedBlobs.Add(contact); } } } // Send the TUIO messages //////////////////////////// //Console.WriteLine("Sending..."); //sendTUIO_2DCur(changedFingers, previousContacts); //sendTUIO_2DObj(changedTags, previousContacts); //sendTUIO_2DBlb(changedBlobs, previousContacts); ////////////////////////////////////////////////////// if (addedFingers.Count != 0 || changedFingers.Count != 0 || removedFingers.Count != 0) { sendTUIO_2DCur(aliveFingers, previousContacts); } if (addedTags.Count != 0 || changedTags.Count != 0 || removedTags.Count != 0) { sendTUIO_2DObj(aliveTags, previousContacts); } } else { foreach (TouchPoint c in currentContacts) { addedContacts.Add(c); if (c.IsFingerRecognized) { addedFingers.Add(c); } if (c.IsTagRecognized) { addedTags.Add(c); } } } previousContacts = currentContacts; foreach (TouchPoint c in changedContacts) { updateHistoryData(c.Id, c.FrameTimestamp); } foreach (TouchPoint c in removedContacts) { cleanHistory(c.Id); } } base.Update(gameTime); }
private int process_touches(ReadOnlyTouchPointCollection touches) { int count = 0; foreach (TouchPoint touch in touches) { if (touch.IsFingerRecognized || InteractiveSurface.PrimarySurfaceDevice.IsFingerRecognitionSupported == false) { float x = touch.X / size_x; float y = touch.Y / size_y; //touch.X, touch.Y),touch.Orientation if (tuio_ids.Contains(touch.Id)) { tuioserver.UpdateTuioCursor(touch.Id, new System.Drawing.PointF(x, y)); } else { tuioserver.AddTuioCursor(touch.Id, new System.Drawing.PointF(x, y)); tuio_ids.Add(touch.Id); } } tuioserver.InitFrame(); tuioserver.CommitFrame(); } return count; }