Esempio n. 1
0
        public static void draw_rectangle(Vector2 p1, Vector2 p2, bool outline, double angle = 0)
        {
            Microsoft.Xna.Framework.Color fc = FinalizeColor(DrawColor);
            vertices.Clear();

            VertexPositionColor v0 = new VertexPositionColor(new Vector3((float)p1.X, (float)p1.Y, 0), fc);
            VertexPositionColor v1 = new VertexPositionColor(new Vector3((float)p1.X, (float)p2.Y, 0), fc);
            VertexPositionColor v2 = new VertexPositionColor(new Vector3((float)p2.X, (float)p1.Y, 0), fc);
            VertexPositionColor v3 = new VertexPositionColor(new Vector3((float)p2.X, (float)p2.Y, 0), fc);

            angle = ApplyEpsilon(angle);
            if (angle != 0)
            {
                Vector3 v = new Vector3(p1.X + (p2.X - p1.X) / 2, p1.Y + (p2.Y - p1.Y) / 2, 0);

                v0.Position = RotateVec3(v0.Position, v, angle);
                v1.Position = RotateVec3(v1.Position, v, angle);
                v2.Position = RotateVec3(v2.Position, v, angle);
                v3.Position = RotateVec3(v3.Position, v, angle);
            }

            if (!outline)
            {
                vertices.AddRange(new[] { v0, v1, v3, v0, v3, v2 });
                RenderVertices();
            }
            else
            {
                vertices.AddRange(new[] { v0, v1, v1, v3, v3, v2, v2, v0 });
                RenderVertices(PrimitiveType.LineList, true);
            }
        }
Esempio n. 2
0
        // todo
        public static void draw_ellipse(Vector2 pos, Vector2 exct, float theta)
        {
            Microsoft.Xna.Framework.Color fc = FinalizeColor(DrawColor);
            int vertexCount = 40;

            VertexPositionColor[] vertices = new VertexPositionColor[vertexCount];
            //Drawing an Ellipse with its major axis parallel to the x-axis. Rotation can be applied to change this.
            Vector3     position = Vector3.One;
            const float max      = MathHelper.Pi;
            //2 * max since we're moving from -Pi to +Pi in the loop.
            float step = 2 * max / (float)vertexCount;
            int   i    = 0;
            //Optional Axis and angle rotation for the ellipse (See later notes):
            //Vector3 axis = new Vector3(0, 0, -1);
            float angle = MathHelper.ToRadians(theta);

            for (float t = -max; t <= max; t += step)
            {
                //Formula shamelessly taken from wikipedia
                position = new Vector3(exct.X + pos.X * (float)Math.Cos((double)t), exct.Y + pos.Y * (float)Math.Sin((double)t), 0f);
                //Optional Rotation for the Ellipse:
                position    = Vector3.Transform(position, Matrix.CreateFromAxisAngle(new Vector3(0, 0, angle), angle));
                vertices[i] = new VertexPositionColor(position, fc);
                i++;
            }

            //Optional Rotation for the Ellipse:

            //then add the first vector again so it's a complete loop (sounds familiar)
            position = new Vector3(exct.X + pos.X * (float)Math.Cos((double)-max), exct.Y + pos.Y * (float)Math.Sin((double)-max), 0f);
            position = Vector3.Transform(position, Matrix.CreateFromAxisAngle(new Vector3(0, 0, angle), angle));
            vertices[vertexCount - 1] = new VertexPositionColor(position, fc);


            vb = new DynamicVertexBuffer(sb.GraphicsDevice, typeof(VertexPositionColor), vertices.Length,
                                         BufferUsage.WriteOnly);
            vb.SetData <VertexPositionColor>(vertices.ToArray());


            sb.GraphicsDevice.SetVertexBuffer(vb);

            RasterizerState rasterizerState = new RasterizerState();

            rasterizerState.CullMode             = CullMode.None;
            rasterizerState.MultiSampleAntiAlias = true;
            rasterizerState.FillMode             = FillMode.Solid;

            sb.GraphicsDevice.RasterizerState = rasterizerState;

            foreach (EffectPass pass in be.CurrentTechnique.Passes)
            {
                pass.Apply();
                sb.GraphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, 0, (vertices.Length - 1));
            }

            vb.Dispose();
            rasterizerState.Dispose();
        }
Esempio n. 3
0
        //
        public static void draw_circle(Vector2 pos, int r, bool outline, int startAngle = 0, int totalAngle = 360, int distance = 0)
        {
            r *= 2;
            Microsoft.Xna.Framework.Color fc = FinalizeColor(DrawColor);
            totalAngle += startAngle;

            if (outline)
            {
                distance = r - 4;
            }

            vertices.Clear();

            float xPos = pos.X;
            float yPos = pos.Y;

            float x1 = xPos;
            float y1 = yPos;

            float angle = 0;

            for (int i = startAngle; i <= totalAngle; i += 10)
            {
                angle = (i / 57.2961161551924f);

                float x2 = xPos + (((int)r / 2f) * (float)Math.Sin(angle));
                float y2 = yPos + (((int)r / 2f) * (float)Math.Cos(angle));

                float x3 = xPos + ((distance / 2f) * (float)Math.Sin(angle));
                float y3 = yPos + ((distance / 2f) * (float)Math.Cos(angle));

                if (distance == 0)
                {
                    vertices.Add(new VertexPositionColor(new Vector3(x3, y3, 0), fc));
                    vertices.Add(new VertexPositionColor(new Vector3(x1, y1, 0), fc));
                    vertices.Add(new VertexPositionColor(new Vector3(x2, y2, 0), fc));
                }
                else
                {
                    vertices.Add(new VertexPositionColor(new Vector3(x3, y3, 0), fc));
                    vertices.Add(new VertexPositionColor(new Vector3(x1, y1, 0), fc));
                    vertices.Add(new VertexPositionColor(new Vector3(x2, y2, 0), fc));
                    vertices.Add(new VertexPositionColor(new Vector3(x2, y2, 0), fc));
                    vertices.Add(new VertexPositionColor(new Vector3(x3, y3, 0), fc));

                    angle = ((i + 10) / 57.3f);
                    x3    = xPos + ((distance / 2f) * (float)Math.Sin(angle));
                    y3    = yPos + ((distance / 2f) * (float)Math.Cos(angle));
                    vertices.Add(new VertexPositionColor(new Vector3(x3, y3, 0), fc));
                }

                y1 = y2;
                x1 = x2;
            }

            RenderVertices();
        }
Esempio n. 4
0
        public Vector2 Draw(SpriteBatch sb, string str, Vector2 position, Microsoft.Xna.Framework.Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            Vector2 maxBound = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 vector   = position;
            float   num      = 0f;
            float   num2     = 0f;

            foreach (char c in str)
            {
                addTex(c);
                CharTile charTile = CharTiles[c];
                if (c == '\r' || vector.X + (float)charTile.rect.Width * scale.X > maxBound.X)
                {
                    if (vector.X > num2)
                    {
                        num2 = vector.X;
                    }
                    vector.X  = position.X;
                    vector.Y += num * scale.Y + Spacing.Y * scale.X;
                    num       = 0f;
                }
                else
                {
                    if (c == '\n')
                    {
                        continue;
                    }
                    if ((float)charTile.rect.Height > num)
                    {
                        num = charTile.rect.Height;
                        if (vector.Y + num * scale.Y > maxBound.Y)
                        {
                            break;
                        }
                    }
                    sb?.Draw(charTile.tex, vector, charTile.rect, color, rotation, origin, scale, effects, layerDepth);
                    vector.X += (float)charTile.rect.Width * scale.X + Spacing.X * scale.X;
                }
            }
            if (vector.X > num2)
            {
                num2 = vector.X;
            }
            vector.X  = num2 - Spacing.X * scale.X;
            vector.Y += num * scale.Y;
            return(vector - position);
        }
        public Texture2D CreateTexture()
        {
            var texture = new Texture2D(MyGame.Instance.GraphicsDevice, Size.Width, Size.Height);

            Microsoft.Xna.Framework.Color[] colorData = new Microsoft.Xna.Framework.Color[Size.Width * Size.Height];
            switch (FileType)
            {
            case PpmFileType.P3:
                return(Ppm3(texture, colorData));

            case PpmFileType.P6:
                return(Ppm6(texture, colorData));

            default:
            case PpmFileType.Invalid:
                throw new ArgumentException("Invalid PPM file type");
            }
        }
Esempio n. 6
0
        // Public goodies
        public static void draw_triangle(double x1, double y1, double x2, double y2, double x3, double y3, bool outline, double angle = 0)
        {
            Microsoft.Xna.Framework.Color fc = FinalizeColor(DrawColor);
            vertices.Clear();

            VertexPositionColor v0 = new VertexPositionColor(new Vector3((float)x1, (float)y1, 0), fc);
            VertexPositionColor v1 = new VertexPositionColor(new Vector3((float)x2, (float)y2, 0), fc);
            VertexPositionColor v2 = new VertexPositionColor(new Vector3((float)x3, (float)y3, 0), fc);

            if (Math.Abs(angle) > 0.001)
            {
                Vector2 pp = GetCentroid(new Vector3[] { v0.Position, v1.Position, v2.Position });

                v0.Position = RotateVec3(v0.Position, new Vector3(pp, 0), angle);
                v1.Position = RotateVec3(v1.Position, new Vector3(pp, 0), angle);
                v2.Position = RotateVec3(v2.Position, new Vector3(pp, 0), angle);
            }

            vertices.Add(v0);
            vertices.Add(v1);
            vertices.Add(v2);

            RenderVertices(PrimitiveType.TriangleList, outline);
        }
Esempio n. 7
0
        public static bool DrawStringPrefixCover(SpriteFont spriteFont, string text, Vector2 position, Microsoft.Xna.Framework.Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            if ((text == null && text.Length == 0))
            {
                return(true);
            }

            bool hasChineseWord = false;

            foreach (char i in text)
            {
                if (IsChinese(i))
                {
                    hasChineseWord = true;
                    break;
                }
            }
            if (!hasChineseWord)
            {
                return(true);
            }

            if (spriteFont.GetHashCode() == GuiData.tinyfont.GetHashCode())
            {
                CurSpriteFont10.Draw(GuiData.spriteBatch, text, position, color, rotation, origin, scale, effects, layerDepth);
            }
            else if (spriteFont.GetHashCode() == GuiData.smallfont.GetHashCode())
            {
                CurSpriteFont12.Draw(GuiData.spriteBatch, text, position, color, rotation, origin, scale, effects, layerDepth);
            }
            else if (spriteFont.GetHashCode() == GuiData.font.GetHashCode())
            {
                CurSpriteFont23.Draw(GuiData.spriteBatch, text, position, color, rotation, origin, scale, effects, layerDepth);
            }
            else if (spriteFont.GetHashCode() == GuiData.detailfont.GetHashCode())
            {
                CurSpriteFont7.Draw(GuiData.spriteBatch, text, position, color, rotation, origin, scale, effects, layerDepth);
            }
            else
            {
                return(true);
            }
            return(false);
        }
Esempio n. 8
0
        public static void draw_line_width_color(Vector2 pos1, Vector2 pos2, int width, Microsoft.Xna.Framework.Color c1, Microsoft.Xna.Framework.Color c2, Microsoft.Xna.Framework.Color c3, Microsoft.Xna.Framework.Color c4, double angle = 0)
        {
            vertices.Clear();

            Vector2 newVec    = pos2 - pos1;
            Vector3 newVector = Vector3.Cross(new Vector3(newVec, 0), Vector3.Forward);

            newVector.Normalize();
            newVec.X = newVector.X;
            newVec.Y = newVector.Y;

            Vector2 x1 = width * newVec + pos2;
            Vector2 x2 = -width * newVec + pos1;
            Vector2 x3 = -width * newVec + pos2;
            Vector2 x4 = width * newVec + pos1;

            VertexPositionColor v1 = new VertexPositionColor(new Vector3(x1, 0), FinalizeColor(c1));
            VertexPositionColor v2 = new VertexPositionColor(new Vector3(x2, 0), FinalizeColor(c2));
            VertexPositionColor v3 = new VertexPositionColor(new Vector3(x3, 0), FinalizeColor(c3));
            VertexPositionColor v4 = new VertexPositionColor(new Vector3(x4, 0), FinalizeColor(c4));

            angle = ApplyEpsilon(angle);
            if (angle != 0)
            {
                Vector2 c = GetCentroid(new Vector3[] { v1.Position, v3.Position, v2.Position, v4.Position });
                v1.Position = RotateVec3(v1.Position, new Vector3(c, 0), angle);
                v2.Position = RotateVec3(v2.Position, new Vector3(c, 0), angle);
                v3.Position = RotateVec3(v3.Position, new Vector3(c, 0), angle);
                v4.Position = RotateVec3(v4.Position, new Vector3(c, 0), angle);
            }

            vertices.AddRange(new[] { v1, v3, v2, v2, v4, v1 });

            RenderVertices();
        }
Esempio n. 9
0
        public Vector2 Draw(SpriteBatch sb, char[] str, Vector2 position, Vector2 maxBound, Vector2 scale, Microsoft.Xna.Framework.Color color)
        {
            if (maxBound.X == 0f)
            {
                maxBound.X = float.MaxValue;
            }
            else
            {
                maxBound.X += position.X;
            }
            if (maxBound.Y == 0f)
            {
                maxBound.Y = float.MaxValue;
            }
            else
            {
                maxBound.Y += position.Y;
            }
            Vector2 vector = position;
            float   num    = 0f;
            float   num2   = 0f;

            foreach (char c in str)
            {
                addTex(c);
                CharTile charTile = CharTiles[c];
                if (c == '\r' || vector.X + (float)charTile.rect.Width * scale.X > maxBound.X)
                {
                    if (vector.X > num2)
                    {
                        num2 = vector.X;
                    }
                    vector.X  = position.X;
                    vector.Y += num * scale.Y + Spacing.Y * scale.X;
                    num       = 0f;
                }
                else
                {
                    if (c == '\n')
                    {
                        continue;
                    }
                    if ((float)charTile.rect.Height > num)
                    {
                        num = charTile.rect.Height;
                        if (vector.Y + num * scale.Y > maxBound.Y)
                        {
                            break;
                        }
                    }
                    sb?.Draw(charTile.tex, vector, charTile.rect, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
                    vector.X += (float)charTile.rect.Width * scale.X + Spacing.X * scale.X;
                }
            }
            if (vector.X > num2)
            {
                num2 = vector.X;
            }
            vector.X  = num2 - Spacing.X * scale.X;
            vector.Y += num * scale.Y;
            return(vector - position);
        }
Esempio n. 10
0
 public Vector2 Draw(SpriteBatch sb, string str, Vector2 position, Vector2 maxBound, Vector2 scale, Microsoft.Xna.Framework.Color color)
 {
     return(Draw(sb, str.ToCharArray(), position, maxBound, scale, color));
 }
Esempio n. 11
0
 public Vector2 Draw(SpriteBatch sb, char[] str, Vector2 position, Microsoft.Xna.Framework.Color color)
 {
     return(Draw(sb, str, position, new Vector2(float.MaxValue, float.MaxValue), Vector2.One, color));
 }