Пример #1
0
 private static void NormalizeRect(ref ERectangleF rct)
 {
     if (rct.Width < 0)
     {
         rct.Offset(rct.Width, 0);
         rct.Width = -rct.Width;
     }
     if (rct.Height < 0)
     {
         rct.Offset(0, rct.Height);
         rct.Height = -rct.Height;
     }
 }
Пример #2
0
        public override void SubDraw()
        {
            ERectangleF rctDraw = m_sp.CalcRectInDrawTarget();

//			Matrix QuadMatrix = Matrix.Scaling(rctDraw.Width, rctDraw.Height, 1);

            EPointF pntRegOff = m_sp.RegPoint.ToEPointF() / new EPointF(m_sp.SourceRect.Width, m_sp.SourceRect.Height) * new EPointF(rctDraw.Width, rctDraw.Height);

//			QuadMatrix.Multiply(Matrix.Translation(-pntRegOff.X, pntRegOff.Y,0));
//			QuadMatrix.Multiply(Matrix.RotationZ(-m_sp.Rotation));
//			QuadMatrix.Multiply(Matrix.Translation(pntRegOff.X, -pntRegOff.Y,0));

            EPoint  renderControlSize = new EPoint(800, 600);
            EPointF pntLoc            = new EPointF(rctDraw.X - renderControlSize.X / 2, rctDraw.Y - renderControlSize.Y / 2);

            //QuadMatrix.Multiply(Matrix.Translation(pntLoc.X, -pntLoc.Y, 0f));


            int tx = ((MemberSpriteBitmapRenderStrategyA)this.m_sp.Member.RenderStrategy).TextureId;

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, tx);

            //Gl.glRotatef(m_sp.Rotation, 0, 0, 1);

            Gl.glBegin(Gl.GL_QUADS);
            if (false)
            {
                Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-1, -1, 1);
                Gl.glTexCoord2f(1, 0); Gl.glVertex3f(1, -1, 1);
                Gl.glTexCoord2f(1, 1); Gl.glVertex3f(1, 1, 1);
                Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-1, 1, 1);
            }
            rctDraw = rctDraw * 0.01f;
            rctDraw.Offset(-1f, -1f);
//			rctDraw.Y = 1f-rctDraw.Y;
            Gl.glTexCoord2f(0, 0); Gl.glVertex3f(rctDraw.Left, rctDraw.Top, 1);
            Gl.glTexCoord2f(1, 0); Gl.glVertex3f(rctDraw.Right, rctDraw.Top, 1);
            Gl.glTexCoord2f(1, 1); Gl.glVertex3f(rctDraw.Right, rctDraw.Bottom, 1);
            Gl.glTexCoord2f(0, 1); Gl.glVertex3f(rctDraw.Left, rctDraw.Bottom, 1);

            Gl.glEnd();
        }
Пример #3
0
 private static void NormalizeRect(ref ERectangleF rct)
 {
     if (rct.Width < 0)
     {
         rct.Offset(rct.Width,0);
         rct.Width = -rct.Width;
     }
     if (rct.Height < 0)
     {
         rct.Offset(0,rct.Height);
         rct.Height = -rct.Height;
     }
 }
Пример #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);
        }