Exemple #1
0
        /// <summary>
        /// Move the pendulum
        /// </summary>
        /// <param name="timer">The timer.</param>
        public void Move(Timer timer)
        {
            var rotation = (float)(_maxAngle * Math.Cos(Math.Sqrt(9.81 / _length) * timer.Time()));

            _sprite.Begin(Direct3D.SpriteFlags.AlphaBlend);
            _sprite.Transform =
                Matrix.Transformation2D(
                    new Vector2((float)(_sWidth / 2.0), 0.0f),      //scaling centre
                    0.0f,                                           //scaling ratio
                    new Vector2(_length / 5.0f, _length / 5.0f),    //scaling
                    new Vector2((float)(_sWidth / 2.0), 0),         //rotation centre
                    rotation,                                       //rotation
                    new Vector2(0.0f, 0.0f));                       //translation

            _sprite.Draw(_texture, Rectangle.Empty, new Vector3(50, 0.0f, 0.0f), new Vector3((float)(_sWidth / 2.0), 0, 0.0f), Color.White);
            _sprite.End();
            if (Math.Abs(_maxAngle - 0.0) < 0.001)
            {
                _sound.Pan    = 0;
                _sound.Volume = 0;
            }
            else
            {
                _sound.Pan    = -(int)(10000 * (float)((rotation / _maxAngle) * .5));
                _sound.Volume = (int)(-1000 * (Math.Abs(rotation) / (_maxAngle)));
            }
        }
Exemple #2
0
        public override void DrawText(Point dest_pt, string text)
        {
            if (mSprite == null)
            {
                mSprite = new Microsoft.DirectX.Direct3D.Sprite(mD3DFont.Device);
            }

            Point dest = Origin.Calc(DisplayAlignment, StringDisplaySize(text));


            dest_pt.X -= dest.X;
            dest_pt.Y -= dest.Y;

            double scalex, scaley;

            GetScale(out scalex, out scaley);

            mDisplay.D3D_Device.DrawBuffer.Flush();
            mDisplay.D3D_Device.SetFontRenderState();

            mSprite.Begin(SpriteFlags.AlphaBlend);
            mSprite.Transform = Matrix.Scaling((float)scalex, (float)scaley, 1.0f)
                                * Matrix.Translation(dest_pt.X, dest_pt.Y, 0);

            mD3DFont.DrawText(mSprite, text, new System.Drawing.Point(0, 0), Color.ToArgb());

            mSprite.End();
        }
Exemple #3
0
        internal void EndScene()
        {
            _SpriteBatch.End();

            _Device.EndScene();

            _Device.Present();
        }
 public void Draw(D3D.Device device)
 {
     using (D3D.Sprite d3dSprite = new D3D.Sprite(device)) {
         d3dSprite.Begin(D3D.SpriteFlags.AlphaBlend);
         foreach (BasicSprite sprite in sprites)
         {
             sprite.Draw(d3dSprite);
         }
         d3dSprite.End();
     }
 }
        private bool render_image(Microsoft.DirectX.Direct3D.Sprite sprite, Texture texture, Point hot, double fRadian, int nXDest, int nYDest, int nDestWidth, int nDestHeight, int nXSource, int nYSource, int nSourceWidth, int nSourceHeight, int cbAlpha)
        {
            const double M_PI = 3.14159265358979323846;

            if (sprite == null)
            {
                return(false);
            }

            if (fRadian == M_PI)
            {
                float degrees1 = (float)(fRadian * (180 / M_PI));
            }

            float degrees = (float)(fRadian * (180 / M_PI));

            System.Drawing.Rectangle srcRectangle = new System.Drawing.Rectangle(nXSource, nYSource, nSourceWidth, nSourceHeight);
            //Color color = Color.FromArgb( cbAlpha, Color.White );

            sprite.Begin(SpriteFlags.SortTexture | SpriteFlags.AlphaBlend);
            //sprite.Draw(_Texture, srcRectangle, Vector3.Empty, new Vector3(nXDest, nYDest, 0), cbAlpha );

            //_Sprite.Transform = Matrix.Scaling((float)nDestWidth / nSourceWidth, (float)nDestHeight / nSourceHeight, 0.0f);

            //sprite.Transform = Matrix.Translation(-nSourceWidth / 2, -nSourceHeight / 2, 0);
            //sprite.Transform *= Matrix.RotationZ((float)fRadian);
            //sprite.Transform *= Matrix.Translation(nSourceWidth / 2, nSourceHeight / 2, 0);
            //sprite.Transform *= Matrix.Scaling((float)nDestWidth / nSourceWidth, (float)nDestHeight / nSourceHeight, 0.0f);
            //sprite.Transform *= Matrix.Translation(nXDest, nYDest, 0);

            //sprite.Transform = Matrix.Scaling((float)nDestWidth / nSourceWidth, (float)nDestHeight / nSourceHeight, 0.0f);
            //sprite.Transform *= Matrix.Translation(-nDestWidth / 2, -nDestWidth / 2, 0);
            //sprite.Transform = Matrix.RotationZ((float)fRadian);
            //sprite.Transform *= Matrix.Translation(nDestWidth / 2, nDestWidth / 2, 0);
            //sprite.Transform *= Matrix.Translation(nXDest, nYDest, 0);

            sprite.Transform = Matrix.RotationZ((float)fRadian) * Matrix.Scaling((float)nDestWidth / nSourceWidth, (float)nDestHeight / nSourceHeight, 0.0f) * Matrix.Translation(nXDest, nYDest, 0);

            sprite.Draw(texture, srcRectangle, new Vector3((int)hot.x_, (int)hot.y_, 0), new Vector3(0, 0, 0), System.Drawing.Color.FromArgb(cbAlpha, System.Drawing.Color.White).ToArgb());
            //sprite.Draw(texture, srcRectangle, new Vector3(0, 0, 0), new Vector3(0, 0, 0), System.Drawing.Color.FromArgb(cbAlpha, System.Drawing.Color.White).ToArgb());

            //_Sprite.Draw(_Texture, Vector3.Empty, new Vector3(nXDest, nYDest, 0), Color.White.ToArgb());
            sprite.End();

            //sprite.Begin(SpriteFlags.None);
            //sprite.Draw2D(_Texture, Rectangle.Empty, Rectangle.Empty,
            //              new Point(5, 5), Color.White);
            //sprite.End();

            return(true);
        }
Exemple #6
0
        public void DisplayLevel(int level)
        {
            int     characterStart   = 30;
            int     characterSpacing = 15;
            Vector3 displayPosition  =
                new Vector3((float)this.Width / 2 - characterStart, (float)this.Height / 2, 0f);
            int         digit;
            NixieSprite nixie = new NixieSprite(nixiesTileSet);

            //Render the level indicator
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            device.BeginScene();
            using (D3D.Sprite d3dSprite = new D3D.Sprite(device)) {
                d3dSprite.Begin(D3D.SpriteFlags.AlphaBlend);

                //Show the letter L
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.L, displayPosition);

                //Show the letter E
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.E, displayPosition);

                //Show the letter V
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.V, displayPosition);

                //Show the letter E
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.E, displayPosition);

                //Show the letter L
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.L, displayPosition);

                displayPosition.X = (float)this.Width / 2 + 40;
                for (int digitCount = 1; digitCount <= maxLevelDigits; digitCount++)
                {
                    digit  = level % 10;
                    level /= 10;
                    nixie.Draw(d3dSprite, (NixieSprite.NixieCharacters)digit, displayPosition);
                    displayPosition.X -= characterSpacing;
                }
                d3dSprite.End();
            }
            device.EndScene();
            device.Present();
            Thread.Sleep(3000); //wait for 3 seconds
        }
        /// <summary>
        /// Ends the Sprite (MUST be called between DeviceBegin() and DeviceEnd()!).
        /// </summary>
        /// <returns>true if successful, false otherwise.</returns>
        public bool SpriteEnd()
        {
            if (sprite == null)
            {
                return(false);
            }

            try
            {
                sprite.End();
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to end sprite scene.", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            return(true);
        }
Exemple #8
0
        public void WriteScore(D3D.Device device, int score)
        {
            Rectangle nixiePosition = new Rectangle(nixiesTileSet.XOrigin, nixiesTileSet.YOrigin, nixiesTileSet.ExtentX * 2, nixiesTileSet.ExtentY * 2);
            int       digit;

            using (D3D.Sprite d3dSprite = new D3D.Sprite(device)) {
                d3dSprite.Begin(D3D.SpriteFlags.AlphaBlend);
                for (int digitCount = 1; digitCount <= maxScoreDigits; digitCount++)
                {
                    digit           = score % 10;
                    score          /= 10;
                    nixiePosition.X = nixiesTileSet.XOrigin + (digit % nixiesTileSet.NumberFrameColumns) * nixiesTileSet.ExtentX * 2;
                    nixiePosition.Y = nixiesTileSet.YOrigin; //we know it's only one row
                    Vector3 position = new Vector3((float)this.Width / 2 - digitCount * nixiesTileSet.ExtentX * 2,
                                                   (float)this.Height - 60f, 0f);
                    d3dSprite.Draw(nixiesTileSet.Texture, nixiePosition,
                                   new Vector3(), position, Color.FromArgb(255, 255, 255, 255));
                }
                d3dSprite.End();
            }
        }
        //绘画图片
        public bool DrawImage(Device pD3DDevice, CPoint ptRotationOffset, double fRadian, char chDirection, int nXDest, int nYDest, int nDestWidth, int nDestHeight, int nXSource, int nYSource, int nSourceWidth, int nSourceHeight, int cbAlpha)
        {
            if (_Sprite == null)
            {
                return(false);
            }

            if (fRadian == FishDefine.M_PI)
            {
                float degrees1 = (float)(fRadian * (180 / FishDefine.M_PI));
            }

            float degrees = (float)(fRadian * (180 / FishDefine.M_PI));

            Rectangle srcRectangle = new Rectangle(nXSource, nYSource, nSourceWidth, nSourceHeight);

            //Color color = Color.FromArgb( cbAlpha, Color.White );

            _Sprite.Begin(SpriteFlags.SortTexture | SpriteFlags.AlphaBlend);
            //sprite.Draw(_Texture, srcRectangle, Vector3.Empty, new Vector3(nXDest, nYDest, 0), cbAlpha );

            //_Sprite.Transform = Matrix.Scaling((float)nDestWidth / nSourceWidth, (float)nDestHeight / nSourceHeight, 0.0f);

            _Sprite.Transform = Matrix.RotationZ((float)-fRadian) * Matrix.Scaling((float)nDestWidth / nSourceWidth, (float)nDestHeight / nSourceHeight, 0.0f) * Matrix.Translation(nXDest, nYDest, 0);

            _Sprite.Draw(_Texture, srcRectangle, new Vector3(ptRotationOffset.x, ptRotationOffset.y, 0), new Vector3(0, 0, 0), Color.FromArgb(cbAlpha, Color.White).ToArgb());

            //_Sprite.Draw(_Texture, Vector3.Empty, new Vector3(nXDest, nYDest, 0), Color.White.ToArgb());
            _Sprite.End();

            //sprite.Begin(SpriteFlags.None);
            //sprite.Draw2D(_Texture, Rectangle.Empty, Rectangle.Empty,
            //              new Point(5, 5), Color.White);
            //sprite.End();

            return(true);
        }
        public void DisplayLevel(int level)
        {
            int characterStart = 30;
            int characterSpacing = 15;
            Vector3 displayPosition =
                new Vector3((float)this.Width/2 - characterStart, (float)this.Height/2, 0f);
            int digit;
            NixieSprite nixie = new NixieSprite(nixiesTileSet);

            //Render the level indicator
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            device.BeginScene();
            using (D3D.Sprite d3dSprite = new D3D.Sprite(device)) {
                d3dSprite.Begin(D3D.SpriteFlags.AlphaBlend);

                //Show the letter L
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.L, displayPosition);

                //Show the letter E
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.E, displayPosition);

                //Show the letter V
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.V, displayPosition);

                //Show the letter E
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.E, displayPosition);

                //Show the letter L
                displayPosition.X -= characterSpacing;
                nixie.Draw(d3dSprite, NixieSprite.NixieCharacters.L, displayPosition);

                displayPosition.X = (float)this.Width/2 + 40;
                for (int digitCount = 1; digitCount <= maxLevelDigits; digitCount++) {
                    digit = level % 10;
                    level /= 10;
                    nixie.Draw(d3dSprite, (NixieSprite.NixieCharacters)digit, displayPosition);
                    displayPosition.X -= characterSpacing;
                }
                d3dSprite.End();
            }
            device.EndScene();
            device.Present();
            Thread.Sleep(3000); //wait for 3 seconds
        }
 public void WriteScore(D3D.Device device, int score)
 {
     Rectangle nixiePosition = new Rectangle(nixiesTileSet.XOrigin,nixiesTileSet.YOrigin,nixiesTileSet.ExtentX*2,nixiesTileSet.ExtentY*2);
     int digit;
     using (D3D.Sprite d3dSprite = new D3D.Sprite(device)) {
         d3dSprite.Begin(D3D.SpriteFlags.AlphaBlend);
         for (int digitCount = 1; digitCount <= maxScoreDigits; digitCount++) {
             digit = score % 10;
             score /= 10;
             nixiePosition.X = nixiesTileSet.XOrigin + ( digit % nixiesTileSet.NumberFrameColumns ) * nixiesTileSet.ExtentX*2;
             nixiePosition.Y = nixiesTileSet.YOrigin; //we know it's only one row
             Vector3 position = new Vector3((float)this.Width/2 - digitCount*nixiesTileSet.ExtentX*2,
                 (float)this.Height-60f, 0f);
             d3dSprite.Draw(nixiesTileSet.Texture, nixiePosition,
                 new Vector3(), position, Color.FromArgb(255,255,255,255));
         }
         d3dSprite.End();
     }
 }
Exemple #12
0
        void Draw(Device device)
        {
            try
            {
                System.Drawing.Rectangle rect;
                // start drawing commands
                device.BeginScene();


                // Demonstration 1
                // Draw a simple line using DrawText
                // Pass in DrawTextFormat.NoClip so we don't have to calc
                // the bottom/right of the rect

                font1.DrawText(null,
                               "This is a trivial call to Font.DrawText",
                               new System.Drawing.Rectangle(5, 150, 0, 0),
                               DrawTextFormat.NoClip, System.Drawing.Color.Red);


                // Demonstration 2
                // Allow multiple draw calls to sort by texture changes
                // by Sprite When drawing 2D text use flags:
                // SpriteFlags.AlphaBlend | SpriteFlags.SortTexture.

                textDrawerSprite.Begin(SpriteFlags.AlphaBlend |
                                       SpriteFlags.SortTexture);

                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 6, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "These are multiple calls to Font.DrawText()",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 5, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "using the same Sprite. The font now caches",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 4, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "letters on one or more textures. In order",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 3, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "to sort by texturestate changes on multiple",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 2, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "calls to DrawText() pass a Sprite and use flags",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 1, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "SpriteFlags.AlphaBlend | SpriteFlags.SortTexture",
                               rect, DrawTextFormat.NoClip, Color.White);

                textDrawerSprite.End();

                // Demonstration 3:
                // Word wrapping and unicode text.
                // Note that not all fonts support dynamic font linking.
                System.Drawing.Rectangle rc =
                    new System.Drawing.Rectangle(10, 35,
                                                 this.screenwidth - 30, this.screenheight - 10);

                font2.DrawText(null, bigText, rc,
                               DrawTextFormat.Left | DrawTextFormat.WordBreak |
                               DrawTextFormat.ExpandTabs,
                               System.Drawing.Color.CornflowerBlue);

                // write the fps
                //fpsTimer.Render();
                OnRender( );
            }

            finally
            {
                // end the drawing commands and copy to screen
                device.EndScene();
                device.Present();
                //fpsTimer.StopFrame();
            }


            sprite.Begin(SpriteFlags.None);
            sprite.Draw(texture,
                        new Rectangle(0, 0, 512, 512),
                                                          //new Vector2( 1.0f, 1.0f ), // scaling
                        new Vector3(256.0f, 256.0f, 0.0f) //rotation center
                                                          //,0.0f // rogateion
                        , new Vector3(0.0f, 0.0f, 0.0f)   // translation
                        , Color.White                     // color
                        );
            sprite.End();
        }
 public void Draw(D3D.Device device)
 {
     using (D3D.Sprite d3dSprite = new D3D.Sprite(device)) {
         d3dSprite.Begin(D3D.SpriteFlags.AlphaBlend);
         foreach (BasicSprite sprite in sprites) {
             sprite.Draw(d3dSprite);
         }
         d3dSprite.End();
     }
 }
Exemple #14
0
 /// <summary>
 ///     Call this method after drawing.
 /// </summary>
 public void EndDrawSprite()
 {
     DxSprite.End();
 }
Exemple #15
0
 public void draw_string(Point pt, string s, Color color)
 {
     sprite_.Begin(SpriteFlags.SortTexture | SpriteFlags.AlphaBlend);
     d3dFont_.DrawText(sprite_, s, (int)pt.x_, (int)pt.y_, System.Drawing.Color.FromArgb(color.red_, color.green_, color.blue_));
     sprite_.End();
 }
Exemple #16
0
 /// <summary>
 /// Finalizar render de Sprites
 /// </summary>
 public void endDrawSprite()
 {
     dxSprite.End();
 }