Ejemplo n.º 1
0
 public void Attach(GeomPole pole, float fXOffset)
 {
     m_pole = pole;
     m_pole.SetLocation(Location.X + fXOffset, Location.Y);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Render the gyms specified data.
        /// </summary>
        /// <param name="bShowUi">When <i>true</i> the Bitmap is drawn.</param>
        /// <param name="nWidth">Specifies the width used to size the Bitmap.</param>
        /// <param name="nHeight">Specifies the height used to size the Bitmap.</param>
        /// <param name="rgData">Specifies the gym data to render.</param>
        /// <param name="bGetAction">When <i>true</i> the action data is returned as a SimpleDatum.</param>
        /// <returns>A tuple optionally containing a Bitmap and/or Simpledatum is returned.</returns>
        public Tuple <Bitmap, SimpleDatum> Render(bool bShowUi, int nWidth, int nHeight, double[] rgData, bool bGetAction)
        {
            Bitmap bmp = new Bitmap(nWidth, nHeight);

            double dfX              = rgData[0];
            double dfTheta          = rgData[2];
            double dfThetaInDegrees = dfTheta * (180.0 / Math.PI);
            double dfForceMag       = rgData[4];
            int    nSteps           = (int)rgData[5];

            m_nSteps    = nSteps;
            m_nMaxSteps = Math.Max(nSteps, m_nMaxSteps);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                Rectangle rc = new Rectangle(0, 0, bmp.Width, bmp.Height);
                g.FillRectangle(Brushes.White, rc);

                float fScreenWidth  = g.VisibleClipBounds.Width;
                float fScreenHeight = g.VisibleClipBounds.Height;
                float fWorldWidth   = (float)(m_dfXThreshold * 2);
                float fScale        = fScreenWidth / fWorldWidth;
                float fCartY        = 100; // Top of Cart;
                float fPoleWidth    = 10;
                float fPoleLen      = fScale * 1.0f;
                float fCartWidth    = 50;
                float fCartHeight   = 30;

                float    fL          = -fCartWidth / 2;
                float    fR          = fCartWidth / 2;
                float    fT          = fCartHeight / 2;
                float    fB          = -fCartHeight / 2;
                float    fAxleOffset = 0;
                GeomCart cart        = new GeomCart(fL, fR, fT, fB, Color.SkyBlue, Color.Black);

                fL = -fPoleWidth / 2;
                fR = fPoleWidth / 2;
                fT = fPoleLen - fPoleWidth / 2;
                fB = --fPoleWidth / 2;
                GeomPole pole = new GeomPole(fL, fR, fT, fB, Color.Tan, Color.Black);

                fL = 0;
                fR = fScreenWidth;
                fT = fCartY;
                fB = fT;
                GeomLine track = new GeomLine(fL, fR, fT, fB, Color.Black, Color.Black);

                fL = 0;
                fR = fScreenWidth;
                fT = fCartY - 40;
                fB = fT + 10;

                if (m_clrMap == null)
                {
                    m_clrMap = new ColorMapper(fL, fR, Color.Fuchsia, Color.Red);
                }

                GeomRectangle posbar = new GeomRectangle(fL, fR, fT, fB, Color.Black, Color.Transparent, m_clrMap);

                float fCartX = (float)dfX * fScale + fScreenWidth / 2;   // middle of the cart.
                cart.SetLocation(fCartX, fCartY);
                pole.SetRotation((float)-dfThetaInDegrees);
                cart.Attach(pole, fAxleOffset);

                GeomView view = new GeomView();

                view.RenderText(g, "Current Force = " + dfForceMag.ToString(), 10, 10);
                view.RenderText(g, "X = " + dfX.ToString("N02"), 10, 24);
                view.RenderText(g, "Theta = " + dfTheta.ToString("N02") + " radians", 10, 36);
                view.RenderText(g, "Theta = " + dfThetaInDegrees.ToString("N02") + " degrees", 10, 48);
                view.RenderSteps(g, m_nSteps, m_nMaxSteps);

                // Render the objects.
                view.AddObject(posbar);
                view.AddObject(track);
                view.AddObject(cart);
                view.Render(g);

                SimpleDatum sdAction = null;

                if (bGetAction)
                {
                    sdAction = getActionData(fCartX, fCartY, bmp);
                }

                m_bmp = bmp;

                return(new Tuple <Bitmap, SimpleDatum>(bmp, sdAction));
            }
        }