Beispiel #1
0
        private static Model3DGroup GetModel_Rod(WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            Model3DGroup retVal = new Model3DGroup();

            switch (dna.HandleMaterial)
            {
            case WeaponHandleMaterial.Soft_Wood:
            case WeaponHandleMaterial.Hard_Wood:
                GetModel_Rod_Wood(retVal, dna, finalDNA, materials);
                break;

            case WeaponHandleMaterial.Bronze:
            case WeaponHandleMaterial.Iron:
            case WeaponHandleMaterial.Steel:
                GetModel_Rod_Metal(retVal, dna, finalDNA, materials);
                break;

            case WeaponHandleMaterial.Composite:
                GetModel_Rod_Composite(retVal, dna, finalDNA, materials);
                break;

            case WeaponHandleMaterial.Klinth:
                GetModel_Rod_Klinth(retVal, dna, finalDNA, materials);
                break;

            case WeaponHandleMaterial.Moon:
                GetModel_Rod_Moon(retVal, dna, finalDNA, materials);
                break;

            default:
                throw new ApplicationException("Unknown WeaponHandleMaterial: " + dna.HandleMaterial.ToString());
            }

            return(retVal);
        }
Beispiel #2
0
        private static void GetModel_Rod_Klinth(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            GeometryModel3D geometry = new GeometryModel3D();

            var color = WeaponMaterialCache.GetKlinth(dna.MaterialsForCustomizable);

            finalDNA.MaterialsForCustomizable = color.Item3;

            geometry.Material     = color.Item1;
            geometry.BackMaterial = color.Item1;

            //NOTE: The dimensions shouldn't be randomized.  This should look like a manufactured, almost mass produced product.
            // Also, being a crystal, it needs to appear solid

            List <TubeRingBase> rings = new List <TubeRingBase>();

            rings.Add(new TubeRingPoint(0, false));
            rings.Add(new TubeRingRegularPolygon(.2, false, .75, .75, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, 1, 1, false));
            rings.Add(new TubeRingRegularPolygon(.5, false, .9, .9, false));
            rings.Add(new TubeRingRegularPolygon(1, false, .8, .8, false));
            rings.Add(new TubeRingRegularPolygon(15, false, .8, .8, false));
            rings.Add(new TubeRingRegularPolygon(1, false, .9, .9, false));
            rings.Add(new TubeRingRegularPolygon(.5, false, 1, 1, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, .75, .75, false));
            rings.Add(new TubeRingPoint(.2, false));

            rings = TubeRingBase.FitNewSize(rings, dna.Radius, dna.Radius, dna.Length);

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(5, rings, false, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x

            geometries.Children.Add(geometry);
        }
        public WeaponHandle(WeaponMaterialCache materials, WeaponHandleDNA dna)
        {
            _materials = materials;

            var model = GetModel(dna, materials);

            this.Model = model.Item1;
            this.DNA = model.Item2;
        }
Beispiel #4
0
        public WeaponHandle(WeaponMaterialCache materials, WeaponHandleDNA dna)
        {
            _materials = materials;

            var model = GetModel(dna, materials);

            Model = model.model;
            DNA   = model.dna;
        }
Beispiel #5
0
        //TODO: random chance of randomly placing metal fittings on the handle
        private static void GetModel_Rod_Wood(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            const double PERCENT = 1;

            Random rand = StaticRandom.GetRandomForThread();
            var    from = dna.KeyValues;
            var    to   = finalDNA.KeyValues;

            GeometryModel3D geometry = new GeometryModel3D();

            #region material

            switch (dna.HandleMaterial)
            {
            case WeaponHandleMaterial.Soft_Wood:
                geometry.Material = materials.Handle_SoftWood;
                break;

            case WeaponHandleMaterial.Hard_Wood:
                geometry.Material = materials.Handle_HardWood;
                break;

            default:
                throw new ApplicationException("Unexpected WeaponHandleMaterial: " + dna.HandleMaterial.ToString());
            }

            geometry.BackMaterial = geometry.Material;

            #endregion

            #region tube

            double maxX1 = WeaponDNA.GetKeyValue("maxX1", from, to, rand.NextDouble(.45, .7));
            double maxX2 = WeaponDNA.GetKeyValue("maxX2", from, to, rand.NextDouble(.45, .7));

            double maxY1 = WeaponDNA.GetKeyValue("maxY1", from, to, rand.NextDouble(.85, 1.05));
            double maxY2 = WeaponDNA.GetKeyValue("maxY2", from, to, rand.NextDouble(.85, 1.05));

            List <TubeRingBase> rings = new List <TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, maxX1 * .45, maxY1 * .75, true));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring1", from, to, rand.NextPercent(.5, PERCENT)), false, maxX1 * .5, maxY1 * 1, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring2", from, to, rand.NextPercent(2, PERCENT)), false, maxX1 * .4, maxY1 * .8, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring3", from, to, rand.NextPercent(5, PERCENT)), false, Math1D.Avg(maxX1, maxX2) * .35, Math1D.Avg(maxY1, maxY2) * .75, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring4", from, to, rand.NextPercent(5, PERCENT)), false, maxX2 * .4, maxY2 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring5", from, to, rand.NextPercent(2, PERCENT)), false, maxX2 * .5, maxY2 * 1, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring6", from, to, rand.NextPercent(.5, PERCENT)), false, maxX2 * .45, maxY2 * .75, true));

            rings = TubeRingBase.FitNewSize(rings, dna.Radius * Math.Max(maxX1, maxX2), dna.Radius * Math.Max(maxY1, maxY2), dna.Length);                        // multiplying x by maxX, because the rings were defined with x maxing at maxX, and y maxing at 1

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(10, rings, true, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90))); // the tube builds along z, but this class wants along x

            #endregion

            geometries.Children.Add(geometry);
        }
        private static Tuple<Model3DGroup, WeaponHandleDNA> GetModel(WeaponHandleDNA dna, WeaponMaterialCache materials)
        {
            WeaponHandleDNA finalDNA = UtilityCore.Clone(dna);
            if (finalDNA.KeyValues == null)
            {
                finalDNA.KeyValues = new SortedList<string, double>();
            }

            Model3DGroup model = null;

            // If there is a mismatch between desired material and type, prefer material
            finalDNA.HandleType = GetHandleType(dna.HandleMaterial, dna.HandleType);

            // Build the handle
            switch (finalDNA.HandleType)
            {
                case WeaponHandleType.Rod:
                    model = GetModel_Rod(dna, finalDNA, materials);
                    break;

                case WeaponHandleType.Rope:
                    throw new ApplicationException("Rope currently isn't supported");

                default:
                    throw new ApplicationException("Unknown WeaponHandleType: " + finalDNA.HandleType.ToString());
            }

            // Exit Function
            return Tuple.Create(model, finalDNA);

            #region WRAITH
            //retVal.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(this.DiffuseColor))));
            //retVal.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(this.SpecularColor)), this.SpecularPower.Value));
            //retVal.Children.Add(new EmissiveMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(this.EmissiveColor))));


            //case WeaponHandleMaterial.Wraith:
            //    #region Wraith

            //    retVal.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("6048573E"))));
            //    retVal.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("202C1D33")), 50d));
            //    retVal.Children.Add(new EmissiveMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("1021222B"))));

            //    #endregion
            //    break;




            //if (useDebugVisual)
            //{
            //    geometry.Geometry = UtilityWPF.GetLine(new Point3D(-(handle.Length / 2d), 0, 0), new Point3D(handle.Length / 2d, 0, 0), handle.Radius * 2d);
            //}
            #endregion
        }
Beispiel #7
0
        private static (Model3DGroup model, WeaponHandleDNA dna) GetModel(WeaponHandleDNA dna, WeaponMaterialCache materials)
        {
            WeaponHandleDNA finalDNA = UtilityCore.Clone(dna);

            if (finalDNA.KeyValues == null)
            {
                finalDNA.KeyValues = new SortedList <string, double>();
            }

            Model3DGroup model = null;

            // If there is a mismatch between desired material and type, prefer material
            finalDNA.HandleType = GetHandleType(dna.HandleMaterial, dna.HandleType);

            // Build the handle
            switch (finalDNA.HandleType)
            {
            case WeaponHandleType.Rod:
                model = GetModel_Rod(dna, finalDNA, materials);
                break;

            case WeaponHandleType.Rope:
                throw new ApplicationException("Rope currently isn't supported");

            default:
                throw new ApplicationException("Unknown WeaponHandleType: " + finalDNA.HandleType.ToString());
            }

            return(model, finalDNA);

            #region WRAITH
            //retVal.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(this.DiffuseColor))));
            //retVal.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(this.SpecularColor)), this.SpecularPower.Value));
            //retVal.Children.Add(new EmissiveMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(this.EmissiveColor))));


            //case WeaponHandleMaterial.Wraith:
            //    #region Wraith

            //    retVal.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("6048573E"))));
            //    retVal.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("202C1D33")), 50d));
            //    retVal.Children.Add(new EmissiveMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("1021222B"))));

            //    #endregion
            //    break;



            //if (useDebugVisual)
            //{
            //    geometry.Geometry = UtilityWPF.GetLine(new Point3D(-(handle.Length / 2d), 0, 0), new Point3D(handle.Length / 2d, 0, 0), handle.Radius * 2d);
            //}
            #endregion
        }
        private static Model3DGroup GetModel_Rod(WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            Model3DGroup retVal = new Model3DGroup();

            switch (dna.HandleMaterial)
            {
                case WeaponHandleMaterial.Soft_Wood:
                case WeaponHandleMaterial.Hard_Wood:
                    GetModel_Rod_Wood(retVal, dna, finalDNA, materials);
                    break;

                case WeaponHandleMaterial.Bronze:
                case WeaponHandleMaterial.Iron:
                case WeaponHandleMaterial.Steel:
                    GetModel_Rod_Metal(retVal, dna, finalDNA, materials);
                    break;

                case WeaponHandleMaterial.Composite:
                    GetModel_Rod_Composite(retVal, dna, finalDNA, materials);
                    break;

                case WeaponHandleMaterial.Klinth:
                    GetModel_Rod_Klinth(retVal, dna, finalDNA, materials);
                    break;

                case WeaponHandleMaterial.Moon:
                    GetModel_Rod_Moon(retVal, dna, finalDNA, materials);
                    break;

                default:
                    throw new ApplicationException("Unknown WeaponHandleMaterial: " + dna.HandleMaterial.ToString());
            }

            // Exit Function
            return retVal;
        }
        private static void GetModel_Rod_Moon(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            const double PERCENT = 1;

            Random rand = StaticRandom.GetRandomForThread();
            var from = dna.KeyValues;
            var to = finalDNA.KeyValues;

            #region Shaft

            GeometryModel3D shaft = new GeometryModel3D();

            shaft.Material = materials.Handle_Moon;
            shaft.BackMaterial = shaft.Material;

            double maxRad1 = WeaponDNA.GetKeyValue("maxRad1", from, to, rand.NextDouble(.7, 1.02));
            double maxRad2 = WeaponDNA.GetKeyValue("maxRad2", from, to, rand.NextDouble(.7, 1.02));
            double maxRad12 = Math.Max(maxRad1, maxRad2);       // this is used in several places

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, maxRad1 * .4, maxRad1 * .4, true));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube1", from, to, rand.NextPercent(.25, PERCENT)), false, maxRad1 * .8, maxRad1 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube2", from, to, rand.NextPercent(.3, PERCENT)), false, maxRad1 * .85, maxRad1 * .85, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube3", from, to, rand.NextPercent(.75, PERCENT)), false, maxRad1 * .6, maxRad1 * .6, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube4", from, to, rand.NextPercent(20, PERCENT)), false, maxRad2 * .8, maxRad2 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube5", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * .9, maxRad2 * .9, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube6", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * 1, maxRad2 * 1, false));
            rings.Add(new TubeRingDome(WeaponDNA.GetKeyValue("tube7", from, to, rand.NextPercent(2.5, PERCENT)), false, 4));

            rings = TubeRingBase.FitNewSize(rings, maxRad12 * dna.Radius, maxRad12 * dna.Radius, dna.Length);

            shaft.Geometry = UtilityWPF.GetMultiRingedTube(10, rings, true, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));      // the tube builds along z, but this class wants along x

            #endregion

            // Number of gems
            int numIfNew = 0;
            if (rand.NextDouble() > .66d)       // only 33% will get gems
            {
                // Of the handles with gems, only 5% will get 2
                numIfNew = rand.NextDouble() > .95 ? 2 : 1;
            }

            int numGems = Convert.ToInt32(WeaponDNA.GetKeyValue("numGems", from, to, numIfNew));

            if (numGems == 0)
            {
                geometries.Children.Add(shaft);
                return;
            }

            #region Gems

            List<double> percents = new List<double>();

            for (int cntr = 0; cntr < numGems; cntr++)
            {
                string keyPrefix = "gem" + cntr.ToString();

                // Get a placement for this gem
                double percentIfNew = 0;
                do
                {
                    percentIfNew = rand.NextDouble(.15, .85);

                    if (percents.Count == 0)
                    {
                        break;
                    }
                } while (percents.Any(o => Math.Abs(percentIfNew - o) < .15));

                double percent = WeaponDNA.GetKeyValue(keyPrefix + "Percent", from, to, percentIfNew);

                percents.Add(percent);

                // Gem
                GeometryModel3D gem = new GeometryModel3D();

                gem.Material = materials.Handle_MoonGem;
                gem.BackMaterial = gem.Material;

                double width = WeaponDNA.GetKeyValue(keyPrefix + "Width", from, to, rand.NextDouble(maxRad12 * 1d, maxRad12 * 1.4d));

                gem.Geometry = UtilityWPF.GetSphere_LatLon(5, dna.Radius * width);
                Point3D position = new Point3D((dna.Length * percent) - (dna.Length / 2d), 0, 0);
                gem.Transform = new TranslateTransform3D(position.ToVector());

                // Light
                PointLight pointLight = new PointLight(materials.Handle_MoonGemLight, position);
                UtilityWPF.SetAttenuation(pointLight, dna.Radius * 120d, .1d);

                geometries.Children.Add(pointLight);
                geometries.Children.Add(gem);
            }

            // Adding this after so that you don't see the shaft through the gems
            geometries.Children.Add(shaft);

            #endregion
        }
        public static WeaponHandleDNA GetRandomDNA(WeaponHandleMaterial? material = null, WeaponHandleType? type = null, bool? isDouble = null, double? length = null, double? radius = null)
        {
            const double DOUBLE_END = .2d;
            const double DOUBLE_CENTER = .05d;       // this is only half of the center

            WeaponHandleDNA retVal = new WeaponHandleDNA();

            Random rand = StaticRandom.GetRandomForThread();

            bool isDoubleActual = isDouble ?? (rand.Next(2) == 0);

            #region Material

            if (material == null)
            {
                retVal.HandleMaterial = UtilityCore.GetRandomEnum<WeaponHandleMaterial>();
            }
            else
            {
                retVal.HandleMaterial = material.Value;
            }

            #endregion

            //TODO: Support rope
            retVal.HandleType = WeaponHandleType.Rod;

            #region Length

            if (length == null)
            {
                //double lengthActual = rand.NextDouble(1.5d, 3.5d);
                double lengthActual = rand.NextDouble(1.5d, 2.8d);
                if (isDoubleActual)
                {
                    lengthActual *= 2d;
                }

                retVal.Length = lengthActual;
            }
            else
            {
                retVal.Length = length.Value;
            }

            #endregion
            #region Radius

            if (radius == null)
            {
                //double radiusActual = rand.NextDouble(.03d, .17d);
                double radiusActual = rand.NextDouble(.03d, .12d);
                if (isDoubleActual)
                {
                    radiusActual *= 2d;
                }

                retVal.Radius = radiusActual;
            }
            else
            {
                retVal.Radius = radius.Value;
            }

            #endregion
            #region AttachPoint

            if (isDoubleActual)
            {
                // Since the center of mass is in the middle, the attach point can't be in the middle.
                // Both ends are out as well.
                // So, choose one of the areas that are stars
                //  |----|********|--------|********|----|

                double randMaxValue = .5d - DOUBLE_END - DOUBLE_CENTER;
                double randValue = rand.NextDouble(randMaxValue);
                double half = DOUBLE_CENTER + randValue;

                if (rand.NextBool())
                {
                    // left side
                    retVal.AttachPointPercent = .5d - half;
                }
                else
                {
                    // right side
                    retVal.AttachPointPercent = .5d + half;
                }
            }
            else
            {
                // Choose one of the ends
                retVal.AttachPointPercent = rand.NextBool() ? 0d : 1d;
            }

            #endregion

            #region Color

            switch (retVal.HandleMaterial)
            {
                case WeaponHandleMaterial.Composite:
                    retVal.MaterialsForCustomizable = GetRandomMaterials_Composite();
                    break;

                case WeaponHandleMaterial.Klinth:
                    retVal.MaterialsForCustomizable = GetRandomMaterials_Klinth();
                    break;
            }

            #endregion

            return retVal;
        }
        private static void GetModel_Rod_Composite(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            Random rand = StaticRandom.GetRandomForThread();

            finalDNA.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Composite(dna.MaterialsForCustomizable);
            var from = dna.KeyValues;
            var to = finalDNA.KeyValues;

            double halfLength = dna.Length / 2d;
            double halfBeamThickness = dna.Radius / 8d;
            double halfCoreThickness = (dna.Radius * .66d) / 2d;
            double washerRadius = dna.Radius * 1.1;

            double washerThickness1 = WeaponDNA.GetKeyValue("washerThickness1", from, to, dna.Length * rand.NextPercent(.015d, .5d));
            double washerThickness2 = WeaponDNA.GetKeyValue("washerThickness2", from, to, dna.Length * rand.NextPercent(.15d, .5d));
            double washerOffset = WeaponDNA.GetKeyValue("washerOffset", from, to, rand.NextPercent(.05d, .5d));

            var material = GetModel_Rod_CompositeSprtMaterial(finalDNA.MaterialsForCustomizable[0]);

            //NOTE: The beam/core dimensions shouldn't be randomized.  This should look like a manufactured, almost mass produced product
            #region Beams

            // Beam1
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -dna.Radius, -halfBeamThickness), new Point3D(halfLength, dna.Radius, halfBeamThickness));

            geometries.Children.Add(geometry);

            // Beam2
            geometry = new GeometryModel3D();

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -halfBeamThickness, -dna.Radius), new Point3D(halfLength, halfBeamThickness, dna.Radius));

            geometries.Children.Add(geometry);

            #endregion
            #region Core

            material = GetModel_Rod_CompositeSprtMaterial(finalDNA.MaterialsForCustomizable[1]);

            geometry = new GeometryModel3D();

            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -halfCoreThickness, -halfCoreThickness), new Point3D(halfLength, halfCoreThickness, halfCoreThickness));

            geometry.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 45));

            geometries.Children.Add(geometry);

            #endregion
            #region Washers

            material = GetModel_Rod_CompositeSprtMaterial(finalDNA.MaterialsForCustomizable[2]);

            var locations = new Tuple<double, double>[] 
            {
                Tuple.Create(0d, washerThickness1),
                Tuple.Create(washerOffset, washerThickness1),
                Tuple.Create(.5d, washerThickness2),
                Tuple.Create(1d - washerOffset, washerThickness1),
                Tuple.Create(1d, washerThickness1)
            };

            foreach (var loc in locations)
            {
                geometry = new GeometryModel3D();

                geometry.Material = material;
                geometry.BackMaterial = material;

                geometry.Geometry = UtilityWPF.GetCylinder_AlongX(8, washerRadius, loc.Item2);

                geometry.Transform = new TranslateTransform3D(-halfLength + (dna.Length * loc.Item1), 0, 0);

                geometries.Children.Add(geometry);
            }

            #endregion
        }
        private static void GetModel_Rod_Klinth(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            GeometryModel3D geometry = new GeometryModel3D();

            var color = WeaponMaterialCache.GetKlinth(dna.MaterialsForCustomizable);
            finalDNA.MaterialsForCustomizable = color.Item3;

            geometry.Material = color.Item1;
            geometry.BackMaterial = color.Item1;

            //NOTE: The dimensions shouldn't be randomized.  This should look like a manufactured, almost mass produced product.
            // Also, being a crystal, it needs to appear solid

            List<TubeRingBase> rings = new List<TubeRingBase>();

            rings.Add(new TubeRingPoint(0, false));
            rings.Add(new TubeRingRegularPolygon(.2, false, .75, .75, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, 1, 1, false));
            rings.Add(new TubeRingRegularPolygon(.5, false, .9, .9, false));
            rings.Add(new TubeRingRegularPolygon(1, false, .8, .8, false));
            rings.Add(new TubeRingRegularPolygon(15, false, .8, .8, false));
            rings.Add(new TubeRingRegularPolygon(1, false, .9, .9, false));
            rings.Add(new TubeRingRegularPolygon(.5, false, 1, 1, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, .75, .75, false));
            rings.Add(new TubeRingPoint(.2, false));

            rings = TubeRingBase.FitNewSize(rings, dna.Radius, dna.Radius, dna.Length);

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(5, rings, false, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x

            geometries.Children.Add(geometry);
        }
        private static void GetModel_Rod_Metal(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            Random rand = StaticRandom.GetRandomForThread();
            var from = dna.KeyValues;
            var to = finalDNA.KeyValues;

            #region Materials

            System.Windows.Media.Media3D.Material material1, material2;

            switch (dna.HandleMaterial)
            {
                case WeaponHandleMaterial.Bronze:
                    material1 = materials.Handle_Bronze;       // the property get returns a slightly random color
                    material2 = materials.Handle_Bronze;
                    break;

                case WeaponHandleMaterial.Iron:
                    material1 = materials.Handle_Iron;
                    material2 = materials.Handle_Iron;
                    break;

                case WeaponHandleMaterial.Steel:
                    material1 = materials.Handle_Steel;
                    material2 = materials.Handle_Steel;
                    break;

                default:
                    throw new ApplicationException("Unexpected WeaponHandleMaterial: " + dna.HandleMaterial.ToString());
            }

            #endregion

            #region Ends

            double capRadius = dna.Radius * 1.1;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, capRadius * .75, capRadius * .75, true));
            rings.Add(new TubeRingRegularPolygon(capRadius * .2, false, capRadius, capRadius, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("capWidth", from, to, capRadius * (1d + rand.NextPow(7d, 2.2d))), false, capRadius, capRadius, false));
            rings.Add(new TubeRingRegularPolygon(capRadius * .8, false, capRadius * .75, capRadius * .75, true));

            double capHeight = TubeRingBase.GetTotalHeight(rings);
            double halfLength = dna.Length / 2d;
            double halfCap = capHeight / 2d;

            // Cap 1
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material = material1;
            geometry.BackMaterial = material1;

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x
            transform.Children.Add(new TranslateTransform3D(-halfLength + halfCap, 0, 0));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(6, rings, false, true, transform);

            geometries.Children.Add(geometry);

            // Cap 2
            geometry = new GeometryModel3D();

            geometry.Material = material1;
            geometry.BackMaterial = material1;

            transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));      // the tube builds along z, but this class wants along x
            transform.Children.Add(new TranslateTransform3D(halfLength - halfCap, 0, 0));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(6, rings, false, true, transform);

            geometries.Children.Add(geometry);

            #endregion

            #region Shaft

            geometry = new GeometryModel3D();

            geometry.Material = material2;
            geometry.BackMaterial = material2;

            rings = new List<TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, dna.Radius * .8, dna.Radius * .8, true));
            rings.Add(new TubeRingRegularPolygon(dna.Length - capHeight, false, dna.Radius * .8, dna.Radius * .8, true));

            transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 45)));      // make the bar impact along the edge instead of the flat part

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(4, rings, false, true, transform);

            geometries.Children.Add(geometry);

            #endregion
        }
Beispiel #14
0
        private static void GetModel_Rod_Metal(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            Random rand = StaticRandom.GetRandomForThread();
            var    from = dna.KeyValues;
            var    to   = finalDNA.KeyValues;

            #region materials

            System.Windows.Media.Media3D.Material material1, material2;

            switch (dna.HandleMaterial)
            {
            case WeaponHandleMaterial.Bronze:
                material1 = materials.Handle_Bronze;           // the property get returns a slightly random color
                material2 = materials.Handle_Bronze;
                break;

            case WeaponHandleMaterial.Iron:
                material1 = materials.Handle_Iron;
                material2 = materials.Handle_Iron;
                break;

            case WeaponHandleMaterial.Steel:
                material1 = materials.Handle_Steel;
                material2 = materials.Handle_Steel;
                break;

            default:
                throw new ApplicationException("Unexpected WeaponHandleMaterial: " + dna.HandleMaterial.ToString());
            }

            #endregion

            #region ends

            double capRadius = dna.Radius * 1.1;

            List <TubeRingBase> rings = new List <TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, capRadius * .75, capRadius * .75, true));
            rings.Add(new TubeRingRegularPolygon(capRadius * .2, false, capRadius, capRadius, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("capWidth", from, to, capRadius * (1d + rand.NextPow(7d, 2.2d))), false, capRadius, capRadius, false));
            rings.Add(new TubeRingRegularPolygon(capRadius * .8, false, capRadius * .75, capRadius * .75, true));

            double capHeight  = TubeRingBase.GetTotalHeight(rings);
            double halfLength = dna.Length / 2d;
            double halfCap    = capHeight / 2d;

            // Cap 1
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = material1;
            geometry.BackMaterial = material1;

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x
            transform.Children.Add(new TranslateTransform3D(-halfLength + halfCap, 0, 0));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(6, rings, false, true, transform);

            geometries.Children.Add(geometry);

            // Cap 2
            geometry = new GeometryModel3D();

            geometry.Material     = material1;
            geometry.BackMaterial = material1;

            transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));      // the tube builds along z, but this class wants along x
            transform.Children.Add(new TranslateTransform3D(halfLength - halfCap, 0, 0));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(6, rings, false, true, transform);

            geometries.Children.Add(geometry);

            #endregion

            #region shaft

            geometry = new GeometryModel3D();

            geometry.Material     = material2;
            geometry.BackMaterial = material2;

            rings = new List <TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, dna.Radius * .8, dna.Radius * .8, true));
            rings.Add(new TubeRingRegularPolygon(dna.Length - capHeight, false, dna.Radius * .8, dna.Radius * .8, true));

            transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 45)));      // make the bar impact along the edge instead of the flat part

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(4, rings, false, true, transform);

            geometries.Children.Add(geometry);

            #endregion
        }
        //TODO: random chance of randomly placing metal fittings on the handle
        private static void GetModel_Rod_Wood(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            const double PERCENT = 1;

            Random rand = StaticRandom.GetRandomForThread();
            var from = dna.KeyValues;
            var to = finalDNA.KeyValues;

            GeometryModel3D geometry = new GeometryModel3D();

            #region Material

            switch (dna.HandleMaterial)
            {
                case WeaponHandleMaterial.Soft_Wood:
                    geometry.Material = materials.Handle_SoftWood;
                    break;

                case WeaponHandleMaterial.Hard_Wood:
                    geometry.Material = materials.Handle_HardWood;
                    break;

                default:
                    throw new ApplicationException("Unexpected WeaponHandleMaterial: " + dna.HandleMaterial.ToString());
            }

            geometry.BackMaterial = geometry.Material;

            #endregion

            #region Tube

            double maxX1 = WeaponDNA.GetKeyValue("maxX1", from, to, rand.NextDouble(.45, .7));
            double maxX2 = WeaponDNA.GetKeyValue("maxX2", from, to, rand.NextDouble(.45, .7));

            double maxY1 = WeaponDNA.GetKeyValue("maxY1", from, to, rand.NextDouble(.85, 1.05));
            double maxY2 = WeaponDNA.GetKeyValue("maxY2", from, to, rand.NextDouble(.85, 1.05));

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, maxX1 * .45, maxY1 * .75, true));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring1", from, to, rand.NextPercent(.5, PERCENT)), false, maxX1 * .5, maxY1 * 1, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring2", from, to, rand.NextPercent(2, PERCENT)), false, maxX1 * .4, maxY1 * .8, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring3", from, to, rand.NextPercent(5, PERCENT)), false, Math1D.Avg(maxX1, maxX2) * .35, Math1D.Avg(maxY1, maxY2) * .75, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring4", from, to, rand.NextPercent(5, PERCENT)), false, maxX2 * .4, maxY2 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring5", from, to, rand.NextPercent(2, PERCENT)), false, maxX2 * .5, maxY2 * 1, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("ring6", from, to, rand.NextPercent(.5, PERCENT)), false, maxX2 * .45, maxY2 * .75, true));

            rings = TubeRingBase.FitNewSize(rings, dna.Radius * Math.Max(maxX1, maxX2), dna.Radius * Math.Max(maxY1, maxY2), dna.Length);        // multiplying x by maxX, because the rings were defined with x maxing at maxX, and y maxing at 1

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(10, rings, true, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x

            #endregion

            geometries.Children.Add(geometry);
        }
Beispiel #16
0
        private static void GetModel_Rod_Composite(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            Random rand = StaticRandom.GetRandomForThread();

            finalDNA.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Composite(dna.MaterialsForCustomizable);
            var from = dna.KeyValues;
            var to   = finalDNA.KeyValues;

            double halfLength        = dna.Length / 2d;
            double halfBeamThickness = dna.Radius / 8d;
            double halfCoreThickness = (dna.Radius * .66d) / 2d;
            double washerRadius      = dna.Radius * 1.1;

            double washerThickness1 = WeaponDNA.GetKeyValue("washerThickness1", from, to, dna.Length * rand.NextPercent(.015d, .5d));
            double washerThickness2 = WeaponDNA.GetKeyValue("washerThickness2", from, to, dna.Length * rand.NextPercent(.15d, .5d));
            double washerOffset     = WeaponDNA.GetKeyValue("washerOffset", from, to, rand.NextPercent(.05d, .5d));

            var material = GetModel_Rod_Composite_Material(finalDNA.MaterialsForCustomizable[0]);

            //NOTE: The beam/core dimensions shouldn't be randomized.  This should look like a manufactured, almost mass produced product
            #region beams

            // Beam1
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -dna.Radius, -halfBeamThickness), new Point3D(halfLength, dna.Radius, halfBeamThickness));

            geometries.Children.Add(geometry);

            // Beam2
            geometry = new GeometryModel3D();

            geometry.Material     = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -halfBeamThickness, -dna.Radius), new Point3D(halfLength, halfBeamThickness, dna.Radius));

            geometries.Children.Add(geometry);

            #endregion
            #region core

            material = GetModel_Rod_Composite_Material(finalDNA.MaterialsForCustomizable[1]);

            geometry = new GeometryModel3D();

            geometry.Material     = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -halfCoreThickness, -halfCoreThickness), new Point3D(halfLength, halfCoreThickness, halfCoreThickness));

            geometry.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 45));

            geometries.Children.Add(geometry);

            #endregion
            #region washers

            material = GetModel_Rod_Composite_Material(finalDNA.MaterialsForCustomizable[2]);

            var locations = new Tuple <double, double>[]
            {
                Tuple.Create(0d, washerThickness1),
                Tuple.Create(washerOffset, washerThickness1),
                Tuple.Create(.5d, washerThickness2),
                Tuple.Create(1d - washerOffset, washerThickness1),
                Tuple.Create(1d, washerThickness1)
            };

            foreach (var loc in locations)
            {
                geometry = new GeometryModel3D();

                geometry.Material     = material;
                geometry.BackMaterial = material;

                geometry.Geometry = UtilityWPF.GetCylinder_AlongX(8, washerRadius, loc.Item2);

                geometry.Transform = new TranslateTransform3D(-halfLength + (dna.Length * loc.Item1), 0, 0);

                geometries.Children.Add(geometry);
            }

            #endregion
        }
Beispiel #17
0
        /// <summary>
        /// This returns a random ball that will fit well with the handle passed in
        /// </summary>
        public static WeaponSpikeBallDNA GetRandomDNA(WeaponHandleDNA handle)
        {
            WeaponSpikeBallDNA retVal = new WeaponSpikeBallDNA();

            Random rand = StaticRandom.GetRandomForThread();

            // Radius
            retVal.Radius = GetRandomRadius(handle.Radius, handle.Length);

            #region Material

            // Choose a ball material that goes with the handle's material
            //NOTE: This is assuming that the ball is an appropriate radius for the handle it will be attached to.
            //A large soft wood could safely handle a very small ball, etc

            WeaponSpikeBallMaterial[] ballMaterials = null;

            switch (handle.HandleMaterial)
            {
            case WeaponHandleMaterial.Soft_Wood:
                ballMaterials = new[] { WeaponSpikeBallMaterial.Wood, WeaponSpikeBallMaterial.Composite };
                break;

            case WeaponHandleMaterial.Hard_Wood:
                ballMaterials = new[] { WeaponSpikeBallMaterial.Wood, WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Composite, WeaponSpikeBallMaterial.Klinth };
                break;

            case WeaponHandleMaterial.Bronze:
            case WeaponHandleMaterial.Iron:
            case WeaponHandleMaterial.Steel:
                ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Moon };
                break;

            case WeaponHandleMaterial.Composite:
                ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Composite, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon };
                break;

            case WeaponHandleMaterial.Klinth:
                ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon };
                break;

            case WeaponHandleMaterial.Moon:
                ballMaterials = new[] { WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon };
                break;

            default:
                throw new ApplicationException("Unknown WeaponHandleMaterial: " + handle.HandleMaterial.ToString());
            }

            // Choose one from the filtered list
            retVal.Material = rand.NextItem(ballMaterials);

            #endregion

            #region Color

            ColorHSV?basedOn = null;
            if (handle.MaterialsForCustomizable != null && handle.MaterialsForCustomizable.Length > 0 && !string.IsNullOrEmpty(handle.MaterialsForCustomizable[0].DiffuseColor))
            {
                basedOn = UtilityWPF.ColorFromHex(handle.MaterialsForCustomizable[0].DiffuseColor).ToHSV();
            }

            switch (retVal.Material)
            {
            case WeaponSpikeBallMaterial.Composite:
                retVal.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Composite(null, basedOn);
                break;

            case WeaponSpikeBallMaterial.Klinth:
                retVal.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Klinth(null, basedOn);
                break;
            }

            #endregion

            return(retVal);
        }
Beispiel #18
0
        public static WeaponHandleDNA GetRandomDNA(WeaponHandleMaterial?material = null, WeaponHandleType?type = null, bool?isDouble = null, double?length = null, double?radius = null)
        {
            const double DOUBLE_END    = .2d;
            const double DOUBLE_CENTER = .05d;       // this is only half of the center

            WeaponHandleDNA retVal = new WeaponHandleDNA();

            Random rand = StaticRandom.GetRandomForThread();

            bool isDoubleActual = isDouble ?? (rand.Next(2) == 0);

            #region Material

            if (material == null)
            {
                retVal.HandleMaterial = UtilityCore.GetRandomEnum <WeaponHandleMaterial>();
            }
            else
            {
                retVal.HandleMaterial = material.Value;
            }

            #endregion

            //TODO: Support rope
            retVal.HandleType = WeaponHandleType.Rod;

            #region Length

            if (length == null)
            {
                //double lengthActual = rand.NextDouble(1.5d, 3.5d);
                double lengthActual = rand.NextDouble(1.5d, 2.8d);
                if (isDoubleActual)
                {
                    lengthActual *= 2d;
                }

                retVal.Length = lengthActual;
            }
            else
            {
                retVal.Length = length.Value;
            }

            #endregion
            #region Radius

            if (radius == null)
            {
                //double radiusActual = rand.NextDouble(.03d, .17d);
                double radiusActual = rand.NextDouble(.03d, .12d);
                if (isDoubleActual)
                {
                    radiusActual *= 2d;
                }

                retVal.Radius = radiusActual;
            }
            else
            {
                retVal.Radius = radius.Value;
            }

            #endregion
            #region AttachPoint

            if (isDoubleActual)
            {
                // Since the center of mass is in the middle, the attach point can't be in the middle.
                // Both ends are out as well.
                // So, choose one of the areas that are stars
                //  |----|********|--------|********|----|

                double randMaxValue = .5d - DOUBLE_END - DOUBLE_CENTER;
                double randValue    = rand.NextDouble(randMaxValue);
                double half         = DOUBLE_CENTER + randValue;

                if (rand.NextBool())
                {
                    // left side
                    retVal.AttachPointPercent = .5d - half;
                }
                else
                {
                    // right side
                    retVal.AttachPointPercent = .5d + half;
                }
            }
            else
            {
                // Choose one of the ends
                retVal.AttachPointPercent = rand.NextBool() ? 0d : 1d;
            }

            #endregion

            #region Color

            switch (retVal.HandleMaterial)
            {
            case WeaponHandleMaterial.Composite:
                retVal.MaterialsForCustomizable = GetRandomMaterials_Composite();
                break;

            case WeaponHandleMaterial.Klinth:
                retVal.MaterialsForCustomizable = GetRandomMaterials_Klinth();
                break;
            }

            #endregion

            return(retVal);
        }
Beispiel #19
0
        private static void GetModel_Rod_Moon(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            const double PERCENT = 1;

            Random rand = StaticRandom.GetRandomForThread();
            var    from = dna.KeyValues;
            var    to   = finalDNA.KeyValues;

            #region shaft

            GeometryModel3D shaft = new GeometryModel3D();

            shaft.Material     = materials.Handle_Moon;
            shaft.BackMaterial = shaft.Material;

            double maxRad1  = WeaponDNA.GetKeyValue("maxRad1", from, to, rand.NextDouble(.7, 1.02));
            double maxRad2  = WeaponDNA.GetKeyValue("maxRad2", from, to, rand.NextDouble(.7, 1.02));
            double maxRad12 = Math.Max(maxRad1, maxRad2);       // this is used in several places

            List <TubeRingBase> rings = new List <TubeRingBase>();

            rings.Add(new TubeRingRegularPolygon(0, false, maxRad1 * .4, maxRad1 * .4, true));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube1", from, to, rand.NextPercent(.25, PERCENT)), false, maxRad1 * .8, maxRad1 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube2", from, to, rand.NextPercent(.3, PERCENT)), false, maxRad1 * .85, maxRad1 * .85, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube3", from, to, rand.NextPercent(.75, PERCENT)), false, maxRad1 * .6, maxRad1 * .6, false));

            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube4", from, to, rand.NextPercent(20, PERCENT)), false, maxRad2 * .8, maxRad2 * .8, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube5", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * .9, maxRad2 * .9, false));
            rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube6", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * 1, maxRad2 * 1, false));
            rings.Add(new TubeRingDome(WeaponDNA.GetKeyValue("tube7", from, to, rand.NextPercent(2.5, PERCENT)), false, 4));

            rings = TubeRingBase.FitNewSize(rings, maxRad12 * dna.Radius, maxRad12 * dna.Radius, dna.Length);

            shaft.Geometry = UtilityWPF.GetMultiRingedTube(10, rings, true, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));      // the tube builds along z, but this class wants along x

            #endregion

            // Number of gems
            int numIfNew = 0;
            if (rand.NextDouble() > .66d)       // only 33% will get gems
            {
                // Of the handles with gems, only 5% will get 2
                numIfNew = rand.NextDouble() > .95 ? 2 : 1;
            }

            int numGems = Convert.ToInt32(WeaponDNA.GetKeyValue("numGems", from, to, numIfNew));

            if (numGems == 0)
            {
                geometries.Children.Add(shaft);
                return;
            }

            #region gems

            List <double> percents = new List <double>();

            for (int cntr = 0; cntr < numGems; cntr++)
            {
                string keyPrefix = "gem" + cntr.ToString();

                // Get a placement for this gem
                double percentIfNew = 0;
                do
                {
                    percentIfNew = rand.NextDouble(.15, .85);

                    if (percents.Count == 0)
                    {
                        break;
                    }
                } while (percents.Any(o => Math.Abs(percentIfNew - o) < .15));

                double percent = WeaponDNA.GetKeyValue(keyPrefix + "Percent", from, to, percentIfNew);

                percents.Add(percent);

                // Gem
                GeometryModel3D gem = new GeometryModel3D();

                gem.Material     = materials.Handle_MoonGem;
                gem.BackMaterial = gem.Material;

                double width = WeaponDNA.GetKeyValue(keyPrefix + "Width", from, to, rand.NextDouble(maxRad12 * 1d, maxRad12 * 1.4d));

                gem.Geometry = UtilityWPF.GetSphere_LatLon(5, dna.Radius * width);
                Point3D position = new Point3D((dna.Length * percent) - (dna.Length / 2d), 0, 0);
                gem.Transform = new TranslateTransform3D(position.ToVector());

                // Light
                PointLight pointLight = new PointLight(materials.Handle_MoonGemLight, position);
                UtilityWPF.SetAttenuation(pointLight, dna.Radius * 120d, .1d);

                geometries.Children.Add(pointLight);
                geometries.Children.Add(gem);
            }

            // Adding this after so that you don't see the shaft through the gems
            geometries.Children.Add(shaft);

            #endregion
        }
        /// <summary>
        /// This returns a random ball that will fit well with the handle passed in
        /// </summary>
        public static WeaponSpikeBallDNA GetRandomDNA(WeaponHandleDNA handle)
        {
            WeaponSpikeBallDNA retVal = new WeaponSpikeBallDNA();

            Random rand = StaticRandom.GetRandomForThread();

            // Radius
            retVal.Radius = GetRandomRadius(handle.Radius, handle.Length);

            #region Material

            // Choose a ball material that goes with the handle's material
            //NOTE: This is assuming that the ball is an appropriate radius for the handle it will be attached to.
            //A large soft wood could safely handle a very small ball, etc

            WeaponSpikeBallMaterial[] ballMaterials = null;

            switch (handle.HandleMaterial)
            {
                case WeaponHandleMaterial.Soft_Wood:
                    ballMaterials = new[] { WeaponSpikeBallMaterial.Wood, WeaponSpikeBallMaterial.Composite };
                    break;

                case WeaponHandleMaterial.Hard_Wood:
                    ballMaterials = new[] { WeaponSpikeBallMaterial.Wood, WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Composite, WeaponSpikeBallMaterial.Klinth };
                    break;

                case WeaponHandleMaterial.Bronze:
                case WeaponHandleMaterial.Iron:
                case WeaponHandleMaterial.Steel:
                    ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Moon };
                    break;

                case WeaponHandleMaterial.Composite:
                    ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Composite, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon };
                    break;

                case WeaponHandleMaterial.Klinth:
                    ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon };
                    break;

                case WeaponHandleMaterial.Moon:
                    ballMaterials = new[] { WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon };
                    break;

                default:
                    throw new ApplicationException("Unknown WeaponHandleMaterial: " + handle.HandleMaterial.ToString());
            }

            // Choose one from the filtered list
            retVal.Material = rand.NextItem(ballMaterials);

            #endregion

            #region Color

            ColorHSV? basedOn = null;
            if (handle.MaterialsForCustomizable != null && handle.MaterialsForCustomizable.Length > 0 && !string.IsNullOrEmpty(handle.MaterialsForCustomizable[0].DiffuseColor))
            {
                basedOn = UtilityWPF.ColorFromHex(handle.MaterialsForCustomizable[0].DiffuseColor).ToHSV();
            }

            switch (retVal.Material)
            {
                case WeaponSpikeBallMaterial.Composite:
                    retVal.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Composite(null, basedOn);
                    break;

                case WeaponSpikeBallMaterial.Klinth:
                    retVal.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Klinth(null, basedOn);
                    break;
            }

            #endregion

            return retVal;
        }
Beispiel #21
0
        public static (BotDNA bot, WeaponDNA weapon) GetRandomDNA(ItemOptionsArco itemOptions, BotShellColorsDNA shellColors = null, WeaponDNA weapon = null)
        {
            Random rand = StaticRandom.GetRandomForThread();

            BotDNA bot = new BotDNA()
            {
                UniqueID            = Guid.NewGuid(),
                Lineage             = Guid.NewGuid().ToString(),
                Generation          = 0,
                DraggingMaxVelocity = rand.NextPercent(5, .25),
                DraggingMultiplier  = rand.NextPercent(20, .25),
            };

            #region Parts

            List <ShipPartDNA> parts = new List <ShipPartDNA>();

            double partSize;

            // Homing
            partSize = rand.NextPercent(1, .5);
            parts.Add(new ShipPartDNA()
            {
                PartType = SensorHoming.PARTTYPE, Position = new Point3D(0, 0, 2.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize)
            });

            // Vision
            //TODO: Support filtering by type
            partSize = rand.NextPercent(1, .5);
            parts.Add(new SensorVisionDNA()
            {
                PartType = SensorVision.PARTTYPE, Position = new Point3D(0, 0, 1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize), SearchRadius = itemOptions.VisionSensor_SearchRadius
            });

            // Brains
            int numBrains = 1 + Convert.ToInt32(rand.NextPow(5, 1d) * 4);

            for (int cntr = 0; cntr < numBrains; cntr++)
            {
                partSize = rand.NextPercent(1, .5);

                Point3D position = new Point3D(0, 0, 0);
                if (numBrains > 1)
                {
                    position = Math3D.GetRandomVector_Circular(1).ToPoint();
                }

                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Position = position, Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize)
                });
            }

            // MotionController - always exactly one of these
            partSize = rand.NextPercent(1, .5);
            parts.Add(new ShipPartDNA()
            {
                PartType = MotionController2.PARTTYPE, Position = new Point3D(0, 0, -1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize)
            });

            // Store it
            bot.Parts = parts.ToArray();

            #endregion

            if (shellColors == null)
            {
                bot.ShellColors = BotShellColorsDNA.GetRandomColors();
            }
            else
            {
                bot.ShellColors = shellColors;
            }

            #region Weapon

            WeaponDNA weaponActual = null;
            if (weapon == null)
            {
                if (rand.NextDouble() < .95d)
                {
                    WeaponHandleMaterial[] weaponMaterials = new WeaponHandleMaterial[] { WeaponHandleMaterial.Soft_Wood, WeaponHandleMaterial.Hard_Wood };

                    weaponActual = new WeaponDNA()
                    {
                        UniqueID = Guid.NewGuid(),
                        Handle   = WeaponHandleDNA.GetRandomDNA(weaponMaterials[StaticRandom.Next(weaponMaterials.Length)])
                    };
                }
            }
            else
            {
                weaponActual = weapon;
            }

            #endregion

            return(bot, weaponActual);
        }