Ejemplo n.º 1
0
        /// <summary>
        /// Draw the space
        /// </summary>
        private void RenderGrid()
        {
            fLines = new DynamicPrimitiveLine(GraphicsDevice);

            float worldFactor = WORLD_SIZE / (WORLD_BLOCKS - 1);
            VertexPositionColor p1;
            VertexPositionColor p2;

            for (int x = 0; x < WORLD_BLOCKS; x++)
            {
                float sx1 = (x + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                for (int y = 0; y < WORLD_BLOCKS; y++)
                {
                    float sy1 = (y + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                    for (int z = 0; z < WORLD_BLOCKS; z++)
                    {
                        float sz1 = (z + 0.5f) * worldFactor - HALF_WORLD_SIZE;

                        float   dx    = 1024 * (fSpace[x, y, z].ForcePositiveX - fSpace[x, y, z].ForceNegativeX);
                        float   dy    = 1024 * (fSpace[x, y, z].ForcePositiveY - fSpace[x, y, z].ForceNegativeY);
                        float   dz    = 1024 * (fSpace[x, y, z].ForcePositiveZ - fSpace[x, y, z].ForceNegativeZ);
                        Vector3 d     = new Vector3(dx, dy, dz);
                        float   power = d.Length() / 1000000;
                        if (power > 0)
                        {
                            d.Normalize();
                            if (power > 200)
                            {
                                power = 200;
                            }

                            dx = d.X * power;
                            dy = d.Y * power;
                            dz = d.Z * power;

                            float sx2 = sx1 + dx;
                            float sy2 = sy1 + dy;
                            float sz2 = sz1 + dz;
                            int   r   = (int)(255f * Math.Abs(d.X));
                            int   g   = (int)(255f * Math.Abs(d.Y));
                            int   b   = (int)(255f * Math.Abs(d.Z));
                            Color c1  = new Color(r, g, b);
                            Color c2  = Color.Transparent;
                            p1 = new VertexPositionColor(new Vector3(sx1, sy1, sz1), c1);
                            p2 = new VertexPositionColor(new Vector3(sx2, sy2, sz2), c2);
                            fLines.AddLine(p1, p2);
                        }
                    }
                }
            }
            fBasicEffect.World      = fCamera.Camera.WorldMatrix;
            fBasicEffect.View       = fCamera.Camera.ViewMatrix;
            fBasicEffect.Projection = fCamera.Camera.ProjectionMatrix;
            foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                fLines.Render();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes the lines
 /// </summary>
 private void InitializeLines()
 {
     fLines = new DynamicPrimitiveLine(GraphicsDevice);
     for (int i = 0; i < 256; i++)
     {
         fLines.AddCircle(TARGET_WIDTH / 2, TARGET_HEIGHT / 2, 0, i / 5.0f, 50, new Color(i, 255 - i, 255 - i, 255));
     }
     for (int i = 0; i < 5; i++)
     {
         Color color = new Color(255 - i * 25, 0, 0, 255);
         fLines.AddLine(
             new VertexPositionColor(new Vector3(i, i, 0), color),
             new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, i, 0), color));
         fLines.AddLine(
             new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, i, 0), color),
             new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, TARGET_HEIGHT - i - 1, 0), color));
         fLines.AddLine(
             new VertexPositionColor(new Vector3(TARGET_WIDTH - i - 1, TARGET_HEIGHT - i - 1, 0), color),
             new VertexPositionColor(new Vector3(i, TARGET_HEIGHT - i - 1, 0), color));
         fLines.AddLine(
             new VertexPositionColor(new Vector3(i, TARGET_HEIGHT - i - 1, 0), color),
             new VertexPositionColor(new Vector3(i, i, 0), color));
     }
 }
Ejemplo n.º 3
0
        private void AddTreeBranch(VertexPositionColor p1, int branches, double maxRadius, int maxLines)
        {
            double radius = fRandom.NextDouble() * maxRadius;

            if (radius > 4.0f && fLines.Lines < maxLines)
            {
                double maxInnerRadius = radius / 1.8f;
                for (int i = 0; i < branches; i++)
                {
                    VertexPositionColor p2 = GetRandomPoint(p1, radius);
                    p2.Color.A += 32;
                    fLines.AddLine(p1, p2);
                    AddTreeBranch(p2, branches, maxInnerRadius, maxLines);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draw the space
        /// </summary>
        private void RenderGrid()
        {
            fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice);
            float worldFactor = WORLD_SIZE / (WORLD_BLOCKS - 1);

            for (int x = 0; x < WORLD_BLOCKS; x++)
            {
                //int blockX = (int)((particle.Position.X + HALF_WORLD_SIZE) * PARTICLE_TO_WORLD);
                //int blockY = (int)((particle.Position.Y + HALF_WORLD_SIZE) * PARTICLE_TO_WORLD);
                float sx1 = (x + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                for (int y = 0; y < WORLD_BLOCKS; y++)
                {
                    float sy1 = (y + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                    float dx  = 1024 * 1024 * 1024 * (fSpace[x, y].ForceRight - fSpace[x, y].ForceLeft);
                    float dy  = 1024 * 1024 * 1024 * (fSpace[x, y].ForceUp - fSpace[x, y].ForceDown);
                    float f   = Convert.ToSingle(Math.Sqrt(dx * dx + dy * dy));
                    float f1  = f;
                    Color c1;
                    Color c2;
                    int   b1;
                    float size = 1.0f;
                    if (f1 < 1024.0f)
                    {
                        size = f1 / 1024.0f;
                        b1   = (byte)(f1 / 4.0f);
                        c1   = new Color(0, 0, b1, 255);
                        c2   = new Color(0, 0, b1, 255);
                    }
                    else
                    {
                        f1 /= 1024.0f;
                        if (f1 < 1024.0f)
                        {
                            size = 1.0f;// 0.5f + f1 / 512.0f;
                            b1   = (byte)(f1 / 4.0f);
                            c1   = new Color(0, b1, 255 - b1, 255);
                            c2   = new Color(0, 255, 0, 128);
                        }
                        else
                        {
                            f1 /= 1024.0f;
                            if (f1 < 1024.0f)
                            {
                                size = 1.0f;//0.5f + f1 / 512.0f;
                                b1   = (byte)(f1 / 4.0f);
                                c1   = new Color(b1, 255, 0, 255);
                                c2   = new Color(255, 255, 0, 128);
                            }
                            else
                            {
                                f1 /= 1024.0f;
                                if (f1 < 1024.0f)
                                {
                                    size = 1.0f;//0.5f + f1 / 512.0f;
                                    b1   = (byte)(f1 / 4.0f);
                                    c1   = new Color(255, 255 - b1, 0, 255);
                                    c2   = new Color(255, 0, 0, 128);
                                }
                                else
                                {
                                    size = 1.0f;
                                    c1   = new Color(255, 0, 255, 255);
                                    c2   = new Color(255, 0, 255, 255);
                                }
                            }
                        }
                    }

                    dx = MAX_LINE_SIZE * (dx / f) * size;
                    dy = MAX_LINE_SIZE * (dy / f) * size;
                    float sx2 = sx1 + dx;
                    float sy2 = sy1 + dy;
                    VertexPositionColor p1 = new VertexPositionColor(new Vector3(sx1, sy1, 0), c1);
                    VertexPositionColor p2 = new VertexPositionColor(new Vector3(sx2, sy2, 0), c2);
                    fLines.AddLine(p1, p2);
                }
            }
            fBasicEffect.World      = fCamera.Camera.WorldMatrix;
            fBasicEffect.View       = fCamera.Camera.ViewMatrix;
            fBasicEffect.Projection = fCamera.Camera.ProjectionMatrix;


            foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                fLines.Render();
            }
        }
Ejemplo n.º 5
0
        private void UpdateRectangles(bool createNewRectangles)
        {
            if (fRectangles == null || createNewRectangles)
            {
                fRectangles = MyFactory.GetRandomRectangles();
                fAngle      = 0;
            }
            else
            {
                foreach (var rectangle in fRectangles)
                {
                    rectangle.Angle = fAngle;
                }
            }
            int numberOfPoints = 4 * fRectangles.Count;

            MyPoint[] points     = new MyPoint[numberOfPoints];
            int       pointIndex = 0;

            foreach (var rectangle in fRectangles)
            {
                var corners = rectangle.CalculateCorners();
                points[pointIndex++] = corners[0];
                points[pointIndex++] = corners[1];
                points[pointIndex++] = corners[2];
                points[pointIndex++] = corners[3];
            }
            var polygon = CalculateConvexPolygon(points);

            if (fLines == null)
            {
                fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice);
                fLines.UseVertexBuffer = false;
            }
            else
            {
                fLines.Clear();
            }
            double boardArea = 0;

            foreach (var rectangle in fRectangles)
            {
                var corners = rectangle.CalculateCorners();
                fLines.AddLine(ToVertexPositionColor(corners[0], Color.White), ToVertexPositionColor(corners[1], Color.White));
                fLines.AddLine(ToVertexPositionColor(corners[1], Color.White), ToVertexPositionColor(corners[2], Color.White));
                fLines.AddLine(ToVertexPositionColor(corners[2], Color.White), ToVertexPositionColor(corners[3], Color.White));
                fLines.AddLine(ToVertexPositionColor(corners[3], Color.White), ToVertexPositionColor(corners[0], Color.White));
                boardArea += rectangle.Width * rectangle.Height;
            }

            double polyArea          = 0;
            int    numberOfPolyLines = polygon.Length;

            for (int i = 0; i < numberOfPolyLines; i++)
            {
                int     j  = (i + 1) % numberOfPolyLines;
                MyPoint p1 = polygon[i];
                MyPoint p2 = polygon[j];
                polyArea += MyPoint.Cross(p1, p2);
                fLines.AddLine(ToVertexPositionColor(p1, Color.Red), ToVertexPositionColor(p2, Color.Red));
            }
            polyArea = polyArea / 2;
            double ratio = 100.0 * boardArea / polyArea;
            //System.Console.WriteLine($"Area: {polyArea} PolyPoints: {numberOfPolyLines}, Ratio: {ratio:F1} %");
        }