Exemplo n.º 1
0
        /// <summary>
        /// Draws the arrow image extending from "from" along the "dir" direction
        /// </summary>
        /// <param name="from">beginning position of the vector</param>
        /// <param name="dir">the direction of the vector</param>
        static public void DrawPointVector(Vector2 from, Vector2 dir)
        {
            LoadImage();

            float length = dir.Length();

            float theta = 0f;

            // compute the angle to rotate ...
            if (length > 0.001f)
            {
                dir  /= length;
                theta = (float)Math.Acos((double)dir.X);
                if (dir.X < 0.0f)
                {
                    if (dir.Y > 0.0f)
                    {
                        theta = -theta;
                    }
                }
                else
                {
                    if (dir.Y > 0.0f)
                    {
                        theta = -theta;
                    }
                }
            }

            // Defines where and size of the texture to show
            Vector2   size     = new Vector2(length, kLenToWidthRatio * length);
            Rectangle destRect = Camera.ComputePixelRectangle(from, size);

            // destRect is computed with respect to the "from" position, on the left-side of the texture
            // we only need to offse the reference in the y from top-left to middle-left
            Vector2 org = new Vector2(0f, ShowVector.sImage.Height / 2f);

            Game1.sSpriteBatch.Draw(ShowVector.sImage, destRect, null, Color.White,
                                    theta, org, SpriteEffects.None, 0f);

            String msg;

            msg = "Direction=" + dir + "\nSize=" + length;
            FontSupport.PrintStatusAt(from + (0.5f * length * dir), msg, Color.Black);
        }
        public override void Draw()
        {
            // Defines where and size of the texture to show
            Rectangle destRect = Camera.ComputePixelRectangle(mPosition, mSize);

            int imageTop  = mCurrentRow * mSpriteImageHeight;
            int imageLeft = mCurrentColumn * mSpriteImageWidth;
            //PLS KILL ME
            //Console.WriteLine(imageTop + " " + imageLeft);

            // define the rotation origin
            Vector2 org = new Vector2(mSpriteImageWidth / 2, mSpriteImageHeight / 2);

            // define the area to be drawn
            Rectangle srcRect = new Rectangle(
                imageLeft + mPaddings,
                imageTop + mPaddings,
                mSpriteImageWidth, mSpriteImageHeight);

            // Draw the texture
            Game1.sSpriteBatch.Draw(mImage,
                                    destRect,     // Area to be drawn in pixel space
                                    srcRect,      // <<-- rect on the spriteSheet
                                    Color.White,  //
                                    mRotateAngle, // Angle to roate (clockwise)
                                    org,          // Image reference position,
                                    SpriteEffects, 0f);

            //Game1.sSpriteBatch.Draw(mImage, destRect,srcRect, Color.White);


            if (null != mLabelString)
            {
                FontSupport.PrintStatusAt(mPosition, mLabelString, mLabelColor);
            }
        }