コード例 #1
0
        protected override void Draw(GameTime gameTime)
        {
            if (fLines != null)
            {
                if (fAngleChanged)
                {
                    fAngleChanged = false;

                    fWorldMatrix = Matrix.CreateRotationZ(fAngle) *
                                   Matrix.CreateTranslation(
                        GraphicsDevice.Viewport.Width / 2f,
                        GraphicsDevice.Viewport.Height / 2f, 0);
                }
                fBasicEffect.World = fWorldMatrix;

                fLines.UseVertexBuffer = fUseVertexBuffer;

                foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    fLines.Render();
                }
            }
            base.Draw(gameTime);
        }
コード例 #2
0
ファイル: Gravity3Engine.cs プロジェクト: Warnestam/MonoGUI
        /// <summary>
        /// Draw the space
        /// </summary>
        private void RenderGrid()
        {
            fLines = new DynamicPrimitiveLine(GraphicsDevice);

            float worldFactor = WORLD_SIZE / (WORLD_BLOCKS - 1);
            VertexPositionColor p1;
            VertexPositionColor p2;

            for (int x = 0; x < WORLD_BLOCKS; x++)
            {
                float sx1 = (x + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                for (int y = 0; y < WORLD_BLOCKS; y++)
                {
                    float sy1 = (y + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                    for (int z = 0; z < WORLD_BLOCKS; z++)
                    {
                        float sz1 = (z + 0.5f) * worldFactor - HALF_WORLD_SIZE;

                        float   dx    = 1024 * (fSpace[x, y, z].ForcePositiveX - fSpace[x, y, z].ForceNegativeX);
                        float   dy    = 1024 * (fSpace[x, y, z].ForcePositiveY - fSpace[x, y, z].ForceNegativeY);
                        float   dz    = 1024 * (fSpace[x, y, z].ForcePositiveZ - fSpace[x, y, z].ForceNegativeZ);
                        Vector3 d     = new Vector3(dx, dy, dz);
                        float   power = d.Length() / 1000000;
                        if (power > 0)
                        {
                            d.Normalize();
                            if (power > 200)
                            {
                                power = 200;
                            }

                            dx = d.X * power;
                            dy = d.Y * power;
                            dz = d.Z * power;

                            float sx2 = sx1 + dx;
                            float sy2 = sy1 + dy;
                            float sz2 = sz1 + dz;
                            int   r   = (int)(255f * Math.Abs(d.X));
                            int   g   = (int)(255f * Math.Abs(d.Y));
                            int   b   = (int)(255f * Math.Abs(d.Z));
                            Color c1  = new Color(r, g, b);
                            Color c2  = Color.Transparent;
                            p1 = new VertexPositionColor(new Vector3(sx1, sy1, sz1), c1);
                            p2 = new VertexPositionColor(new Vector3(sx2, sy2, sz2), c2);
                            fLines.AddLine(p1, p2);
                        }
                    }
                }
            }
            fBasicEffect.World      = fCamera.Camera.WorldMatrix;
            fBasicEffect.View       = fCamera.Camera.ViewMatrix;
            fBasicEffect.Projection = fCamera.Camera.ProjectionMatrix;
            foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                fLines.Render();
            }
        }
コード例 #3
0
        /// <summary>
        /// Allows the game component to draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            fBasicEffect.World = fWorldMatrix;
            foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                fLines.Render();
            }
            base.Draw(gameTime);
        }
コード例 #4
0
        /// <summary>
        /// Render to a render target
        /// </summary>
        /// <param name="gameTime"></param>
        private void CreateRenderTarget(GameTime gameTime)
        {
            RenderTargetBinding[] previousRenderTargets = GraphicsDevice.GetRenderTargets();

            GraphicsDevice.SetRenderTarget(fTarget);
            GraphicsDevice.Clear(Color.Transparent);

            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.RasterizerState   = RasterizerState.CullNone;
            GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap;

            float  aspectRatio = ((float)GraphicsDevice.Viewport.Width) / ((float)GraphicsDevice.Viewport.Height);
            Matrix modelWorld  = Matrix.CreateRotationY(fPlaneAngle) *
                                 Matrix.CreateRotationX(MathHelper.ToRadians(90));
            Matrix modelProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), aspectRatio, 1.0f, 30000.0f);
            Matrix modelView       = Matrix.CreateLookAt(new Vector3(0, 0, 4000), Vector3.Zero, Vector3.Up);

            foreach (ModelMesh mesh in fModelGrid.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.View       = modelView;
                    effect.Projection = fCamera.Camera.ProjectionMatrix;
                    effect.World      = modelWorld;
                }
                mesh.Draw();
            }

            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap;

            Matrix view = Matrix.CreateLookAt(
                new Vector3(0.0f, 0.0f, 1.0f),
                Vector3.Zero, Vector3.Up
                );

            Matrix projection = Matrix.CreateOrthographicOffCenter(
                0, TARGET_WIDTH, TARGET_HEIGHT, 0, 1.0f, 1000.0f);


            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.RasterizerState   = RasterizerState.CullNone;
            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap;

            fLineEffect.World              = Matrix.Identity;
            fLineEffect.Projection         = projection;
            fLineEffect.View               = view;
            fLineEffect.VertexColorEnabled = true;
            fLineEffect.CurrentTechnique.Passes[0].Apply();

            fLines.Render();
            fSpriteBatch.Begin();
            string  text     = DateTime.Now.ToString("HH:mm:ss");
            Vector2 size     = fFont.MeasureString(text);
            Vector2 position = new Vector2(TARGET_WIDTH / 2 - size.X / 2, TARGET_HEIGHT / 2 - size.Y / 2);

            fSpriteBatch.DrawString(fFont, text, position, Color.Cornsilk);


            fSpriteBatch.End();


            GraphicsDevice.SetRenderTargets(previousRenderTargets);
        }
コード例 #5
0
ファイル: Gravity2Engine.cs プロジェクト: Warnestam/MonoGUI
        /// <summary>
        /// Draw the space
        /// </summary>
        private void RenderGrid()
        {
            fLines = new DynamicPrimitiveLine(fSpriteBatch.GraphicsDevice);
            float worldFactor = WORLD_SIZE / (WORLD_BLOCKS - 1);

            for (int x = 0; x < WORLD_BLOCKS; x++)
            {
                //int blockX = (int)((particle.Position.X + HALF_WORLD_SIZE) * PARTICLE_TO_WORLD);
                //int blockY = (int)((particle.Position.Y + HALF_WORLD_SIZE) * PARTICLE_TO_WORLD);
                float sx1 = (x + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                for (int y = 0; y < WORLD_BLOCKS; y++)
                {
                    float sy1 = (y + 0.5f) * worldFactor - HALF_WORLD_SIZE;
                    float dx  = 1024 * 1024 * 1024 * (fSpace[x, y].ForceRight - fSpace[x, y].ForceLeft);
                    float dy  = 1024 * 1024 * 1024 * (fSpace[x, y].ForceUp - fSpace[x, y].ForceDown);
                    float f   = Convert.ToSingle(Math.Sqrt(dx * dx + dy * dy));
                    float f1  = f;
                    Color c1;
                    Color c2;
                    int   b1;
                    float size = 1.0f;
                    if (f1 < 1024.0f)
                    {
                        size = f1 / 1024.0f;
                        b1   = (byte)(f1 / 4.0f);
                        c1   = new Color(0, 0, b1, 255);
                        c2   = new Color(0, 0, b1, 255);
                    }
                    else
                    {
                        f1 /= 1024.0f;
                        if (f1 < 1024.0f)
                        {
                            size = 1.0f;// 0.5f + f1 / 512.0f;
                            b1   = (byte)(f1 / 4.0f);
                            c1   = new Color(0, b1, 255 - b1, 255);
                            c2   = new Color(0, 255, 0, 128);
                        }
                        else
                        {
                            f1 /= 1024.0f;
                            if (f1 < 1024.0f)
                            {
                                size = 1.0f;//0.5f + f1 / 512.0f;
                                b1   = (byte)(f1 / 4.0f);
                                c1   = new Color(b1, 255, 0, 255);
                                c2   = new Color(255, 255, 0, 128);
                            }
                            else
                            {
                                f1 /= 1024.0f;
                                if (f1 < 1024.0f)
                                {
                                    size = 1.0f;//0.5f + f1 / 512.0f;
                                    b1   = (byte)(f1 / 4.0f);
                                    c1   = new Color(255, 255 - b1, 0, 255);
                                    c2   = new Color(255, 0, 0, 128);
                                }
                                else
                                {
                                    size = 1.0f;
                                    c1   = new Color(255, 0, 255, 255);
                                    c2   = new Color(255, 0, 255, 255);
                                }
                            }
                        }
                    }

                    dx = MAX_LINE_SIZE * (dx / f) * size;
                    dy = MAX_LINE_SIZE * (dy / f) * size;
                    float sx2 = sx1 + dx;
                    float sy2 = sy1 + dy;
                    VertexPositionColor p1 = new VertexPositionColor(new Vector3(sx1, sy1, 0), c1);
                    VertexPositionColor p2 = new VertexPositionColor(new Vector3(sx2, sy2, 0), c2);
                    fLines.AddLine(p1, p2);
                }
            }
            fBasicEffect.World      = fCamera.Camera.WorldMatrix;
            fBasicEffect.View       = fCamera.Camera.ViewMatrix;
            fBasicEffect.Projection = fCamera.Camera.ProjectionMatrix;


            foreach (EffectPass pass in fBasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                fLines.Render();
            }
        }