private void AddEgg_Click(object sender, RoutedEventArgs e) { try { if (_bots.Count == 0) { MessageBox.Show("Add a bot first", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } Swimbot bot = _bots[StaticRandom.Next(_bots.Count)]; Point3D position = bot.PositionWorld + Math3D.GetRandomVector_Spherical_Shell(bot.Radius * 1.5d); // The radius should be 20% the size of the adult ship ShipDNA dna = bot.GetNewDNA(); double radius = dna.PartsByLayer.SelectMany(o => o.Value). Max(o => o.Position.ToVector().Length + Math1D.Max(o.Scale.X, o.Scale.Y, o.Scale.Z)) * .2d; Egg <ShipDNA> egg = new Egg <ShipDNA>(position, radius, _world, _material_Egg, _itemOptions, dna); egg.PhysicsBody.AngularVelocity = bot.PhysicsBody.AngularVelocity; egg.PhysicsBody.Velocity = bot.PhysicsBody.Velocity; egg.PhysicsBody.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Egg_ApplyForceAndTorque); _map.AddItem(egg); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private static Model3D GetModel_Shop(out BotShellColorsDNA backdropColors, double radius) { Model3DGroup retVal = new Model3DGroup(); backdropColors = new BotShellColorsDNA(); backdropColors.DiffuseDrift = 0; backdropColors.EmissiveColor = "00000000"; #region Plate backdropColors.InnerColorDiffuse = "554A3A"; // Material MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(backdropColors.InnerColorDiffuse)))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("40958265")), 20d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, radius, radius, radius * .1); retVal.Children.Add(geometry); #endregion #region Gold Mineral // Get gold's color backdropColors.Light = Mineral.GetSettingsForMineralType(MineralType.Gold).DiffuseColor.ToHex(); // Get the model of a gold mineral Model3D model = Mineral.GetNewVisual(MineralType.Gold); // Figure out the scale Rect3D aabb = model.Bounds; double halfSize = Math1D.Max(aabb.SizeX, aabb.SizeY, aabb.SizeZ) / 2d; double scale = (radius * .66d) / halfSize; model.Transform = new ScaleTransform3D(scale, scale, scale); retVal.Children.Add(model); #endregion return(retVal); }
void Update() { // See if the left mouse is down if (!Input.GetMouseButton(0)) { return; } // When they first hit the mouse down, define the click point to be along the camera look and intersecting the grab ball bool isFirstClick = Input.GetMouseButtonDown(0); if (isFirstClick) { _clickPlane = new Plane(_camera.transform.forward, transform.position); } Vector3 mousePos = Input.mousePosition; Rect screenRect = new Rect(0, 0, Screen.width, Screen.height); if (!screenRect.Contains(mousePos)) // this can happen when they start on screen and keep dragging off screen { return; } Ray ray = _camera.ScreenPointToRay(mousePos); // Move the grab object to where the mouse ray intersects the click plane Vector3?newPos = Math3D.GetIntersection_Plane_Ray(_clickPlane, ray); if (newPos == null) { return; } if (isFirstClick) { _isSelected = (transform.position - newPos.Value).magnitude <= Math1D.Max(transform.localScale.x, transform.localScale.y, transform.localScale.z) * 1.2f; } if (!_isSelected) { return; } transform.position = newPos.Value; }
private static NeuronMapping[] MapNeurons(Point3D[] externalPoints, Point3D[] internalPoints) { // FuzzyLink wasn't designed for from and to points to be sitting on top of each other, so need to pull them apart // // external is pulled to -Z, internal is +Z. These offset coordinates don't have any meaning outside this function, they are just // a hack to allow FuzzyLink to work properly // Figure out how far to separate them to ensure they are fully separated var aabb = Math3D.GetAABB(externalPoints.Concat(internalPoints)); double offsetDist = Math1D.Max(aabb.Item2.X - aabb.Item1.X, aabb.Item2.Y - aabb.Item1.Y, aabb.Item2.Z - aabb.Item1.Z); offsetDist *= 3; Vector3D offset = new Vector3D(0, 0, offsetDist); // Create seed links. The easiest approach is just to create one per internal point and then let the fuzzy linker find the best // external point // // I could see the argument for remembering the links across generations so that if the external points drift around too much, // the original linking will better persist. But if the bot is mutating that much over generations, the neat NN should be retrained // from time to time. Also, if a mismapping causes the bot to perform bad, then it won't be making children (and a mismapping // might end up causing better performance) Tuple <Point3D, Point3D, double>[] initialLinks = internalPoints. Select(o => Tuple.Create(o - offset, o + offset, 1d)). ToArray(); Point3D[] pointsForFuzzy = externalPoints.Select(o => o - offset). Concat(internalPoints.Select(o => o + offset)). ToArray(); // Allow a few more links than points. If the external and internal points are aligned well, then the extra link allowance won't // be used int numLinks = (internalPoints.Length * 1.1).ToInt_Ceiling(); var finalLinks = ItemLinker.FuzzyLink(initialLinks, pointsForFuzzy, numLinks, 6); const double THICKNESS = .005; const double DOT = THICKNESS * 3; Debug3DWindow window = new Debug3DWindow(); window.AddDots(externalPoints, DOT, Colors.IndianRed); window.AddDots(internalPoints, DOT, Colors.DodgerBlue); window.AddDots(pointsForFuzzy, DOT, Colors.Silver); window.AddLines(initialLinks.Select(o => (o.Item1, o.Item2)), THICKNESS, Colors.Orchid); List <NeuronMapping> retVal = new List <NeuronMapping>(); foreach (var link in finalLinks) { int?externalIndex = null; int?internalIndex = null; foreach (int index in new[] { link.Item1, link.Item2 }) { if (index < externalPoints.Length) { externalIndex = index; } else { internalIndex = index - externalPoints.Length; } } if (externalIndex == null || internalIndex == null) { // This should never happen in practice, the internal and external sets are pulled too far apart to accidentally be linked together. // Just ignore this link continue; } retVal.Add(new NeuronMapping() { Index_External = externalIndex.Value, Index_NEAT = internalIndex.Value, Weight = link.Item3, }); } foreach (var link in finalLinks) { window.AddLine(pointsForFuzzy[link.Item1], pointsForFuzzy[link.Item2], THICKNESS * link.Item3, Colors.GhostWhite); } foreach (var link in retVal) { window.AddLine(externalPoints[link.Index_External], internalPoints[link.Index_NEAT], THICKNESS * link.Weight, Colors.Coral); } window.Show(); return(retVal.ToArray()); }
private void CreateStars() { const double DENSITY = 1000d / (800d * 800d); const double STARSIZE = 1d / 1500d; double innerRadius = Math1D.Max(Math.Abs(_boundryMax.X), Math.Abs(_boundryMax.Y), Math.Abs(_boundryMax.Z)); innerRadius *= 2; double outerRadius = innerRadius * 2d; double ratio; switch (_optionsPanel.NumStartingObjects) { case NumberOfStartingObjects.VeryFew: ratio = .1d; break; case NumberOfStartingObjects.Few: ratio = .5d; break; case NumberOfStartingObjects.Normal: ratio = 1d; break; case NumberOfStartingObjects.Many: ratio = 1.5d; break; default: throw new ApplicationException("Unknown NumberOfStartingObjects: " + _optionsPanel.NumStartingObjects.ToString()); } int numStars = Convert.ToInt32(DENSITY * innerRadius * innerRadius * ratio); int maxStars = Convert.ToInt32(5000d * ratio); if (numStars > maxStars) { numStars = maxStars; } Random rand = StaticRandom.GetRandomForThread(); Model3DGroup geometries = new Model3DGroup(); for (int cntr = 0; cntr < numStars; cntr++) { #region Geometry // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(WorldColors.Star_Color))); materials.Children.Add(new EmissiveMaterial(new SolidColorBrush(WorldColors.Star_Emissive))); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = _sharedVisuals.StarMesh; // Transform Transform3DGroup transform = new Transform3DGroup(); double scale = innerRadius * STARSIZE; if (rand.NextDouble() > .95d) { scale *= 1d + (rand.NextDouble() * 1.5); } transform.Children.Add(new ScaleTransform3D(scale, scale, scale)); // scale needs to be first (or the prev transforms will be scaled as well) transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()))); // rotate needs to be added before translate transform.Children.Add(new TranslateTransform3D(Math3D.GetRandomVector_Spherical(innerRadius, outerRadius))); geometry.Transform = transform; geometries.Children.Add(geometry); #endregion } // Model Visual ModelVisual3D model = new ModelVisual3D(); // since the stars are static, only make one model. It's way more efficient model.Content = geometries; // Add to the viewport _viewport.Children.Add(model); _stars.Add(model); }