// Update is called once per frame void Update() { Core.ProcessFrame(); pEvents = Core.ConsumePointEvents(); //string output; /* foreach (PointEvent pEvent in pEvents) { if (pEvent.Status == TouchStatus.TOUCHADDED){ output = "TOUCHADDED-----------------------------\r\n"; output += "Point ID: " + pEvent.PointId.ToString(); output += "\r\n X: " + pEvent.Position.X.ToString(); output += "\r\n Y: " + pEvent.Position.Y.ToString(); output += "\r\n W: " + pEvent.Position.W.ToString(); output += "\r\n H: " + pEvent.Position.H.ToString(); output += "\r\n Z: " + pEvent.Position.Z.ToString(); output += "\r\n Touch Status: " + pEvent.Status.ToString(); output += "\r\n Timestamp: \r\n" + pEvent.Timestamp.ToString(); Debug.Log(output); } } */ if(pEvents!=null){ foreach(PointEvent pEvent in pEvents){ if(pEvent.Status == TouchStatus.TOUCHADDED){ if(!TouchPoints.ContainsKey(pEvent.PointId)){ TouchPoints.Add(pEvent.PointId, new TouchCircle(pEvent.PointId, pEvent.Position.X, pEvent.Position.Y)); } } if(pEvent.Status == TouchStatus.TOUCHREMOVED){ if(TouchPoints.ContainsKey(pEvent.PointId)){ TouchPoints[pEvent.PointId].RemoveRing(); TouchPoints.Remove(pEvent.PointId); } } if(pEvent.Status == TouchStatus.TOUCHUPDATE){ if(TouchPoints.ContainsKey(pEvent.PointId)){ TouchPoints[pEvent.PointId].Update(pEvent.Position.X, pEvent.Position.Y); } } } } }
// Update is called once per frame void Update() { Core.ProcessFrame(); pEvents = Core.ConsumePointEvents(); if (Input.GetKey ("escape")) { Application.Quit(); } //string output; /* foreach (PointEvent pEvent in pEvents) { if (pEvent.Status == TouchStatus.TOUCHADDED){ output = "TOUCHADDED-----------------------------\r\n"; output += "Point ID: " + pEvent.PointId.ToString(); output += "\r\n X: " + pEvent.Position.X.ToString(); output += "\r\n Y: " + pEvent.Position.Y.ToString(); output += "\r\n W: " + pEvent.Position.W.ToString(); output += "\r\n H: " + pEvent.Position.H.ToString(); output += "\r\n Z: " + pEvent.Position.Z.ToString(); output += "\r\n Touch Status: " + pEvent.Status.ToString(); output += "\r\n Timestamp: \r\n" + pEvent.Timestamp.ToString(); Debug.Log(output); } } */ if(pEvents!=null){ foreach(PointEvent pEvent in pEvents){ if(pEvent.Status == TouchStatus.TOUCHADDED){ if(!TouchPoints.ContainsKey(pEvent.PointId)){ TouchPoints.Add(pEvent.PointId, new TouchCircle(pEvent.PointId, pEvent.Position.X, pEvent.Position.Y)); } bool touchPointHitSomething = false; foreach(TouchObject obj in GestureObjects){ if(HitManager.DetectHit(pEvent.Position.X, Camera.main.GetScreenHeight()-pEvent.Position.Y, obj.gameObject)){ Core.AddTouchPoint(obj.GetObjectName(), pEvent.PointId); touchPointHitSomething = true; //Debug.Log("I hit "+obj.GetObjectName()+" pEvent.PointId"+pEvent.PointId); } } if(touchPointHitSomething==false){ Core.AddTouchPoint(Camera.main.name, pEvent.PointId); } } if(pEvent.Status == TouchStatus.TOUCHREMOVED){ if(TouchPoints.ContainsKey(pEvent.PointId)){ TouchPoints[pEvent.PointId].RemoveRing(); TouchPoints.Remove(pEvent.PointId); } } if(pEvent.Status == TouchStatus.TOUCHUPDATE){ if(TouchPoints.ContainsKey(pEvent.PointId)){ TouchPoints[pEvent.PointId].Update(pEvent.Position.X, pEvent.Position.Y); } } } } gEvents = Core.ConsumeGestureEvents(); string activeGestures = ""; string activeGestureTargets = ""; string o; if(gEvents!=null){ foreach (GestureEvent gEvent in gEvents){ #region Test Console Output o = "-----------------------------\r\n"; o += gEvent.ToString(); o += "EventID: " + gEvent.EventID; o += "\r\n GestureID: " + gEvent.GestureID; o += "\r\n Target: " + gEvent.Target; o += "\r\n N: " + gEvent.N.ToString(); o += "\r\n X: " + gEvent.X.ToString(); o += "\r\n Y: " + gEvent.Y.ToString(); o += "\r\n Timestamp: " + gEvent.Timestamp.ToString(); o += "\r\n Locked Points: " + gEvent.LockedPoints.GetLength(0).ToString(); o += "\r\n"; //Debug.Log(o); #endregion //activeGestures += gEvent.GestureID + ", "; // for debugging //activeGestureTargets += gEvent.Target + ", "; // for debugging // send gesture events to all subscribers foreach(TouchObject obj in GestureObjects){ //send events only to corresponding registered touch objects //Debug.Log(gEvent.GestureID+" gesture and for "+gEvent.Target); if(obj.name==gEvent.Target){ //Debug.Log(gEvent.GestureID+" gesture found for "+gEvent.Target); obj.SendMessage(gEvent.GestureID, gEvent); } } } } else { //Debug.Log("gEvents null"); } }
/// <summary> /// Obtains all currently tracked touch point events from <c>GestureWorksCore</c>, represented by a collection of <see cref="PointEvent"/> objects. /// </summary> /// <returns>A <see cref="PointEventArray"/> containing any point events as held by GestureWorks.</returns> public PointEventArray ConsumePointEvents() { PointEventArray points = new PointEventArray(); IntPtr eventArrayPtr = GwNative.consumePointEvents(); PointEventArrayIntermediate eventArray = (PointEventArrayIntermediate)Marshal.PtrToStructure(eventArrayPtr, typeof(PointEventArrayIntermediate)); Marshal.DestroyStructure(eventArrayPtr, typeof(PointEventArrayIntermediate)); IntPtr eventPtr = eventArray.Events; for (int i = 0; i < eventArray.Size; i++) { points.Add((PointEvent)Marshal.PtrToStructure((IntPtr)eventPtr, typeof(PointEvent))); Marshal.DestroyStructure(eventPtr, typeof(PointEvent)); eventPtr = new IntPtr(eventPtr.ToInt64() + Marshal.SizeOf(typeof(PointEvent))); } return points; }