internal SkinEventArgs(Point rawLocation, Point transformedLocation, double distanceToArmCenter, double hoverDistance, SkinEventType eventType) : base(TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds) { m_point = new SkinTouchPoint(rawLocation, transformedLocation, distanceToArmCenter, hoverDistance, eventType); }
internal SkinTouchPoint(Point rawLocation, Point transformedLocation, double distanceToArmCenter, double hoverDistance, SkinEventType eventType) { m_rawLocation = rawLocation; m_transformedLocation = transformedLocation; m_eventType = eventType; m_distanceToArmCenter = distanceToArmCenter; m_hoverDistance = hoverDistance; }
private void InvokeSkinEvents(SkinEventType skinEventType) { SharedList <SkinEventListener> list = ((NaiveLockingList <SkinEventListener>)DotNetNukeContext.Current.SkinEventListeners).SharedList; using (list.GetReadLock()) { foreach (var listener in list.Where(x => x.EventType == skinEventType)) { listener.SkinEvent.Invoke(this, new SkinEventArgs(this)); } } }
internal void OnRawData(Tuple <Point3D, Quaternion> armData, Tuple <Point3D, Quaternion> wristData, Tuple <Point3D, Quaternion> fingerData, Point location, double distanceToArmCenter, double hoverDistance, SkinEventType skinEventType, RawDataEventType rawEventType) { RawDataEventArgs e = new RawDataEventArgs( armData.Item1, armData.Item2, wristData.Item1, wristData.Item2, fingerData.Item1, fingerData.Item2, location, distanceToArmCenter, hoverDistance, skinEventType, rawEventType); RawData?.Invoke(this, e); }
private SkinEventType SetTouchInactive(double distanceToCenter, double hoverDistance) { SkinEventType eventType = SkinEventType.None; if (m_touching) { // there was a touch before -> fire touch up m_arm.OnSkinTouchUp(m_prevTouchLocation, distanceToCenter, hoverDistance); eventType = SkinEventType.Up; } m_touching = false; return(eventType); }
private SkinEventType SetTouchActive(double distanceToCenter, double hoverDistance) { SkinEventType eventType = SkinEventType.None; if (!(m_touching)) { // there was no touch before -> fire touch down m_arm.OnSkinTouchDown(m_prevTouchLocation, distanceToCenter, hoverDistance); eventType = SkinEventType.Down; } else { m_arm.OnSkinTouchMove(m_prevTouchLocation, distanceToCenter, hoverDistance); eventType = SkinEventType.Move; } m_touching = true; return(eventType); }
internal RawDataEventArgs(Point3D armPosition, Quaternion armOrientation, Point3D wristPosition, Quaternion wristOrientation, Point3D fingerPosition, Quaternion fingerOrientation, Point location, double distanceToArmCenter, double hoverDistance, SkinEventType skinEventType, RawDataEventType rawEventType) : base(TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds) { m_armPosition = armPosition; m_armOrientation = armOrientation; m_wristPosition = wristPosition; m_wristOrientation = wristOrientation; m_fingerPosition = fingerPosition; m_fingerOrientation = fingerOrientation; m_location = location; m_skinEventType = skinEventType; m_rawEventType = rawEventType; m_distanceToArmCenter = distanceToArmCenter; m_hoverDistance = hoverDistance; }
internal void DetectTouch() { Point?projectedTouchPoint = null; // gather data (for RAW event) Tuple <Point3D, Quaternion> armData = new Tuple <Point3D, Quaternion>( m_arm.ForearmPosition, m_arm.ForearmOrientation); Tuple <Point3D, Quaternion> wristData = new Tuple <Point3D, Quaternion>( m_arm.WristPosition, m_arm.WristOrientation); Tuple <Point3D, Quaternion> fingerData = new Tuple <Point3D, Quaternion>( m_finger.FingertipPosition, m_finger.FingertipOrientation); // set initial values RawDataEventType rawEventType = RawDataEventType.Outside; SkinEventType skinEventType = SkinEventType.None; Point touchLocation = new Point(-1.0, -1.0); double distanceToCenter = double.MaxValue; double distanceToArmSurface = double.MaxValue; // do the detection Point3D forearmCenter = m_arm.ForearmCenter; Point3D wristCenter = m_arm.WristCenter; Point3D fingertipPosition = m_finger.FingertipPosition; // get closest point Vector3D u = wristCenter - forearmCenter; Vector3D pq = fingertipPosition - forearmCenter; Vector3D w2 = pq - Vector3D.Multiply(u, Vector3D.DotProduct(pq, u) / u.LengthSquared); Point3D closestPoint = fingertipPosition - w2; // test, if closestPoint is between forearmCenter and wristCenter Vector3D centerVect = wristCenter - forearmCenter; double armLength = centerVect.Length; Vector3D closestToForearm = closestPoint - forearmCenter; double lengthToForearm = closestToForearm.Length; Vector3D closestToWrist = closestPoint - wristCenter; double lengthToWrist = closestToWrist.Length; // distance between center of arm to tracked point distanceToCenter = (closestPoint - fingertipPosition).Length; bool withinArm = true; if (lengthToForearm / armLength > 1.0 || lengthToWrist / armLength > 1.0 || distanceToCenter > m_arm.Radius * 3.0) { rawEventType = RawDataEventType.Outside; m_arm.OnSkinInactive(new Point(-1.0, -1.0), double.MaxValue, double.MaxValue); withinArm = false; } if (Constants.DebugPrint) { // sample Debug.WriteLine(closestPoint + " [d = " + distanceToCenter + " | WITHIN: " + withinArm + "]"); } // if we're within the arm, we should calculate the closest ellipse if (withinArm) { rawEventType = RawDataEventType.WithinArm; double radius = m_arm.Radius; // first, get the x-coordinate (normalized between 0 and 1) double normalizedX = lengthToForearm / armLength; // now, create generic ellipse data (major and minor axis) double minorAxis = normalizedX * m_arm.WristHeight / 2.0 + (1.0 - normalizedX) * radius; double majorAxis = normalizedX * m_arm.WristWidth / 2.0 + (1.0 - normalizedX) * radius; // transform finger position locally Point3D center = forearmCenter + normalizedX * (wristCenter - forearmCenter); // Quaternion adjustedForearm = new Quaternion(m_arm.ForearmOrientation.Axis, m_arm.ForearmOrientation.Angle - 90.0); Quaternion adjustedForearm = m_arm.ForearmOrientation * (new Quaternion(new Vector3D(0.0, 0.0, 1.0), -90.0)); Quaternion orientation = Quaternion.Slerp(adjustedForearm, m_arm.WristOrientation, normalizedX); Transform3DGroup localTransformGroup = new Transform3DGroup(); localTransformGroup.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation))); localTransformGroup.Children.Add(new TranslateTransform3D(center.X, center.Y, center.Z)); Matrix3D localTransform = localTransformGroup.Value; Matrix3D localTransformInv = localTransform; localTransformInv.Invert(); Point3D localFingerPosition = localTransformInv.Transform(m_finger.FingertipPosition); double angle = Math.Atan2(localFingerPosition.Y, localFingerPosition.X); Point3D pointOnArm = new Point3D(majorAxis * Math.Cos(angle), minorAxis * Math.Sin(angle), localFingerPosition.Z); // distance between tracked finger and arm surface distanceToArmSurface = (localFingerPosition - pointOnArm).Length; // distance between center of arm and surface point double distanceFromCenterToSurface = (pointOnArm - new Point3D(0.0, 0.0, 0.0)).Length; distanceToArmSurface = distanceToCenter - distanceFromCenterToSurface; bool insideArm = (distanceFromCenterToSurface > distanceToCenter); if (Constants.DebugPrint) { Debug.WriteLine(distanceFromCenterToSurface + " :: " + distanceToCenter); } if (distanceToArmSurface >= Constants.Touch.MinimumTouchDistance && !(insideArm)) { if (Constants.DebugPrint) { Debug.WriteLine("NO TOUCH: d = " + distanceToArmSurface); } skinEventType = SetTouchInactive(distanceToCenter, distanceToArmSurface); if (distanceToArmSurface <= Constants.Touch.MaximumHoverDistance) { Point hoverLocation = GetProjectedLocationOnArmSurface(angle, minorAxis, majorAxis, normalizedX); m_arm.OnSkinHover(hoverLocation, distanceToCenter, distanceToArmSurface); rawEventType = RawDataEventType.Hover; skinEventType = SkinEventType.Hover; touchLocation = hoverLocation; projectedTouchPoint = touchLocation; } else { Point hoverLocation = GetProjectedLocationOnArmSurface(angle, minorAxis, majorAxis, normalizedX); m_arm.OnSkinInactive(hoverLocation, distanceToCenter, distanceToArmSurface); } } else { if (Constants.DebugPrint) { Debug.WriteLine(localFingerPosition + " [d = " + (localFingerPosition - new Point3D(0.0, 0.0, 0.0)).Length + ", angle = " + (angle / Math.PI * 180.0) + "]"); Debug.WriteLine(pointOnArm + " [d = " + distanceToArmSurface + "]"); } m_prevTouchLocation = GetProjectedLocationOnArmSurface(angle, minorAxis, majorAxis, normalizedX); skinEventType = SetTouchActive(distanceToCenter, distanceToArmSurface); touchLocation = m_prevTouchLocation; rawEventType = RawDataEventType.Touch; projectedTouchPoint = touchLocation; } } else { skinEventType = SetTouchInactive(-1.0, -1.0); projectedTouchPoint = null; } // update finger m_finger.State = rawEventType; m_arm.SetProjectedTouchPoint(projectedTouchPoint, rawEventType); // fire RAW event m_arm.OnRawData(armData, wristData, fingerData, touchLocation, distanceToCenter, distanceToArmSurface, skinEventType, rawEventType); }
public SkinEventListener(SkinEventType type, SkinEventHandler e) { _Type = type; _skinEvent = e; }
/// <summary> /// Initializes a new instance of the <see cref="SkinEventListener"/> class. /// </summary> /// <param name="type"></param> /// <param name="e"></param> public SkinEventListener(SkinEventType type, SkinEventHandler e) { this.EventType = type; this.SkinEvent = e; }
private void InvokeSkinEvents(SkinEventType skinEventType) { SharedList<SkinEventListener> list = ((NaiveLockingList<SkinEventListener>)DotNetNukeContext.Current.SkinEventListeners).SharedList; using (list.GetReadLock()) { foreach (var listener in list.Where(x => x.EventType == skinEventType)) { listener.SkinEvent.Invoke(this, new SkinEventArgs(this)); } } }
public SkinEventListener(SkinEventType type, SkinEventHandler e) { EventType = type; SkinEvent = e; }