コード例 #1
0
ファイル: LineExt.cs プロジェクト: yadiate/MoonLightCraft
        static public void DrawLine_DotCircle(SpriteBatch spriteBatch, Vector2 vStart, Vector2 vEnd, Color color, int dotsize, int padding)
        {
            if (m_LineTexture == null)
            {
                CreateLineTexture(spriteBatch.GraphicsDevice);
            }


            float   angle    = MathExt.AngleToDegrees(vStart, vEnd);
            float   distance = Vector2.Distance(vStart, vEnd);
            Vector2 vTemp    = vStart - MathExt.DistanceTo_range_angle(Vector2.Zero, padding, angle);

            for (int i = padding; i < distance; i += dotsize * 2)
            {
                vTemp += MathExt.DistanceTo_range_angle(Vector2.Zero, dotsize, angle) * 2;
                DrawCircleAll(spriteBatch, vTemp, dotsize, color);
            }
        }
コード例 #2
0
ファイル: LineExt.cs プロジェクト: yadiate/MoonLightCraft
        static public void DrawLine_DotRect(SpriteBatch spriteBatch, Vector2 vStart, Vector2 vEnd, Color color, int dotwitdh, int LineT, int padding)
        {
            if (m_LineTexture == null)
            {
                CreateLineTexture(spriteBatch.GraphicsDevice);
            }
            m_LIneColor = color;
            float   angle    = MathExt.AngleToDegrees(vStart, vEnd);
            float   distance = Vector2.Distance(vStart, vEnd);
            Vector2 vTemp    = vStart - MathExt.DistanceTo_range_angle(Vector2.Zero, padding, angle);

            for (int i = padding; i < distance; i += dotwitdh * 2)
            {
                vTemp    += MathExt.DistanceTo_range_angle(Vector2.Zero, dotwitdh, angle) * 2;
                distanceY = LineT;
                Draw(spriteBatch, vTemp, MathExt.DistanceTo_range_angle(vTemp, dotwitdh, angle));
            }
        }
コード例 #3
0
        public static bool LineRectCollision(Vector2 vStart, Vector2 vEnd, Rectangle destRect)
        {
            float   degree        = MathExt.AngleToDegrees(vStart, vEnd);
            float   lineLength    = MathExt.DistanceTwoPoint(vStart, vEnd);
            float   inputRotation = MathHelper.ToRadians(degree);
            Vector2 vOrg          = new Vector2(1, 0);

            vOrg = Vector2.Transform(vOrg, Matrix.CreateRotationZ(inputRotation));

            BoundingBox box = new BoundingBox(new Vector3(destRect.Left, destRect.Top, 0.0f),
                                              new Vector3(destRect.Right, destRect.Bottom, 0.0f));
            Ray ray = new Ray(new Vector3(vStart, 0.0f), new Vector3(vOrg, 0.0f));

            float?result = box.Intersects(ray);

            if (result != null && result <= lineLength)
            {
                return(true);
            }

            return(false);
        }