/// <summary> /// Initializes a new instance of the <see cref="MyNode"/> class. /// </summary> /// <param name="rand">The rand.</param> /// <param name="circleTex">The circle tex.</param> /// <param name="screenSize">Size of the screen.</param> /// <param name="gardener">The gardener.</param> public MyNode(Random rand, Texture2D circleTex, Point screenSize, Gardener gardener) : base(rand, circleTex, screenSize) { this.NodeSizeMax = 70; this.gardener = gardener; var accentColor = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"]; this.color = GetXnaColour(accentColor); // set the controllable node to take touch events Touch.FrameReported += this.TouchFrameReported; this.DisableVirtualMovement = true; var pingTag = new PingTag { AccentColour = accentColor }; this.Tag = pingTag.Serialize(); }
/// <summary> /// Configures the gardener. /// </summary> private void ConfigureGardener() { this.gardener = new Gardener(); var comm = CommType.Udp; if (this.WebComms.IsChecked ?? false) { comm = CommType.Web; } // Define the way the gardener should behave var settings = new GardenerSettings { CommType = comm, // Not specifying the other options for camera related detection // If wanting to add them a videobrush must be added to the page also // - See the Silverlight project for an example EnableColorDetection = false, EnableImageDetection = false, EnableShakeDetection = this.EnableShakeDetection.IsChecked ?? false, EnableNoiseDetection = this.EnableNoiseDetection.IsChecked ?? false, NoiseThreshold = 1500, NoiseDuration = 2, }; this.gardener.Initialize(settings); this.AddHandlersForDetectedEvents(); // Handle notification, from another device, that a node has been added/changed this.gardener.OnNodeChanged += nodeId => this.Dispatcher.BeginInvoke( () => { var gardenerNode = this.gardener.Nodes.FirstOrDefault(n => n.Id == nodeId); var visualNode = this.nodes.FirstOrDefault(n => n.Id == nodeId); if (gardenerNode != null) { if (visualNode == null) { var on = new ShadowNode( rand, this.circleTex, new Microsoft.Xna.Framework.Point( GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)); on.X = gardenerNode.X; on.Y = gardenerNode.Y; on.Tag = gardenerNode.Tag; on.Id = gardenerNode.Id; on.DisableVirtualMovement = true; this.nodes.Add(on); } else { var idx = this.nodes.IndexOf(visualNode); this.nodes[idx].X = gardenerNode.X; this.nodes[idx].Y = gardenerNode.Y; this.nodes[idx].Tag = gardenerNode.Tag; } } else { if (visualNode != null) { this.nodes.Remove(visualNode); } } }); }
/// <summary> /// Configures the gardener. /// </summary> private void ConfigureGardener() { this.gardener = new Gardener(); var comm = CommType.Udp; if (this.WebComms.IsChecked ?? false) { comm = CommType.Web; } // Define the way the gardener should behave var settings = new GardenerSettings { CommType = comm, // Not specifying the other options for camera related detection // If wanting to add them a videobrush must be added to the page also // - See the Silverlight project for an example EnableColorDetection = false, EnableImageDetection = false, EnableShakeDetection = this.EnableShakeDetection.IsChecked ?? false, EnableNoiseDetection = this.EnableNoiseDetection.IsChecked ?? false, NoiseThreshold = 1500, NoiseDuration = 2, }; this.gardener.Initialize(settings); this.AddHandlersForDetectedEvents(); // Handle notification, from another device, that a node has been added/changed this.gardener.OnNodeChanged += nodeId => this.Dispatcher.BeginInvoke(new Action( () => { var gardenerNode = this.gardener.Nodes.FirstOrDefault(n => n.Id == nodeId); var nativeId = this.GetNodeIdInt(nodeId); if (gardenerNode != null) { if (nativeId < 0) { nativeId = m_d3dInterop.CreateNode((float)gardenerNode.X, (float)gardenerNode.Y); this.MapNodeIds(gardenerNode.Id, nativeId); } else { m_d3dInterop.UpdateNodePosition(nativeId, (float)gardenerNode.X, (float)gardenerNode.Y); } } else { if (nativeId >= 0) { m_d3dInterop.RemoveNode(nativeId); this.NativeManagedNodeIdMap.Remove(nodeId); } } })); }
/// <summary> /// The start button was clicked. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void StartClicked(object sender, RoutedEventArgs e) { this.gardener = new Gardener(); var comm = CommType.Udp; if (this.WebComms.IsChecked ?? false) { comm = CommType.Web; } // Define the way the gardener should behave var settings = new GardenerSettings { CommType = comm, EnableColorDetection = this.EnableColorDetection.IsChecked ?? false, EnableImageDetection = this.EnableImageDetection.IsChecked ?? false, EnableShakeDetection = this.EnableShakeDetection.IsChecked ?? false, EnableNoiseDetection = this.EnableNoiseDetection.IsChecked ?? false, NoiseThreshold = 1500, NoiseDuration = 2, ColorToDetect = Colors.Blue, ColorDetectionThreshold = 40, // These two properties must be set like this for the camera to be // able to be used to do color and image detection ViewFinderBrush = this.viewfinderBrush, ViewFinderBrushTransform = this.viewfinderBrushTransformation, }; this.gardener.Initialize(settings); this.AddHandlersForDetectedEvents(); // Handle notification, from another device, that a node has been added/changed this.gardener.OnNodeChanged += nodeId => this.Dispatcher.BeginInvoke(() => { var gardenerNode = this.gardener.Nodes.FirstOrDefault(n => n.Id == nodeId); var visualNode = this.nodes.FirstOrDefault(n => n.Id == nodeId); if (gardenerNode != null) { if (visualNode == null) { var vn = new VisualNode(rand, MainCanvas) { X = gardenerNode.X, Y = gardenerNode.Y, Tag = gardenerNode.Tag, Id = gardenerNode.Id, DisableVirtualMovement = true }; this.nodes.Add(vn); } else { var idx = this.nodes.IndexOf(visualNode); this.nodes[idx].X = gardenerNode.X; this.nodes[idx].Y = gardenerNode.Y; this.nodes[idx].Tag = gardenerNode.Tag; } } else { if (visualNode != null) { visualNode.Remove(this.MainCanvas); this.nodes.Remove(visualNode); } } }); this.ConfigureOtherOptions(); this.nodes = new List<VisualNode>(); this.CreateOwnNode(); this.gardener.WhereIsEveryBody(); this.CreateDefaultNodes(Convert.ToInt32(Math.Floor(this.AdditionalNodesCount.Value))); this.CreateLines(); this.nodeMovementTimer.Interval = TimeSpan.FromMilliseconds(10); this.nodeMovementTimer.Tick += this.UpdateDisplay; this.nodeMovementTimer.Start(); }
/// <summary> /// Initializes and configures the gardener. /// </summary> private void InitializeAndConfigureGardener() { this.gardener = new Gardener(); var comm = CommType.Udp; if (this.WebComms.IsChecked ?? false) { comm = CommType.Web; } var settings = new GardenerSettings { CommType = comm, EnableColorDetection = false, EnableImageDetection = false, EnableShakeDetection = this.EnableShakeDetection.IsChecked ?? false, EnableNoiseDetection = this.EnableNoiseDetection.IsChecked ?? false, NoiseThreshold = 1500, NoiseDuration = 2, }; this.gardener.Initialize(settings); this.gardener.OnNodeChanged += nodeId => this.Dispatcher.BeginInvoke(() => { var node = this.gardener.Nodes.FirstOrDefault(n => n.Id == nodeId); if (node != null) { this.TellJsAboutNode(node); } }); this.gardener.OnNoiseDetected += () => Dispatcher.BeginInvoke(() => this.embeddedBrowser.InvokeScript("NoiseDetected")); this.gardener.OnShakeDetected += () => Dispatcher.BeginInvoke(() => this.embeddedBrowser.InvokeScript("ShakeDetected")); var x = this.rand.Next(50, 430); var y = this.rand.Next(50, 750); this.gardener.AddSelfNode(x, y); this.gardener.WhereIsEveryBody(); this.TellJsAboutAccentColor(); this.TellJsAboutNode(this.gardener.Nodes.FirstOrDefault(n => n.NodeType == TypeOfNode.Self)); }