public override void Fire() { Init(); //be sure to leave this here to enable use of the na variable double[] rotation = { -Math.PI / 2, -Math.PI / 24, 0, Math.PI / 24, Math.PI / 2 }; float direction = 0; for (int i = 0; i < na.Width; i++) { if (na.GetNeuronAt(i, 0).LastCharge > 0.9 || na.GetNeuronAt(i, 0).LastCharge > 0.9 && i < rotation.Length) { direction = (float)rotation[i]; } } if (na.GetNeuronAt(2, 0).CurrentCharge != 0) { direction = na.GetNeuronAt(2, 0).CurrentCharge; na.GetNeuronAt(2, 0).SetValue(0); } ModuleRealityModel mrm = (ModuleRealityModel)FindModuleByType(typeof(ModuleRealityModel)); if (mrm != null && direction != 0) { mrm.Rotate(20); } Module2DSim m2D = (Module2DSim)FindModuleByType(typeof(Module2DSim)); if (m2D != null && direction != 0) { m2D.Rotate(direction); } Module3DSim m3D = (Module3DSim)FindModuleByType(typeof(Module3DSim)); if (m3D != null && direction != 0) { m3D.Rotate(direction); } Module2DModel m2DModel = (Module2DModel)FindModuleByType(typeof(Module2DModel)); if (m2DModel != null && direction != 0) { m2DModel.Rotate(direction); } Module2DVision m2DVision = (Module2DVision)FindModuleByType(typeof(Module2DVision)); if (m2DVision != null && direction != 0) { m2DVision.ViewChanged(); } }
private void TheCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { Module2DSim parent = (Module2DSim)base.ParentModule; Point windowSize = new Point(theCanvas.ActualWidth, theCanvas.ActualHeight); Point windowCenter = new Point(windowSize.X / 2, windowSize.Y / 2); float scale = (float)Math.Min(windowSize.X, windowSize.Y) / 12; Point position = e.GetPosition(theCanvas); PointPlus v = new PointPlus { P = (Point)(position - parent.entityPosition) }; float dist = (float)v.R; double angle = (float)v.Theta; double deltaAngle = angle - parent.entityDirection1; ModuleView naGoToDest = MainWindow.theNeuronArray.FindAreaByLabel("ModuleGoToDest"); if (naGoToDest != null) { naGoToDest.GetNeuronAt("Go").SetValue(1); naGoToDest.GetNeuronAt("Theta").SetValue((float)deltaAngle); naGoToDest.GetNeuronAt("R").SetValue(dist); } else { ModuleView naBehavior = MainWindow.theNeuronArray.FindAreaByLabel("ModuleBehavior"); if (naBehavior != null) { naBehavior.GetNeuronAt("TurnTo").SetValue(1); naBehavior.GetNeuronAt("Theta").SetValue((float)-deltaAngle); naBehavior.GetNeuronAt("MoveTo").SetValue(1); naBehavior.GetNeuronAt("R").SetValue(dist); } } }
public override void Fire() { Init(); //be sure to leave this here if (GetNeuronValue("Auto") == 0) { return; } goToGoal = GetNeuronValue("Goal") == 1; ModuleBehavior mBehavior = (ModuleBehavior)FindModleu(typeof(ModuleBehavior)); if (mBehavior == null) { return; } Module2DModel mModel = (Module2DModel)FindModleu(typeof(Module2DModel)); if (mModel is null) { return; } ModuleEvent mEvent = (ModuleEvent)FindModleu(typeof(ModuleEvent)); if (mEvent == null) { return; } ModuleUKSN UKS = (ModuleUKSN)FindModleu(typeof(ModuleUKSN)); if (UKS == null) { return; } if (GetNeuronValue("ModuleBehavior", "Done") == 0) { return; } mModel.GetSegmentsFromUKS(); IList <Thing> segments = mModel.GetUKSSegments(); if (segments.Count == 0) { return; } Thing t = segments[0]; //TODO: this only works with just a single item in the UKS //figure out if any motion occured Segment s = Module2DModel.SegmentFromUKSThing(t); Module2DModel.OrderSegment(s); if (GetNeuronValue("E0") == 1) { GoToLandmark(UKS.Labeled("E0").References[0].T, s); doPush = 2; doBackOff = true; return; } if (GetNeuronValue("E1") == 1) { GoToLandmark(UKS.Labeled("E1").References[0].T, s); doPush = 2; doBackOff = true; return; } if (GetNeuronValue("E2") == 1) { GoToLandmark(UKS.Labeled("E2").References[0].T, s); doPush = 2; doBackOff = true; return; } if (doPush != 0) { if (doPush == 2) { Push(s); } doPush--; return; } if (doFaceSegment) { DoFaceSegment(s); doFaceSegment = false; return; } Segment s1; if (lastPosition == null) //create objects to keep track of the target and last position { s1 = s.Clone(); lastPosition = mModel.AddSegmentToUKS(s1); lastPosition.Label = "LastPosition"; lastPosition.RemoveParent(UKS.Labeled("Segment")); lastPosition.AddParent(UKS.Labeled("SSegment")); Module2DSim mSim = (Module2DSim)FindModleu(typeof(Module2DSim)); if (mSim is null) { return; } Segment motionTarget = mSim.GetMotionTarget(); if (motionTarget == null) { motionTarget = new Segment(); motionTarget.P1 = new PointPlus(4, 1.5f); motionTarget.P2 = new PointPlus(4, -2.5f); motionTarget.theColor = (ColorInt)0xff; } endTarget = mModel.AddSegmentToUKS(motionTarget); endTarget.Label = "EndTarget"; //endTarget.RemoveParent(UKS.Labeled("Segment")); //endTarget.AddParent(UKS.Labeled("SSegment")); } else { s1 = Module2DModel.SegmentFromUKSThing(lastPosition); } //get motion from subtracting and then updating last position Angle rotation = s.Angle - s1.Angle; if (rotation > PI / 2) { rotation = PI - rotation; } if (rotation < -PI / 2) { rotation = PI + rotation; } Motion motion = new Motion() { P = (Point)s.MidPoint.V - s1.MidPoint.V, rotation = rotation, }; lastPosition.References[0].T.V = s.P1.Clone(); lastPosition.References[1].T.V = s.P2.Clone(); if (Abs(motion.R) > .01 || Abs(motion.rotation) > .05 && !goToGoal && !doBackOff) { //check for existing Event Thing currentEvent = MostLikelyEvent(t); if (currentEvent == null) { //add new Event Thing lm1 = mEvent.CreateLandmark(new List <Thing>() { t }); Thing t1 = mEvent.CreateEvent(lm1); Thing t3 = UKS.AddThing("m" + motionCount++, UKS.Labeled("Motion"), motion); mEvent.AddOutcomePair(t1, UKS.GetOrAddThing("Push", "Action"), t3); } return; } if (doBackOff) { DoBackOff(s); doBackOff = false; doFaceSegment = true; return; } if (goToGoal) { if (endTarget != null) { Segment s2 = Module2DModel.SegmentFromUKSThing(endTarget); GoToGoal(s, s2); return; } } Explore(s); }
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { Module2DSim parent = (Module2DSim)base.ParentModule; parent.inMotion = (int)speedSlider.Value; }
private void ModuleBaseDlg_Loaded(object sender, RoutedEventArgs e) { Module2DSim parent = (Module2DSim)base.ParentModule; speedSlider.Value = parent.inMotion; }
public override bool Draw(bool checkDrawTimer) { if (MainWindow.shiftPressed) { theCanvas.Cursor = Cursors.Hand; } else { theCanvas.Cursor = Cursors.Arrow; } if (!base.Draw(checkDrawTimer)) { return(false); } Module2DSim parent = (Module2DSim)base.ParentModule; //theCanvas.Children.RemoveRange(1, theCanvas.Children.Count-1); theCanvas.Children.Clear(); Point windowSize = new Point(theCanvas.ActualWidth, theCanvas.ActualHeight); Point windowCenter = new Point(windowSize.X / 2, windowSize.Y / 2); windowCenter += pan; float scale = (float)Math.Min(windowSize.X, windowSize.Y) * zoom; if (scale == 0) { return(false); } TransformGroup tg = new TransformGroup(); tg.Children.Add(new RotateTransform(90)); tg.Children.Add(new ScaleTransform(scale, -scale, 0, 0)); tg.Children.Add(new TranslateTransform(windowCenter.X, windowCenter.Y)); theCanvas.RenderTransform = tg; //add a background Rectangle r = new Rectangle() { Height = parent.boundarySize * 2, Width = parent.boundarySize * 2, Stroke = Brushes.AliceBlue, Fill = Brushes.AliceBlue }; Canvas.SetLeft(r, -parent.boundarySize); Canvas.SetTop(r, -parent.boundarySize); theCanvas.Children.Add(r); //draw the camera track... Polyline p = new Polyline(); p.StrokeThickness = 1 / scale; p.Stroke = Brushes.Pink; for (int i = 0; i < parent.entityTrack.Count; i++) { p.Points.Add( new Point( parent.entityTrack[i].X, parent.entityTrack[i].Y ) ); } theCanvas.Children.Add(p); //draw the objects for (int i = 0; i < parent.objects.Count; i++) { if (parent.objects[i].theColor != Colors.Black && parent.texture != 0) { theCanvas.Children.Add(new Line { X1 = parent.objects[i].P1.X, X2 = parent.objects[i].P2.X, Y1 = parent.objects[i].P1.Y, Y2 = parent.objects[i].P2.Y, StrokeThickness = 4 / scale, Stroke = new SolidColorBrush(parent.objects[i].theColor), }); //dash the line PointPlus P1 = new PointPlus(parent.objects[i].P1); PointPlus P2 = new PointPlus(parent.objects[i].P2); PointPlus delta = P2 - P1; delta.R = .1f; Segment s = new Segment(P1, P2, parent.objects[i].theColor); for (int j = 1; j < 1 + s.Length * 10; j += 2) { PointPlus PStart = new PointPlus((Point)(P1.V + j * delta.V)); PointPlus PEnd = new PointPlus((Point)(P1.V + (j + .5f) * delta.V)); theCanvas.Children.Add(new Line { X1 = PStart.X, X2 = PEnd.X, Y1 = PStart.Y, Y2 = PEnd.Y, StrokeThickness = 4 / scale, Stroke = new SolidColorBrush(Colors.AliceBlue), }); } } else { theCanvas.Children.Add(new Line { X1 = parent.objects[i].P1.X, X2 = parent.objects[i].P2.X, Y1 = parent.objects[i].P1.Y, Y2 = parent.objects[i].P2.Y, StrokeThickness = 4 / scale, Stroke = new SolidColorBrush(parent.objects[i].theColor), }); } } //draw the arms... if (parent.armActual.Length == 2) { for (int i = 0; i < parent.armActual.Length; i++) { PointPlus c = new PointPlus { P = (Point)(parent.armActual[i] - parent.entityPosition) }; double sa = c.R * .85; //lower arm lengths //double sb = (c.R-sa) * 4; //upper arm lengths //double sa = .45; // lower arm lengths double sb = .3; // upper arm lengths float a = (float)(Math.Acos((sb * sb + c.R * c.R - sa * sa) / (2 * sb * c.R))); if (!Double.IsNaN(a)) { PointPlus pa = new PointPlus { R = (float)sb, Theta = c.Theta }; if (i == 0) { pa.Theta += a; } else { pa.Theta -= a; } pa.P = (Point)(pa.P + (Vector)parent.entityPosition); theCanvas.Children.Add(new Line { X1 = parent.entityPosition.X, Y1 = parent.entityPosition.Y, X2 = pa.P.X, Y2 = pa.P.Y, StrokeThickness = 2 / scale, Stroke = Brushes.Black }); theCanvas.Children.Add(new Line { X1 = pa.P.X, Y1 = pa.P.Y, X2 = parent.armActual[i].X, Y2 = parent.armActual[i].Y, StrokeThickness = 2 / scale, Stroke = Brushes.Black }); } } } //draw the current field of view if ((bool)cbArcs.IsChecked) { for (int i = 0; i < parent.currentView0.Count; i++) { try //TODO lock the list { theCanvas.Children.Add(new Line { X1 = parent.currentView0[i].P1.X, Y1 = parent.currentView0[i].P1.Y, X2 = parent.currentView0[i].P1.X, Y2 = parent.currentView0[i].P1.Y, StrokeThickness = 3 / scale, StrokeEndLineCap = PenLineCap.Round, StrokeStartLineCap = PenLineCap.Round, Stroke = new SolidColorBrush(parent.currentView0[i].theColor) }); } catch { } } for (int i = 0; i < parent.currentView1.Count; i++) { try //another thread might mess the array up TODO, lock the object list { theCanvas.Children.Add(new Line { X1 = parent.currentView1[i].P1.X, Y1 = parent.currentView1[i].P1.Y, X2 = parent.currentView1[i].P1.X, Y2 = parent.currentView1[i].P1.Y, StrokeThickness = 3 / scale, StrokeEndLineCap = PenLineCap.Round, StrokeStartLineCap = PenLineCap.Round, Stroke = new SolidColorBrush(parent.currentView1[i].theColor) }); } catch { } } } ////draw the body...it's a transparent gif Image body = new Image() { Source = new BitmapImage(new Uri("/Resources/entity.png", UriKind.Relative)), Width = 2 * parent.bodyRadius, Height = 2 * parent.bodyRadius }; TransformGroup tg1 = new TransformGroup(); tg1.Children.Add(new TranslateTransform(-parent.bodyRadius, -parent.bodyRadius)); tg1.Children.Add(new RotateTransform(90 + parent.entityDirection1 * 180 / Math.PI)); body.RenderTransform = tg1; Canvas.SetLeft(body, parent.entityPosition.X); Canvas.SetTop(body, parent.entityPosition.Y); theCanvas.Children.Add(body); return(true); }
private void Button_Click(object sender, RoutedEventArgs e) { Module2DSim parent = (Module2DSim)base.ParentModule; parent.SetModel(); }
public override void Fire() { Init(); //be sure to leave this here to enable use of the na variable float[] dist = { .5f, .1f, 0, -.025f, -.1f }; float motionX = 0; float motionY = 0; if (na.Width < 3) { Initialize(); } for (int i = 0; i < na.Height; i++) { if (na.GetNeuronAt(1, i).LastCharge > 0.9) { motionX = dist[i]; } } if (na.GetNeuronAt(1, 2).CurrentCharge != 0) { motionX = na.GetNeuronAt(1, 2).CurrentCharge; na.GetNeuronAt(1, 2).SetValue(0); } if (na.GetNeuronAt(0, 2).LastCharge > 0.9) { motionY = 0.5f; } if (na.GetNeuronAt(2, 2).LastCharge > 0.9) { motionY = -0.5f; } //obsolete ModuleRealityModel mrm = (ModuleRealityModel)FindModuleByType(typeof(ModuleRealityModel)); if (mrm != null) { mrm.Move(motionX); } Module3DSim m3D = (Module3DSim)FindModuleByType(typeof(Module3DSim)); if (m3D != null && motionX != 0) { m3D.Move(motionX); } bool moved = false; Module2DSim m2D = (Module2DSim)FindModuleByType(typeof(Module2DSim)); if (m2D != null && motionX != 0 || motionY != 0) { moved = m2D.Move(motionX, motionY); } Module2DModel m2DModel = (Module2DModel)FindModuleByType(typeof(Module2DModel)); if (m2DModel != null && moved && motionX != 0 || motionY != 0) { m2DModel.Move(motionX, motionY); } Module2DVision m2DVision = (Module2DVision)FindModuleByType(typeof(Module2DVision)); if (m2DVision != null && motionX != 0) { m2DVision.ViewChanged(); } }