public void Evaluate(int SpreadMax) { if (!bEnable[0]) { return; } // Get the current state of our contacts. // Nice, this seems to be a threadsafe read. ReadOnlyContactCollection contacts = contactTarget.GetState(); IDout.SliceCount = contactSize.SliceCount = contactRotation.SliceCount = contactCoord.SliceCount = contacts.Count; int i = 0; foreach (Contact c in contacts) { IDout[i] = c.Id; Vector2D pos = new Vector2D(c.X, c.Y); pos.x = (bNormalizeValues[0]) ? pos.x / 512 - 1 : pos.x; pos.y = (bNormalizeValues[0]) ? (2 - pos.y / 384) - 1 : pos.y; double rotation = 1 - c.Orientation / (2 * Math.PI); contactSize[i] = new Vector2D(c.Bounds.Width / 1024.0, c.Bounds.Height / 768.0); contactCoord[i] = pos; contactRotation[i] = rotation; i++; } }
/// <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 (isApplicationActivated || isApplicationPreviewed) { if (isApplicationActivated) { ProcessContacts(gameTime, contactTarget.GetState()); } DoUpdate(gameTime, isApplicationActivated); } base.Update(gameTime); }
/// <summary> /// Initializes the surface input system. This should be called after any window /// initialization is done, and should only be called once. /// </summary> public override void Initialize() { surfaceComp = Game.Components.OfType<SurfaceComponent>().First(); System.Diagnostics.Debug.Assert(Game.Window.Handle != System.IntPtr.Zero, "Window initialization must be complete before InitializeSurfaceInput is called"); if (Game.Window.Handle == System.IntPtr.Zero) return; System.Diagnostics.Debug.Assert(contactTarget == null, "Surface input already initialized"); if (contactTarget != null) return; // Create a target for surface input. contactTarget = new ContactTarget(Game.Window.Handle, EventThreadChoice.OnBackgroundThread); contactTarget.EnableInput(); contactTarget.EnableImage(ImageType.Normalized); contactTarget.FrameReceived += new EventHandler<FrameReceivedEventArgs>(contactTarget_FrameReceived); CurrentContacts = contactTarget.GetState(); manipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY | Affine2DManipulations.Rotate | Affine2DManipulations.Scale); manipulationProcessor.Affine2DManipulationDelta += new EventHandler<Affine2DOperationDeltaEventArgs>(manipulationDelta); manipulationProcessor.Affine2DManipulationStarted += (s, e) => IsManipulating = true; manipulationProcessor.Affine2DManipulationCompleted += (s, e) => IsManipulating = false; base.Initialize(); }
public void Frame() { if (openCOVER != null) { // Want to identify all the contacts added or removed since the last update. List <Contact> addedContacts = new List <Contact>(); List <Contact> removedContacts = new List <Contact>(); List <Contact> changedContacts = new List <Contact>(); // Get a list of the current contacts ReadOnlyContactCollection currentContacts = contactTarget.GetState(); // Compare the contacts in the current list to the list saved from the last update if (previousContacts != null) { foreach (Contact contact in previousContacts) { Contact c = null; currentContacts.TryGetContactFromId(contact.Id, out c); if (c == null) { removedContacts.Add(contact); if (contact.IsFingerRecognized) { removedManipulators.Add(new Manipulator(contact.Id, contact.CenterX, contact.CenterY)); } } } foreach (Contact contact in currentContacts) { Contact c = null; previousContacts.TryGetContactFromId(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 (Contact 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 (Contact c in addedContacts) { openCOVER.addedContact(c); } // Update the captors of all the pre-existing contacts foreach (Contact c in changedContacts) { openCOVER.changedContact(c); } // Clean up all old contacts foreach (Contact co in removedContacts) { openCOVER.removedContact(co); } openCOVER.frame(); } }