Exemplo n.º 1
0
        public static Bitmap CreateLineBitmap(ERectangleF rctLine, Color clrBg, Color clrPen, float penWidth, out EPointF locOffset)
        {
            //Because GDI+ arrows are so limited
            Bitmap bmp = null;

            locOffset = new EPointF();

            if (rctLine.Width != 0 && rctLine.Height != 0)
            {
                bmp = new Bitmap((int)Math.Abs(rctLine.Width) + 1, (int)Math.Abs(rctLine.Height) + 1, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Graphics g = Graphics.FromImage(bmp);

                g.FillRectangle(new SolidBrush(clrBg), 0, 0, bmp.Width, bmp.Height);

                ERectangleF rctOrigo = rctLine.Copy();
                rctOrigo.MakeTopLeftAtOrigo();

                Pen pen = new Pen(clrPen, penWidth);
                g.DrawLine(pen, rctOrigo.X, rctOrigo.Y, rctOrigo.X + rctOrigo.Width, rctOrigo.Y + rctOrigo.Height);
                g.Dispose();

                if (rctOrigo.Width < 0)
                {
                    locOffset.X = rctOrigo.Width;
                }
                if (rctOrigo.Height < 0)
                {
                    locOffset.Y = rctOrigo.Height;
                }
            }
            return(bmp);
        }
Exemplo n.º 2
0
        public static Bitmap CreateLineBitmap(ERectangleF rctLine, Color clrBg, Color clrPen, float penWidth, out EPointF locOffset)
        {
            //Because GDI+ arrows are so limited
            Bitmap bmp = null;
            locOffset = new EPointF();

            if (rctLine.Width != 0 && rctLine.Height != 0)
            {
                bmp = new Bitmap((int)Math.Abs(rctLine.Width)+1, (int)Math.Abs(rctLine.Height)+1, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Graphics g = Graphics.FromImage(bmp);

                g.FillRectangle(new SolidBrush(clrBg), 0,0,bmp.Width,bmp.Height);

                ERectangleF rctOrigo = rctLine.Copy();
                rctOrigo.MakeTopLeftAtOrigo();

                Pen pen = new Pen(clrPen, penWidth);
                g.DrawLine(pen, rctOrigo.X, rctOrigo.Y, rctOrigo.X+rctOrigo.Width, rctOrigo.Y+rctOrigo.Height);
                g.Dispose();

                if (rctOrigo.Width < 0)
                    locOffset.X = rctOrigo.Width;
                if (rctOrigo.Height < 0)
                    locOffset.Y = rctOrigo.Height;
            }
            return bmp;
        }
Exemplo n.º 3
0
        private void PlayerBall_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, MouseEventType t)
        {
            if (t == Sprite.MouseEventType.Down)
            {
                forceMarker.Visible = true;
            }
            else if (t == Sprite.MouseEventType.StillDown)
            {
                MemberSpriteBitmap mb = forceMarker.Member;
                if (mb != null)
                {
                    mb.Dispose();
                }

                //this.MouseDownLoc.X, this.MouseDownLoc.Y
                ERectangleF rctLine = ERectangleF.FromLTRB(this.Loc.X, this.Loc.Y, this.MouseLastLoc.X, this.MouseLastLoc.Y);
                forceVector = rctLine.Size;

                if (rctLine.Width != 0 && rctLine.Height != 0)
                {
                    Bitmap   bmp = new Bitmap((int)Math.Abs(rctLine.Width) + 1, (int)Math.Abs(rctLine.Height) + 1, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    Graphics g   = Graphics.FromImage(bmp);

                    ERectangleF rctOrigo = rctLine.Copy();
                    rctOrigo.MakeTopLeftAtOrigo();

                    Pen pen = new Pen(Color.Red, 2);
                    g.DrawLine(pen, rctOrigo.X, rctOrigo.Y, rctOrigo.X + rctOrigo.Width, rctOrigo.Y + rctOrigo.Height);
                    g.Dispose();

                    EPointF locOffset = new EPointF();
                    if (rctOrigo.Width < 0)
                    {
                        locOffset.X = rctOrigo.Width;
                    }
                    if (rctOrigo.Height < 0)
                    {
                        locOffset.Y = rctOrigo.Height;
                    }

                    mb = new MemberSpriteBitmap(bmp);
                    forceMarker.Member = mb;
                    forceMarker.Loc    = this.Loc + locOffset;
                }
                else
                {
                    forceMarker.Member = null;
                }
            }
            else if (t == Sprite.MouseEventType.UpOutside || t == Sprite.MouseEventType.Click)
            {
                this.Velocity = forceVector * -0.1f;

                forceMarker.Visible = false;
                MemberSpriteBitmap mb = forceMarker.Member;
                if (mb != null)
                {
                    forceMarker.Member = null;
                    mb.Dispose();
                }
            }
        }
Exemplo n.º 4
0
        public static bool CalcCircleLineCollision(EPointF circleLoc, float radius, EPointF circleMovement, ERectangleF lineRect, out EPointF pntFirstCollision, out EPointF circleLocAtCollision)
        {
            //first calc two lines parallel with line, at radius distance from it
            double dAngleLine = Math.Atan2((double)lineRect.Width, -(double)lineRect.Height);
            double dAnglePerp = dAngleLine+Math.PI/2;
            EPointF pntOffset = new EPointF(radius*(float)Math.Sin(dAnglePerp), -radius*(float)Math.Cos(dAnglePerp));
            ERectangleF lineRect1 = lineRect;
            ERectangleF circleMovementLine = new ERectangleF(circleLoc, new EPointF(circleMovement.X, circleMovement.Y));

            float fTimeFirstCollision = 1000;
            pntFirstCollision = new EPointF(0,0);
            circleLocAtCollision = new EPointF(0,0);
            for (int i = -1; i < 2; i+=2)
            {
                ERectangleF lineRectParallel = lineRect.Copy();
                lineRectParallel.Offset(pntOffset.X*i, pntOffset.Y*i);
                EPointF pntCollision;
                if (CalcLineLineCollision(circleMovementLine, lineRectParallel, out pntCollision))
                {
                    EPointF pntDiff = new EPointF(pntCollision.X-circleMovementLine.X, pntCollision.Y-circleMovementLine.Y); //circleMovementLine.Left, pntCollision.Y-circleMovementLine.Top
                    float fTimeCollision = Endogine.Collision.PointLine.PointIsWhereOnLine(pntDiff, circleMovementLine);
                    if (fTimeCollision < fTimeFirstCollision)
                    {
                        fTimeFirstCollision = fTimeCollision;
                        pntFirstCollision = new EPointF(pntCollision.X-pntOffset.X*i, pntCollision.Y-pntOffset.Y*i);
                        circleLocAtCollision = pntCollision;
                    }
                }
            }
            //also calc circle/circle collision (for line end points)
            ArrayList aLocs, aTimes;
            EPointF pntLinePointToTest = lineRect.Location;
            for (int i = 0; i < 2; i++)
            {
                if (CalcCircleCircleCollisions(circleLoc, pntLinePointToTest, circleMovement, new EPointF(0,0), radius, 0, out aLocs, out aTimes))
                {
                    EPointF pntCollision = (EPointF)aLocs[0];
                    float fTimeCollision = (float)aTimes[0];
                    if (fTimeCollision < 0)
                    {
                        fTimeCollision = (float)aTimes[1];
                        if (fTimeCollision < 0 || fTimeCollision > 1)
                            continue;
                        pntCollision = (EPointF)aLocs[1];
                    }
                    if (fTimeCollision < fTimeFirstCollision)
                    {
                        fTimeFirstCollision = fTimeCollision;
                        pntFirstCollision = pntLinePointToTest;
                        circleLocAtCollision = new EPointF(circleLoc.X+circleMovement.X*fTimeCollision, circleLoc.Y+circleMovement.Y*fTimeCollision);
                    }
                }
                pntLinePointToTest = new EPointF(lineRect.X+lineRect.Width, lineRect.Y+lineRect.Height); //lineRect.Left+lineRect.Width, lineRect.Top
            }
            if (fTimeFirstCollision <= 1)
                return true;
            return false;
        }
Exemplo n.º 5
0
        public static bool CalcCircleLineCollision(EPointF circleLoc, float radius, EPointF circleMovement, ERectangleF lineRect, out EPointF pntFirstCollision, out EPointF circleLocAtCollision)
        {
            //first calc two lines parallel with line, at radius distance from it
            double      dAngleLine         = Math.Atan2((double)lineRect.Width, -(double)lineRect.Height);
            double      dAnglePerp         = dAngleLine + Math.PI / 2;
            EPointF     pntOffset          = new EPointF(radius * (float)Math.Sin(dAnglePerp), -radius * (float)Math.Cos(dAnglePerp));
            ERectangleF lineRect1          = lineRect;
            ERectangleF circleMovementLine = new ERectangleF(circleLoc, new EPointF(circleMovement.X, circleMovement.Y));

            float fTimeFirstCollision = 1000;

            pntFirstCollision    = new EPointF(0, 0);
            circleLocAtCollision = new EPointF(0, 0);
            for (int i = -1; i < 2; i += 2)
            {
                ERectangleF lineRectParallel = lineRect.Copy();
                lineRectParallel.Offset(pntOffset.X * i, pntOffset.Y * i);
                EPointF pntCollision;
                if (CalcLineLineCollision(circleMovementLine, lineRectParallel, out pntCollision))
                {
                    EPointF pntDiff        = new EPointF(pntCollision.X - circleMovementLine.X, pntCollision.Y - circleMovementLine.Y);          //circleMovementLine.Left, pntCollision.Y-circleMovementLine.Top
                    float   fTimeCollision = Endogine.Collision.PointLine.PointIsWhereOnLine(pntDiff, circleMovementLine);
                    if (fTimeCollision < fTimeFirstCollision)
                    {
                        fTimeFirstCollision  = fTimeCollision;
                        pntFirstCollision    = new EPointF(pntCollision.X - pntOffset.X * i, pntCollision.Y - pntOffset.Y * i);
                        circleLocAtCollision = pntCollision;
                    }
                }
            }
            //also calc circle/circle collision (for line end points)
            ArrayList aLocs, aTimes;
            EPointF   pntLinePointToTest = lineRect.Location;

            for (int i = 0; i < 2; i++)
            {
                if (CalcCircleCircleCollisions(circleLoc, pntLinePointToTest, circleMovement, new EPointF(0, 0), radius, 0, out aLocs, out aTimes))
                {
                    EPointF pntCollision   = (EPointF)aLocs[0];
                    float   fTimeCollision = (float)aTimes[0];
                    if (fTimeCollision < 0)
                    {
                        fTimeCollision = (float)aTimes[1];
                        if (fTimeCollision < 0 || fTimeCollision > 1)
                        {
                            continue;
                        }
                        pntCollision = (EPointF)aLocs[1];
                    }
                    if (fTimeCollision < fTimeFirstCollision)
                    {
                        fTimeFirstCollision  = fTimeCollision;
                        pntFirstCollision    = pntLinePointToTest;
                        circleLocAtCollision = new EPointF(circleLoc.X + circleMovement.X * fTimeCollision, circleLoc.Y + circleMovement.Y * fTimeCollision);
                    }
                }
                pntLinePointToTest = new EPointF(lineRect.X + lineRect.Width, lineRect.Y + lineRect.Height);             //lineRect.Left+lineRect.Width, lineRect.Top
            }
            if (fTimeFirstCollision <= 1)
            {
                return(true);
            }
            return(false);
        }