Example #1
0
        public static void GenerateCoarseComponent(ref float[,] map, int chunkX, int chunkY)
        {
            var height = map.GetLength(0);
            var width  = map.GetLength(1);

            Noise2D.Turbulence(
                ref map,
                chunkX * (height - 1),
                chunkY * (width - 1),
                3,
                0.5f,
                0.01f,
                Noise2D.Perlin);

            var ridges = new float[height, width];

            Noise2D.Turbulence(
                ref ridges,
                chunkX * (height - 1),
                chunkY * (width - 1),
                8,
                0.5f,
                0.12f,
                Noise2D.RidgedBillowedPerlin);
            Transformation2D.Combine(ref map, 50f, ridges, 5f);
        }
        public void Scene_FluentBuildTransformations_ShouldAdded()
        {
            var rotationCenterX = 10.0;
            var rotationCenterY = 15.0;
            var rotationAngle   = Math.PI / 2;

            var shapes1 = CreateShapes();
            var shapes2 = CreateShapes();

            //Old syntax: method to method
            var translation1   = new Translation2D(rotationCenterX, rotationCenterY);
            var rotation       = new Rotation2D(rotationAngle);
            var translation2   = new Translation2D(-rotationCenterX, -rotationCenterY);
            var transformation = Transformation2D.Compose(translation1, rotation, translation2);

            for (int i = 0; i < shapes1.Count; i++)
            {
                shapes1[i].Apply(transformation);
                shapes1[i].DoTransform();
            }

            //New syntax: fluent builder
            shapes2.Translate(rotationCenterX, rotationCenterY).Rotate(rotationAngle).Translate(-rotationCenterX, -rotationCenterY).DoTransform();

            shapes1.Shapes.Should().BeEquivalentTo(shapes2.Shapes);
        }
Example #3
0
        private void Update(float updatePeriod)
        {
            var t = new Transformation2D();

            t.RotateLocal(-200f * updatePeriod);
            bird.TransformCenter(t);
        }
Example #4
0
        protected override Bounds2D GetBounds(string text, Matrix2D transformation, Enum24 wsh)
        {
            Bounds2D bounds2D = new Bounds2D();

            using (GraphicsPath graphicsPath = this.method_1(text))
            {
                if (graphicsPath.PointCount > 1)
                {
                    RectangleF bounds = graphicsPath.GetBounds((transformation * Transformation2D.Scaling(this.CanonicalScaling)).ToMatrix());
                    bounds2D.Update(new Point2D((double)bounds.Left, (double)bounds.Bottom));
                    bounds2D.Update(new Point2D((double)bounds.Right, (double)bounds.Top));
                }
            }
            if (text.Length > 0)
            {
                if ((wsh & Enum24.flag_1) != Enum24.flag_0 && char.IsWhiteSpace(text[0]))
                {
                    bounds2D.Update(0.0, 0.0);
                }
                if ((wsh & Enum24.flag_2) != Enum24.flag_0 && char.IsWhiteSpace(text[text.Length - 1]))
                {
                    Vector2D vector2D = this.imethod_0(text, (IList <Vector2D>)null);
                    bounds2D.Update(vector2D.X, vector2D.Y);
                }
            }
            return(bounds2D);
        }
Example #5
0
        public static void GenerateShelf(ref float[,] map, int chunkX, int chunkY)
        {
            var height = map.GetLength(0);
            var width  = map.GetLength(1);

            TerrainComponents.GenerateSmoothComponent(ref map, chunkX, chunkY);

            var coarseShelf = new float[height, width];

            TerrainComponents.GenerateCoarseComponent(ref coarseShelf, chunkX, chunkY);

            var coarseMap = new float[height, width];

            Noise2D.Uniform(
                ref coarseMap,
                chunkX * (height - 1),
                chunkY * (width - 1),
                0.005f,
                1f,
                Noise2D.Perlin);
            Transformation2D.Exponent(ref coarseMap, 1.1f);
            Transformation2D.ClampLower(ref coarseMap, 0f);
            Transformation2D.Mutlipy(ref coarseShelf, coarseMap);

            Transformation2D.Combine(ref map, 1f, coarseShelf, 5f);
        }
Example #6
0
        public void ScaleAroundTest()
        {
            var a         = new Vector2(1, 1);
            var t         = Transformation2D.CreateScaleAround(-1, -1, 2, 3);
            var expectedA = new Vector2(3, 5);

            Assert.AreEqual(expectedA, t.Transform(a));
        }
Example #7
0
        public void RotateAroundTest()
        {
            var a         = Vector2.Zero;
            var t         = Transformation2D.CreateRotationAround(-1, -1, 90f);
            var expectedA = -2 * Vector2.UnitX;

            Assert.AreEqual(expectedA, t.Transform(a));
        }
Example #8
0
        public void RotateAroundOriginTestIdentity2()
        {
            var t = new Transformation2D();

            t.RotateLocal(0f);
            var expectedM = Matrix3x2.Identity;

            Assert.AreEqual(expectedM, t);
        }
Example #9
0
        private void Update(float updatePeriod)
        {
            rotCenter.X += updatePeriod * 0.1f;
            var t = Transformation2D.CreateRotationAround(rotCenter.X, rotCenter.Y, updatePeriod * 200f);

            foreach (var bird in birds)
            {
                bird.TransformCenter(t);
            }
        }
Example #10
0
        public void RotateAroundOriginTest90()
        {
            var a = Vector2.UnitX;
            var t = new Transformation2D();

            t.RotateLocal(90f);
            var expectedA = Vector2.UnitY;

            Assert.AreEqual(expectedA, t.Transform(a));
        }
Example #11
0
        public void ScaleAroundOriginTest()
        {
            var a = new Vector2(-3, 2);
            var t = new Transformation2D();

            t.ScaleLocal(2, -3);
            var expectedA = new Vector2(-6, -6);

            Assert.AreEqual(expectedA, t.Transform(a));
        }
        protected Matrix <Vector2D> ComposeTransformations()
        {
            if (Transformations.Count == 0)
            {
                return(Transformation2D.Identity(3) as Transformation2D);
            }

            var transformation = Transformations[0];

            for (int t = 1; t < Transformations.Count; t++)
            {
                transformation = transformation * Transformations[t];
            }

            return(transformation);
        }
Example #13
0
        public static GameObject GenerateChunk(int chunkX, int chunkY, int chunkSize)
        {
            var map = new float[chunkSize, chunkSize];

//            ContinentalShelf.GenerateShelf(ref map, chunkX, chunkY);
            Coast.GenerateCoast(ref map, chunkX, chunkY);
            Transformation2D.Translate(ref map, 1f);
            Transformation2D.Scale(ref map, 0.5f);

            var terrainData = new TerrainData();

            terrainData.SetHeights(0, 0, map);
            terrainData.size = new Vector3(chunkSize, 300f, chunkSize);
            var chunk = Terrain.CreateTerrainGameObject(terrainData);

            chunk.transform.position = new Vector3(chunkX * (chunkSize - 1), 0, chunkY * (chunkSize - 1));
            chunk.GetComponent <Terrain>().Flush();

            return(chunk);
        }
Example #14
0
        public static Point[] ApplyTransformation(Transformation2D trans, Point center, Point[] pts)
        {
            // setup
            if (pts == null || pts.Length < 1)
            {
                return(null);
            }
            var res = new Point[pts.Length];

            // 1 for 1
            for (int i = 0; i < pts.Length; i++)
            {
                // around center ..
                var x = pts[i].X - center.X;
                var y = pts[i].Y - center.Y;

                // scale
                x = x * trans.Scale;
                y = y * trans.Scale;

                // rotate (mathematically positive!)
                var    radian   = -trans.Rot * (Math.PI / 180);
                double cosTheta = Math.Cos(radian);
                double sinTheta = Math.Sin(radian);
                var    nx       = cosTheta * x - sinTheta * y;
                var    ny       = sinTheta * x + cosTheta * y;

                // move
                nx += trans.OfsX;
                ny += trans.OfsY;

                // store
                res[i] = new Point(nx, ny);
            }

            // ok
            return(res);
        }
Example #15
0
        public static Transformation2D FindBestFitForFieldOfPoints(
            Point[] pts, Point[] field,
            Transformation2D start,
            double rangeScale, double rangeRot, double rangeXY,
            int steps, int iterations)
        {
            // setup
            if (pts == null || field == null || pts.Length < 1 || field.Length < 1 || start == null || iterations < 0)
            {
                return(null);
            }

            // systematicall apply disturbances
            // on the hierarchy: scale, rot (in degrees), ofsX, ofsY

            var    bestTrans = start;
            double bestError = Double.MaxValue;
            var    be        = CumulatedErrorToFieldOfPoints(pts, field);

            if (be != null)
            {
                bestError = be.Value;
            }

            var center = ComputeCOG(pts);

            if (center == null)
            {
                return(null);
            }

            for (int iScale = 0; iScale <= steps; iScale++)
            {
                for (int iRot = 0; iRot <= steps; iRot++)
                {
                    for (int iY = 0; iY <= steps; iY++)
                    {
                        for (int iX = 0; iX <= steps; iX++)
                        {
                            // current point
                            var currTrans = new Transformation2D(
                                start.Scale - rangeScale + (2 * rangeScale * iScale / steps),
                                start.Rot - rangeRot + (2 * rangeRot * iRot / steps),
                                start.OfsX - rangeXY + (2 * rangeXY * iX / steps),
                                start.OfsY - rangeXY + (2 * rangeXY * iY / steps));

                            // some parts of the vectorroom are "taboo"
                            if (currTrans.Scale <= 0.000)
                            {
                                continue;
                            }

                            // transform
                            var currPts = ApplyTransformation(currTrans, center.Value, pts);

                            // evaluate
                            var error = CumulatedErrorToFieldOfPoints(currPts, field);
                            if (error != null && error.Value < bestError)
                            {
                                bestError = error.Value;
                                bestTrans = currTrans;
                            }
                        }
                    }
                }
            }

            // go into "recursion"
            var rm = 1.0 / steps;
            // ReSharper disable once UnusedVariable
            var betterTrans = FindBestFitForFieldOfPoints(pts, field, bestTrans,
                                                          rm * rangeScale, rm * rangeRot, rm * rangeXY, steps, iterations - 1);

            // result
            return(bestTrans);
        }
Example #16
0
 public static void GenerateCoast(ref float[,] map, int chunkX, int chunkY)
 {
     TerrainComponents.GenerateSmoothComponent(ref map, chunkX, chunkY);
     Transformation2D.Scale(ref map, 1 / 10f);
 }
Example #17
0
            public Class866 method_0(char c)
            {
                Class866 class866;

                lock (this.dictionary_0)
                {
                    if (!this.dictionary_0.TryGetValue(c, out class866))
                    {
                        using (GraphicsPath path1 = new GraphicsPath())
                        {
                            StringFormat format = new StringFormat(StringFormat.GenericTypographic);
                            format.FormatFlags |= StringFormatFlags.NoWrap;
                            format.FormatFlags &= ~StringFormatFlags.NoFontFallback;
                            path1.AddString(c.ToString(), this.Font.FontFamily, (int)this.Font.Style, 144f, this.pointF_0, format);
                            IShape2D wrappedShape = (IShape2D)GeneralShape2D.Create(path1, Transformation2D.Scaling(this.double_0));
                            IShape2D path2        = wrappedShape.HasSegments ? (IShape2D) new CachedBoundsShape2D(wrappedShape) : (IShape2D)NullShape2D.Instance;
                            class866 = new Class866(c, path2, Vector2D.Zero, true);
                            format.Dispose();
                        }
                        this.dictionary_0.Add(c, class866);
                    }
                }
                return(class866);
            }
Example #18
0
        public Interface34 GetText(
            string text,
            WW.Cad.Model.Color color,
            short lineWeight,
            bool vertical)
        {
            GeneralShape2D generalShape2D;

            using (GraphicsPath graphicsPath = this.class26_0.method_1(text))
                generalShape2D = (GeneralShape2D)graphicsPath;
            generalShape2D.FillMode = WW.Math.Geometry.FillMode.Winding;
            IShape2D path = generalShape2D.HasSegments ? (IShape2D) new CachedBoundsShape2D((IShape2D)generalShape2D) : (IShape2D)NullShape2D.Instance;

            return((Interface34) new Class865(text, (Interface14)this, color, lineWeight, path, this.class26_0.CharTransformation, Transformation2D.Scaling(this.class26_0.CanonicalScaling), this.class26_0.imethod_0(text, (IList <Vector2D>)null)));
        }