/// <summary> /// Creates a new instance of <see cref="TangibleObjectControl"/> for a given <see cref="TangibleObject"/>. /// </summary> /// <param name="tangibleObject">The tangible object.</param> /// <param name="tangibleCanvas">The tangible canvas that hosts the tangible object.</param> internal TangibleObjectController(TangibleObject tangibleObject, TangibleCanvas tangibleCanvas) { Check.NotNull(tangibleObject, "tangibleObject"); Check.NotNull(tangibleCanvas, "tangibleCanvas"); _tangibleObject = tangibleObject; _tangibleCanvas = tangibleCanvas; //InitializeTopLine(); InitializePhysicBoundaries(); //InitializeTangibleObjectData(); }
/// <summary> /// Creates a new instance of <see cref="TangibleObjectManager"/>. /// </summary> /// <param name="container">The tangible canvas.</param> public TangibleObjectManager(TangibleCanvas container) { Check.NotNull(container, "container"); _container = container; // Initialize fields _detectedObjects = new List<TangibleObject>(); _detectedTouchPoints = new TouchPointCollection(TouchHelper.MaxTouchPoints); // Debugging //_detectedTouchPoints.AddPoint(new TouchPoint()); // Initialize detection logic SubscribeEvents(_container); }
/// <summary> /// Expose a static method to show the contacts in DEBUG mode only. /// Should not be called explicitly. /// </summary> /// <param name="tangibleCanvas">The <see cref="TangibleCanvas"/>.</param> /// <param name="size">The location and the size of the rectangle where the contacts should be shown.</param> /// <param name="contacts">The contacts.</param> /// <param name="physicSprites">A collection with physic sprites.</param> internal static void ShowContacts(TangibleCanvas tangibleCanvas, Rect size, IEnumerable<ContactViewModel> contacts, List<PhysicsSprite> physicSprites) { //List<ContactControl> _contactControls = new List<ContactControl>(); int count = contacts.Count(); if (count == 0) return; double angle = 0; //Degrees converted to Radian. double incrementalAngularSpace = MathHelper.DegreesToRadians(360.0 / contacts.Count()); //An approximate radii based on the available size , obviously a better approach is needed here. double radiusX = size.Width / 2.4; double radiusY = size.Height / 2.4; foreach (var contact in contacts) { //Calculate the point on the circle for the element Point childPoint = new Point(Math.Cos(angle) * radiusX, -Math.Sin(angle) * radiusY); //Offsetting the point to the available rectangular area which is FinalSize. Point actualChildPoint = new Point(size.X + size.Width / 2 + childPoint.X - ContactControl.DefaultWidth / 2, size.Y + size.Height / 2 + childPoint.Y - ContactControl.DefaultHeight / 2); //Call Arrange method on the child element by giving the calculated point as the placementPoint. //elem.Arrange(new Rect(actualChildPoint.X, actualChildPoint.Y, elem.DesiredSize.Width, elem.DesiredSize.Height)); var contactControl = new ContactControl(contact); if (physicSprites == null) tangibleCanvas.AddPhysicsUserControl(contactControl, actualChildPoint.X, actualChildPoint.Y, 0); else // Add the ContactControl to the root canvas and cache the physic sprites. physicSprites.AddRange( tangibleCanvas.AddPhysicsUserControl(contactControl, actualChildPoint.X, actualChildPoint.Y, 0)); //_contactControls.Add(contactControl); //contactControl.PhysicObject.Mass = -1; //Calculate the new _angle for the next element angle += incrementalAngularSpace; } //return _contactControls; }
private Microsoft.Xna.Framework.Vector2 CalculateContactCardPosition(Microsoft.Xna.Framework.Vector2 pointerPosition, TangibleCanvas tangibleCanvas) { Microsoft.Xna.Framework.Vector2 position = new Microsoft.Xna.Framework.Vector2(pointerPosition.X, pointerPosition.Y); if (pointerPosition.X > tangibleCanvas.ActualWidth - ContactCard.ActualWidth - Canvas.GetLeft(ContactCard)) // Don't group the terms in () position.X = (float)(tangibleCanvas.ActualWidth - ContactCard.ActualWidth - Canvas.GetLeft(ContactCard)); if (pointerPosition.Y > tangibleCanvas.ActualHeight - ContactCard.ActualHeight + Canvas.GetTop(ContactCard)) // Negativ offset in Y-direction. position.Y = (float)(tangibleCanvas.ActualHeight - ContactCard.ActualHeight + Canvas.GetTop(ContactCard)); else if (pointerPosition.Y + Canvas.GetTop(ContactCard) < 0) position.Y = -(float)Canvas.GetTop(ContactCard); // Compensate the offset; return position; }
/// <summary> /// Subscribe events of tangible canvas. /// </summary> /// <param name="uiElement">The tangible canvas.</param> void SubscribeEvents(TangibleCanvas uiElement) { Check.NotNull(uiElement, "uiElement"); //TODO Use reactive programming to aggregate the event streams. //uiElement.PointerEntered += OnPointerEntered; //uiElement.PointerExited += OnPointerExited; uiElement.PointerMoved += OnPointerMoved; uiElement.PointerPressed += OnPointerPressed; uiElement.PointerReleased += OnPointerReleased; uiElement.PointerExited += OnPointerExited; }