Пример #1
0
        public void Draw(Effect effect)
        {
            //device.SetVertexBuffer<VertexPositionNormalTexture>(vertexBuffer);
            //device.SetVertexInputLayout(inputLayout);

            primitive.Draw(effect);
        }
        public override void Draw(GameTime gameTime)
        {
            // If no TargetViewPort specified GraphicsDevice.AutoViewportFromRenderTargets has already set the correct viewport based on the size of the rendertarget
            if (TargetViewport.Width > 0 && TargetViewport.Height > 0)
            {
                GraphicsDevice.SetViewport(TargetViewport);
            }

            if (Holographic)
            {
                GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Additive);
            }
            else
            {
                GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);
            }

            GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.Default);
            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullFront);

            PrepareEffectParameters();

            _geometry.Draw(_roomAliveEffect);

            base.Draw(gameTime);
        }
Пример #3
0
        private void drawGuideLines(int number)
        {
            if (number < 3)
            {
                number = 3;
            }

            float y      = 0.0f;
            float deltaY = (float)1 / (number - 1);

            for (int i = 0; i < number; i++)
            {
                basicEffect.World = Matrix.Scaling(graphicsDevice.BackBuffer.Width, 0.0f, 0.022f) *
                                    Matrix.RotationX(deg2rad(90.0f)) *
                                    Matrix.RotationY(0) *
                                    Matrix.RotationZ(0) *
                                    Matrix.Translation(screenToWorld(new Vector3(0.0f, y, 0.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport)
                                                       + new Vector3(0, 0, 0.001f));

                basicEffect.DiffuseColor = new Color4(0.2f, 0.2f, 0.2f, 0.2f);
                guideLine.Draw(basicEffect);

                y += deltaY;
            }
        }
Пример #4
0
        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            // Clear screen
            GraphicsContext.CommandList.Clear(GraphicsDevice.Presenter.BackBuffer, Color.CornflowerBlue);
            GraphicsContext.CommandList.Clear(GraphicsDevice.Presenter.DepthStencilBuffer,
                                              DepthStencilClearOptions.DepthBuffer | DepthStencilClearOptions.Stencil);

            // Set render target
            GraphicsContext.CommandList.SetRenderTargetAndViewport(GraphicsDevice.Presenter.DepthStencilBuffer,
                                                                   GraphicsDevice.Presenter.BackBuffer);

            var time = (float)gameTime.Total.TotalSeconds;

            // Compute matrices
            var world = Matrix.Scaling((float)Math.Sin(time * 1.5f) * 0.2f + 1.0f)
                        * Matrix.RotationX(time)
                        * Matrix.RotationY(time * 2.0f)
                        * Matrix.RotationZ(time * .7f)
                        * Matrix.Translation(0, 0, 0);
            var projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f,
                                                     (float)GraphicsDevice.Presenter.BackBuffer.ViewWidth / GraphicsDevice.Presenter.BackBuffer.ViewHeight,
                                                     0.1f, 100.0f);

            // Setup effect/shader
            simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, Matrix.Multiply(world, Matrix.Multiply(view, projection)));
            simpleEffect.UpdateEffect(GraphicsDevice);

            // Draw
            teapot.Draw(GraphicsContext, simpleEffect);
        }
Пример #5
0
 private void DrawSky()
 {
     _skyProjection = Matrix.PerspectiveFovLH(MathUtil.PiOverFour, GraphicsDevice.Viewport.AspectRatio, 0.01f, 1.0f);
     _skyBoxEffect.Parameters["ViewProj"].SetValue(_view * _skyProjection);
     _skyBoxEffect.Parameters["CubeMap"].SetResource(_skyBoxMap);
     _skyBox.Draw(_skyBoxEffect);
 }
Пример #6
0
        void DrawPlane(Camera camera)
        {
            var device = this.GraphicsDevice;

            m_basicEffect.World      = Matrix.Identity;
            m_basicEffect.View       = Matrix.Identity;
            m_basicEffect.Projection = Matrix.Identity;

            m_basicEffect.TextureEnabled     = false;
            m_basicEffect.VertexColorEnabled = false;

            m_basicEffect.Alpha        = 0.8f;
            m_basicEffect.DiffuseColor = new Vector4(1f, 1f, 1f, 1);

            device.SetBlendState(device.BlendStates.NonPremultiplied);

            device.SetDepthStencilState(device.DepthStencilStates.None);
            device.SetRasterizerState(device.RasterizerStates.CullNone);

            m_basicEffect.CurrentTechnique.Passes[0].Apply();
            m_plane.Draw(m_basicEffect);

            device.SetBlendState(device.BlendStates.Default);
            device.SetRasterizerState(device.RasterizerStates.Default);
            device.SetDepthStencilState(device.DepthStencilStates.Default);
        }
Пример #7
0
        public override void Draw(Camera camera)
        {
            m_basicEffect.View       = Matrix.Translation(0, 0, 10);
            m_basicEffect.Projection = camera.Projection;

            m_basicEffect.Texture = m_cubeTexture;
            m_basicEffect.World   = m_cubeTransform;
            m_cube.Draw(m_basicEffect);
        }
Пример #8
0
 public void Draw(Matrix view, Matrix projection)
 {
     if (draw)
     {
         effect.View       = view;
         effect.Projection = projection;
         anchorBody.Draw(effect);
     }
 }
Пример #9
0
        protected override void OnRendering(RenderContext context)
        {
            var entitySystem           = Services.GetServiceAs <EntitySystem>();
            var cubemapSourceProcessor = entitySystem.GetProcessor <CubemapSourceProcessor>();

            if (cubemapSourceProcessor == null)
            {
                return;
            }

            // clear render target
            if (clearTarget)
            {
                GraphicsDevice.Clear(IBLRenderTarget, new Color4(0, 0, 0, 0));
            }

            // if no cubemap, exit
            if (cubemapSourceProcessor.Cubemaps.Count <= 0)
            {
                return;
            }

            // set render target
            GraphicsDevice.SetDepthAndRenderTarget(readOnlyDepthBuffer, IBLRenderTarget);

            // set depth state
            GraphicsDevice.SetDepthStencilState(IBLDepthStencilState);

            // set culling
            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullFront);

            // set blend state
            GraphicsDevice.SetBlendState(IBLBlendState);

            foreach (var cubemap in cubemapSourceProcessor.Cubemaps)
            {
                // set world matrix matrices
                // TODO: rotation of cubemap & cube mesh
                parameters.Set(TransformationKeys.World, ComputeTransformationMatrix(cubemap.Value.InfluenceRadius, cubemap.Key.Transformation.Translation));
                parameters.Set(CubemapIBLBaseKeys.CubemapRadius, cubemap.Value.InfluenceRadius);
                parameters.Set(CubemapIBLBaseKeys.Cubemap, cubemap.Value.Texture);
                parameters.Set(CubemapIBLBaseKeys.CubemapPosition, cubemap.Key.Transformation.Translation);

                // apply effect
                IBLEffect.Apply(parameters, context.CurrentPass.Parameters);

                // render cubemap
                cubemapMesh.Draw(GraphicsDevice);
            }

            IBLEffect.UnbindResources();

            // TODO: revert to correct old settings
            GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);
            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullBack);
            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);
        }
Пример #10
0
 public override void Draw(GameTime gameTime)
 {
     if (model != null)
     {
         model.Draw(Matrix.CreateTranslation(position), mygame.viewMatrix, mygame.projectionMatrix);
     }
     else if (primitiveModel != null)
     {
         if (texture != null)
         {
             primitiveModel.Draw(Matrix.CreateTranslation(position), mygame.viewMatrix, mygame.projectionMatrix, texture, alpha);
         }
         else
         {
             primitiveModel.Draw(Matrix.CreateTranslation(position), mygame.viewMatrix, mygame.projectionMatrix, color);
         }
     }
 }
        /// <summary>
        ///     Draw the geometry applying a rotation and translation.
        /// </summary>
        /// <param name="geometry">The geometry to draw.</param>
        /// <param name="transform">The transform to apply.</param>
        private void DrawGeometry(GeometricPrimitive geometry, Matrix transform)
        {
            var effect = geometry.Effect;

            effect.World      = transform;
            effect.View       = Camera.View;
            effect.Projection = Camera.Projection;

            geometry.Draw(effect);
        }
        /// <summary>
        ///     Draw the geometry applying a rotation and translation.
        /// </summary>
        /// <param name="geometry">The geometry to draw.</param>
        /// <param name="position">The position of the geometry.</param>
        /// <param name="yaw">Vertical axis (yaw).</param>
        /// <param name="pitch">Transverse axis (pitch).</param>
        /// <param name="roll">Longitudinal axis (roll).</param>
        private void DrawGeometry(GeometricPrimitive geometry, Vector3 position, float yaw, float pitch, float roll)
        {
            var effect = geometry.Effect;

            effect.World      = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll) * Matrix.CreateTranslation(position);
            effect.View       = Camera.View;
            effect.Projection = Camera.Projection;

            geometry.Draw(effect);
        }
Пример #13
0
 private void drawPoint(Vector3 pos, Vector4 col)
 {
     basicEffect.World = Matrix.Scaling(0.3f, 0.02f, 0.3f) *
                         Matrix.RotationX(deg2rad(90.0f)) *
                         Matrix.RotationY(0) *
                         Matrix.RotationZ(0) *
                         Matrix.Translation(screenToWorld(pos, basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport));
     basicEffect.DiffuseColor = col;
     primitive.Draw(basicEffect);
 }
Пример #14
0
        public void Draw(GraphicsDevice context, Matrix view, Matrix projection)
        {
            if (_effect == null)
            {
                OnLoad(context);
            }

            var rotation = _gyroscope.GetRotation();

            _effect.World      = Matrix.RotationYawPitchRoll(rotation.X, rotation.Y, rotation.Z) * Matrix.Translation(_gyroscope.GetPosition() * 0.0001f);
            _effect.View       = view;
            _effect.Projection = projection;
            _primitive.Draw(_effect);
        }
Пример #15
0
        /// <summary>
        /// Draw the scene content.
        /// </summary>
        /// <param name="gameTime">Structure containing information about elapsed game time.</param>
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            // set the parameters for cube drawing and draw it using the basic effect
            _basicEffect.Texture = _cubeTexture;
            _basicEffect.World   = _cubeTransform;
            _cube.Draw(_basicEffect);

            // set the parameters for plane drawing and draw it using the basic effect
            _basicEffect.Texture = _planeTexture;
            _basicEffect.World   = _planeTransform;
            _plane.Draw(_basicEffect);
        }
Пример #16
0
        public override void Draw(Camera camera)
        {
            m_basicEffect.View       = camera.View;
            m_basicEffect.Projection = camera.Projection;

            var chunks = m_chunkManager.DebugChunks;

            m_basicEffect.Texture = m_cubeTexture;

            var device = this.GraphicsDevice;

            device.SetBlendState(device.BlendStates.NonPremultiplied);

            device.SetRasterizerState(m_rasterizerState);

            foreach (var cp in m_chunkManager.Size.Range())
            {
                var chunk = chunks[m_chunkManager.Size.GetIndex(cp)];
                if (chunk == null)
                {
                    continue;
                }

                if (chunk.IsAllEmpty)
                {
                    m_basicEffect.DiffuseColor = new Vector4(1, 0, 0, 0);
                }
                else if (chunk.IsAllUndefined)
                {
                    m_basicEffect.DiffuseColor = new Vector4(0, 1, 0, 0);
                }
                else
                {
                    m_basicEffect.DiffuseColor = new Vector4(1, 1, 1, 0);
                }

                m_basicEffect.World = Matrix.Translation((cp * Chunk.CHUNK_SIZE + Chunk.CHUNK_SIZE / 2).ToVector3());
                m_cube.Draw(m_basicEffect);
            }

            device.SetRasterizerState(device.RasterizerStates.Default);
            device.SetBlendState(device.BlendStates.Default);
        }
Пример #17
0
        protected override void Draw(GameTime gameTime)
        {
            _graphicsDeviceManager.GraphicsDevice.Clear(Color.CornflowerBlue);

            // if the effect is loaded...
            if (_effect != null)
            {
                // update cube rotation
                var rot = Matrix.RotationY((float)gameTime.TotalGameTime.TotalSeconds);

                // set the parameters
                _effect.Parameters[0].SetValue(rot * _world * _view * _projection);

                // draw cube
                _cubeGeometry.Draw(_effect);
            }

            base.Draw(gameTime);
        }
Пример #18
0
        protected virtual void Draw_BaslerCamera(GameTime _gameTime)
        {
            lock (cameraTextureList_locker)
            {
                lock (textureSizedBuffer_locker)
                {
                    cameraBasicEffect.Texture = cameraTexture;
                    var time = (float)gameTime.TotalGameTime.TotalSeconds;

                    cameraBasicEffect.Projection = eyeProjection;
                    cameraBasicEffect.View       = eyeView;

                    cameraBasicEffect.World = ra.cameraSurfaceWorld; //* Matrix.Translation(config.player.scout.Position);
                    cameraBasicEffect.World.Invert();
                    //cameraBasicEffect.World = Matrix.Identity ;

                    // Draw the primitive using BasicEffect
                    cameraSurface.Draw(cameraBasicEffect);
                }
            }
        }
        /// <summary>
        /// Draws component.
        /// </summary>
        /// <param name="caller">Entity calling the draw operation.</param>
        public override void Draw(BaseEntity caller)
        {
            // Do nothing if disabled
            if (!enabled)
            {
                return;
            }

            // Calculate world matrix
            Matrix worldMatrix = matrix * caller.Matrix;

            // Set technique
            renderGeometryEffect.CurrentTechnique = renderGeometryEffect.Techniques["Diffuse"];

            // Update effect
            renderGeometryEffect.Parameters["World"].SetValue(worldMatrix);
            renderGeometryEffect.Parameters["View"].SetValue(core.ActiveScene.Camera.ViewMatrix);
            renderGeometryEffect.Parameters["Projection"].SetValue(core.ActiveScene.Camera.ProjectionMatrix);
            renderGeometryEffect.Parameters["DiffuseColor"].SetValue(color);

            // Draw primitive
            primitive.Draw(renderGeometryEffect);
        }
Пример #20
0
        public void DrawFloors(GraphicsDevice GraphicsDevice, Matrix viewMatrix, Matrix projectionMatrix, Effect floorEffect, GeometricPrimitive plane)
        {
            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullNone);
            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.NonPremultiplied);

            Matrix worldMatrix;

            for (int wx = 0; wx < level.Width; wx++)
            {
                for (int wy = 0; wy < level.Height; wy++)
                {
                    worldMatrix = Matrix.Translation(wx * 5, wy * 5, 0);

                    Matrix worldView     = Matrix.Multiply(worldMatrix, viewMatrix);
                    Matrix worldViewProj = Matrix.Multiply(worldView, projectionMatrix);
                    floorEffect.Parameters["WorldViewProj"].SetValue(worldViewProj);

                    foreach (var floor in level.floors)
                    {
                        var tile = floor[wx + (wy * level.Width)];

                        if (tile.prop1 != 0)
                        {
                            int main_index = (tile.prop3 >> 4) + ((tile.prop4 & 0x03) << 4);
                            int sub_index  = tile.prop2;

                            int  dt1idx = 0;
                            bool found  = false;
                            for (int i = 0; i < tiles.Count; i++)
                            {
                                var dt1 = tiles[i].File;

                                if (dt1 != null)
                                {
                                    for (int j = 0; j < dt1.FloorHeaders.Count; j++)
                                    {
                                        var item = dt1.FloorHeaders[j];
                                        if ((item.tile.Orientation == 0) &&
                                            (item.tile.MainIndex == main_index) &&
                                            (item.tile.SubIndex == sub_index)
                                            )
                                        {
                                            floorEffect.Parameters["Texture"].SetResource(tiles[i].FloorsTexture);
                                            dt1idx = j;
                                            found  = true;
                                            //break;
                                        }
                                    }
                                }

                                if (found)
                                {
                                    break;
                                }
                            }

                            int ti = dt1idx;

                            floorEffect.Parameters["TileIndex"].SetValue((float)ti);


                            floorEffect.Techniques[0].Passes[0].Apply();


                            plane.Draw(floorEffect);
                        }
                    }
                }
            }
        }
Пример #21
0
        private void DrawWall(D2.FileTypes.DS1File.CELL_W_S tile, int orientation, Effect floorEffect, GeometricPrimitive billboard)
        {
            if (tile.prop1 != 0)
            {
                int main_index = (tile.prop3 >> 4) + ((tile.prop4 & 0x03) << 4);
                int sub_index  = tile.prop2;

                int  dt1idx = 0;
                bool found  = false;
                for (int i = 0; i < tiles.Count; i++)
                {
                    var dt1 = tiles[i].File;

                    if (dt1 != null)
                    {
                        foreach (var item in dt1.WallHeaders
                                 //.OrderBy(x => x.tile.Orientation)
                                 //.ThenBy(x => x.tile.MainIndex)
                                 //.ThenBy(x => x.tile.SubIndex)
                                 //.ThenBy(x => x.tile.RarityFrameIndex)
                                 //.ThenBy(x => x.FloorWallIndex)
                                 )
                        {
                            if ((item.tile.Orientation == orientation) &&
                                (item.tile.MainIndex == main_index) &&
                                (item.tile.SubIndex == sub_index)
                                )
                            {
                                floorEffect.Parameters["Texture"].SetResource(tiles[i].WallsTexture);
                                dt1idx = item.FloorWallIndex;
                                found  = true;
                                //break;
                            }

                            if (orientation == 18 || orientation == 19)
                            {
                                if (orientation == 18)
                                {
                                    orientation = 19;
                                }
                                else
                                {
                                    orientation = 18;
                                }

                                if ((item.tile.Orientation == orientation) && (item.tile.MainIndex == main_index) && (item.tile.SubIndex == sub_index))
                                {
                                    floorEffect.Parameters["Texture"].SetResource(tiles[i].WallsTexture);
                                    dt1idx = item.FloorWallIndex;
                                    found  = true;
                                    //break;
                                }

                                sub_index = 0;
                                if ((item.tile.Orientation == orientation) && (item.tile.MainIndex == main_index) && (item.tile.SubIndex == sub_index))
                                {
                                    floorEffect.Parameters["Texture"].SetResource(tiles[i].WallsTexture);
                                    dt1idx = item.FloorWallIndex;
                                    found  = true;
                                    //break;
                                }
                            }
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }

                int ti = dt1idx;

                floorEffect.Parameters["TileIndex"].SetValue((float)ti);


                floorEffect.Techniques[0].Passes[0].Apply();


                billboard.Draw(floorEffect);
            }
        }
Пример #22
0
        protected override void Draw(GameTime gameTime)
        {
            // Use time in seconds directly
            var time = (float)gameTime.TotalGameTime.TotalSeconds;

            // Make offline rendering
            GraphicsDevice.SetRenderTargets(GraphicsDevice.DepthStencilBuffer, renderTargetOffScreen);

            // Clears the screen with the Color.CornflowerBlue
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Constant used to translate 3d models
            float translateX = 0.0f;

            // ------------------------------------------------------------------------
            // Draw the 3d model
            // ------------------------------------------------------------------------
            var world = Matrix.Scaling(0.003f) *
                        Matrix.RotationY(time) *
                        Matrix.Translation(0, -1.5f, 2.0f);

            model.Draw(GraphicsDevice, world, view, projection);
            translateX += 3.5f;

            // ------------------------------------------------------------------------
            // Draw the 3d primitive using BasicEffect
            // ------------------------------------------------------------------------
            basicEffect.World = Matrix.Scaling(2.0f, 2.0f, 2.0f) *
                                Matrix.RotationX(0.8f * (float)Math.Sin(time * 1.45)) *
                                Matrix.RotationY(time * 2.0f) *
                                Matrix.RotationZ(0) *
                                Matrix.Translation(translateX, -1.0f, 0);
            primitive.Draw(basicEffect);

            // ------------------------------------------------------------------------
            // Draw the some 2d text
            // ------------------------------------------------------------------------
            spriteBatch.Begin();
            var text = new StringBuilder("This text is displayed with SpriteBatch").AppendLine();

            List <Keys> keys = new List <Keys>();

            // Display pressed keys
            keyboardState.GetDownKeys(keys);
            text.Append("Key Pressed: [");
            foreach (var key in keys)
            {
                text.Append(key.ToString());
                text.Append(" ");
            }
            text.Append("]").AppendLine();

            // Display mouse coordinates and mouse button status
            text.AppendFormat("Mouse ({0},{1}) Left: {2}, Right {3}", mouseState.X, mouseState.Y, mouseState.LeftButton, mouseState.RightButton).AppendLine();

            spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White);
            spriteBatch.End();

            // ------------------------------------------------------------------------
            // Use SpriteBatch to draw some balls on the screen using NonPremultiplied mode
            // as the sprite texture used is not premultiplied
            // ------------------------------------------------------------------------
            spriteBatch.Begin(SpriteSortMode.Deferred, GraphicsDevice.BlendStates.NonPremultiplied);
            for (int i = 0; i < 40; i++)
            {
                var posX = (float)Math.Cos(time * 4.5f + i * 0.1f) * 60.0f + 136.0f;
                var posY = GraphicsDevice.BackBuffer.Height * 2.0f / 3.0f + 100.0f * (float)Math.Sin(time * 10.0f + i * 0.4f);

                spriteBatch.Draw(
                    ballsTexture,
                    new Vector2(posX, posY),
                    new Rectangle(0, 0, 32, 32),
                    Color.White,
                    0.0f,
                    new Vector2(16, 16),
                    Vector2.One,
                    SpriteEffects.None,
                    0f);
            }
            spriteBatch.End();

            // ------------------------------------------------------------------------
            // Cheap bloom post effect
            // Blur applied only on latest downscale render target
            // ------------------------------------------------------------------------

            // Setup states for posteffect
            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.Default);
            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);
            GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);

            // Apply BrightPass
            const float brightPassThreshold = 0.5f;

            GraphicsDevice.SetRenderTargets(renderTargetDownScales[0]);
            bloomEffect.CurrentTechnique = bloomEffect.Techniques["BrightPassTechnique"];
            bloomEffect.Parameters["Texture"].SetResource(renderTargetOffScreen);
            bloomEffect.Parameters["PointSampler"].SetResource(GraphicsDevice.SamplerStates.PointClamp);
            bloomEffect.Parameters["BrightPassThreshold"].SetValue(brightPassThreshold);
            GraphicsDevice.Quad.Draw(bloomEffect.CurrentTechnique.Passes[0]);

            // Down scale passes
            for (int i = 1; i < renderTargetDownScales.Length; i++)
            {
                GraphicsDevice.SetRenderTargets(renderTargetDownScales[i]);
                GraphicsDevice.Quad.Draw(renderTargetDownScales[0]);
            }

            // Horizontal blur pass
            var renderTargetBlur = renderTargetDownScales[renderTargetDownScales.Length - 1];

            GraphicsDevice.SetRenderTargets(renderTargetBlurTemp);
            bloomEffect.CurrentTechnique = bloomEffect.Techniques["BlurPassTechnique"];
            bloomEffect.Parameters["Texture"].SetResource(renderTargetBlur);
            bloomEffect.Parameters["LinearSampler"].SetResource(GraphicsDevice.SamplerStates.LinearClamp);
            bloomEffect.Parameters["TextureTexelSize"].SetValue(new Vector2(1.0f / renderTargetBlurTemp.Width, 1.0f / renderTargetBlurTemp.Height));
            GraphicsDevice.Quad.Draw(bloomEffect.CurrentTechnique.Passes[0]);

            // Vertical blur pass
            GraphicsDevice.SetRenderTargets(renderTargetBlur);
            bloomEffect.Parameters["Texture"].SetResource(renderTargetBlurTemp);
            GraphicsDevice.Quad.Draw(bloomEffect.CurrentTechnique.Passes[1]);

            // Render to screen
            GraphicsDevice.SetRenderTargets(GraphicsDevice.BackBuffer);
            GraphicsDevice.Quad.Draw(renderTargetOffScreen);

            // Add bloom on top of it
            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Additive);
            GraphicsDevice.Quad.Draw(renderTargetBlur);
            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);

            base.Draw(gameTime);
        }
Пример #23
0
 private void DrawGeometry()
 {
     simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, worldViewProjection);
     simpleEffect.Apply(GraphicsContext);
     geometry.Draw(GraphicsContext.CommandList, simpleEffect);
 }
Пример #24
0
        protected void Draw(GameTime gameTime)
        {
            var      time = (float)gameTime.TotalGameTime.TotalSeconds;
            TimeSpan tmp  = stopWatch.Elapsed;
            float    xTL  = (float)((tmp.TotalMilliseconds % 10000) / (float)(10000));

            // offline rendering
            graphicsDevice.SetRenderTargets(graphicsDevice.DepthStencilBuffer, graphicsDevice.BackBuffer);

            graphicsDevice.Clear(new Color4(0.316f, 0.451f, 0.473f, 1.0f));//Background color

            float aspectRatio = (float)graphicsDevice.BackBuffer.Width / graphicsDevice.BackBuffer.Height;

            Vector2 normalizedPos = normalizeVector2((Vector2)position);

            // -------- GRADIENT BACKGROUND ----------------
            float eltY = -0.02f;

            /*      float redY = bckgdTopColor[0];
             *    float greenY = bckgdTopColor[1];
             *    float blueY = bckgdTopColor[2];
             *    float deltaRed = gradientBckgdColor[0] / 55;
             *    float deltaGreen = gradientBckgdColor[1] / 55;
             *    float deltaBlue = gradientBckgdColor[2] / 55; */

            float redY   = 1.0f;
            float greenY = 1.0f;
            float blueY  = 1.0f;

            basicEffect.LightingEnabled = false;
            for (int i = 0; i < 55; i++)
            {
                eltY   += 0.02f;
                redY   -= 0.020f;
                greenY -= 0.020f; //22
                blueY  -= 0.020f; //18
                //  redY -= deltaRed;
                //  greenY -= deltaGreen;
                //  blueY -= deltaBlue;
                basicEffect.World = Matrix.Scaling(graphicsDevice.BackBuffer.Width, 0.05f, 0.2f) *
                                    Matrix.RotationX(deg2rad(90.0f)) *
                                    Matrix.RotationY(0) *
                                    Matrix.RotationZ(0) *
                                    Matrix.Translation(screenToWorld(new Vector3(0.0f, eltY, 0.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport)
                                                       + new Vector3(0, 0, 0.2f));

                basicEffect.DiffuseColor = new Color4(redY, greenY, blueY, 0.0f);
                backgroundElt.Draw(basicEffect);
            }
            basicEffect.LightingEnabled = true;
            // --------- END GRADIENT BACKGROUND -----------
            // ----- GUIDE LINES ------------------
            drawGuideLines(15);
            // ----- END GUIDE LINES --------------


            for (int i = 0; i < objects.Count; i++)
            {
                if (Math.Abs(objects[i].Position.X - xTL) <= 0.18 && objects[i].Position.X <= xTL + 0.006)
                {
                    instancedGeo.ModifyInstance(cylinder, objects[i].InstanceId, null, new Vector4((Vector3)pickColor((float)objects[i].Position.Y, objects[i].ObjectColor), 0.0f + (float)Math.Pow(Math.Abs(objects[i].Position.X - xTL) / 0.18f, 2.0) * 0.7f));       //(float)Math.Pow(1.0f-(Math.Abs(xTL-objects[i].Position.X))/xTL,4.0)));
                }
                else
                {
                    instancedGeo.ModifyInstance(cylinder, objects[i].InstanceId, null, new Vector4((Vector3)pickColor((float)objects[i].Position.Y, objects[i].ObjectColor), 0.7f));
                }


                //List<float> xs = new List<float>();
                //List<float> ys = new List<float>();

                //for (float x = objects[i][0].X; x <= objects[i][objects[i].Count - 1].X; x += pointFrequency)
                //{
                //    xs.Add(x);
                //}

                //if (xs.Count > 1)
                //{
                //    ys.AddRange(splines[i].Eval(xs.ToArray()));
                //}
                //else
                //{
                //    ys.Add(objects[i][0].Y);
                //}

                //for (int j = 0; j < xs.Count; j++)
                //{
                //    drawPoint(new Vector3(xs[j], ys[j], 5.0f), (Vector4)pickColor(ys[j]));
                //}
            }


            //if (currentPoints.Count > 0)
            //{
            //    List<Vector2> points = currentSpline.sample(pointFrequency);

            //    foreach (Vector2 p in points)
            //    {
            //        drawPoint(new Vector3(p, 5.0f), (Vector4)pickColor((float)p.Y));
            //    }

            //    //List<float> xs = new List<float>();
            //    //List<float> ys = new List<float>();

            //    //for (float x = currentPoints[0].X; x <= currentPoints[currentPoints.Count - 1].X; x += pointFrequency)
            //    //{
            //    //    xs.Add(x);
            //    //}

            //    //if (xs.Count > 1)
            //    //{
            //    //    ys.AddRange(currentSpline.Eval(xs.ToArray()));
            //    //}
            //    //else
            //    //{
            //    //    ys.Add(currentPoints[0].Y);
            //    //}

            //    //for (int j = 0; j < xs.Count; j++)
            //    //{
            //    //    drawPoint(new Vector3(xs[j], ys[j], 5.0f), (Vector4)pickColor(ys[j]));
            //    //}
            //}

            /*if (mouseState.left)//If we want to show that we are drawing
             *  //(this is more suitable for kinect interaction I think)
             * {
             *  basicEffect.World = Matrix.Scaling(0.5f, 0.05f, 0.5f) *
             *      Matrix.RotationX(deg2rad(90.0f)) *
             *      Matrix.RotationY(0) *
             *      Matrix.RotationZ(0) *
             *      Matrix.Translation(screenToWorld(new Vector3(normalizedPos, 5.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport) + new Vector3(0, 0, -0.200f));
             *  basicEffect.DiffuseColor = new Color4(255,255,255,255);
             *  primitive.Draw(basicEffect);
             * }*/


            for (int l = 0; l < currentPoints.Count; l++)
            {
                drawPoint(new Vector3(currentPoints[l], 5.0f), (Vector4)pickColor(currentPoints[l].Y, paletteColor));
            }


            /**PARTICLE DRAW********************************************************************/
            foreach (Particle p in pSystem.getList())
            {
                if (p.type == 4)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        Vector3 pos = new Vector3(p.getX() - (p.velocity.X * (k * 2)), p.getY() - (p.velocity.Y * (k * 2)), 5.0f);

                        // Glow effect ---------->
                        float glowSize  = 0.42f - k * 0.03f;
                        float deltaGlow = glowSize / 10;
                        for (int i = 0; i < 8; i++)
                        {
                            InstancedGeometricPrimitive.InstanceType glowT = new InstancedGeometricPrimitive.InstanceType();
                            glowT.World = Matrix.Scaling(glowSize, 0.02f, glowSize) *
                                          Matrix.RotationX(deg2rad(90)) *
                                          Matrix.RotationY(0) *
                                          Matrix.RotationZ(0) *
                                          Matrix.Translation(screenToWorld(pos, basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport)
                                                             + new Vector3(0, 0, 0.03f));

                            glowT.Color   = p.getColor();
                            glowT.Color.W = p.lifespan / 300.0f * (0.02f + i * i * 0.003f);

                            instancedGeo.AddToRenderPass(glowInstanced, glowT);

                            glowSize -= deltaGlow;
                        }

                        InstancedGeometricPrimitive.InstanceType t = new InstancedGeometricPrimitive.InstanceType();
                        t.World = Matrix.Scaling((0.08f - k * 0.01f), (0.08f - k * 0.01f), (0.08f - k * 0.01f)) *
                                  Matrix.RotationX(p.getRotationX()) *
                                  Matrix.RotationY(p.getRotationY()) *
                                  Matrix.RotationZ(p.getRotationZ()) *
                                  Matrix.Translation(screenToWorld(pos, basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport));
                        t.Color   = p.getColor();
                        t.Color.W = p.lifespan / 300.0f;

                        instancedGeo.AddToRenderPass(fwInstanced, t);

                        //  basicEffect.World = Matrix.Scaling((0.08f - k*0.01f), (0.08f - k*0.01f), (0.08f - k*0.01f)) *
                        //      Matrix.RotationX(p.getRotationX()) *
                        //      Matrix.RotationY(p.getRotationY()) *
                        //      Matrix.RotationZ(p.getRotationZ()) *
                        //      Matrix.Translation(screenToWorld(new Vector3(p.getX() - (p.velocity.X * (k*2)), p.getY() - (p.velocity.Y * (k*2)), 5.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport));

                        //  // Color4 color = p.getColor();
                        //  basicEffect.DiffuseColor = p.getColor(); //color;
                        ////  basicEffect.Alpha = p.lifespan;
                        //  fireWork.Draw(basicEffect);
                        //  basicEffect.Alpha = 1.0f;
                    }
                }
                else
                {
                    // Glow effect ---------->
                    float glowSize = 0.42f;
                    for (int i = 0; i < 8; i++)
                    {
                        InstancedGeometricPrimitive.InstanceType glowT = new InstancedGeometricPrimitive.InstanceType();
                        glowT.World = Matrix.Scaling(glowSize, 0.02f, glowSize) *
                                      Matrix.RotationX(deg2rad(90)) *
                                      Matrix.RotationY(0) *
                                      Matrix.RotationZ(0) *
                                      Matrix.Translation(screenToWorld(new Vector3(p.getX(), p.getY(), 5.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport)
                                                         + new Vector3(0, 0, 0.03f));

                        glowT.Color   = p.getColor();
                        glowT.Color.W = p.lifespan / 300.0f * (0.02f + i * i * 0.003f);

                        instancedGeo.AddToRenderPass(glowInstanced, glowT);

                        glowSize -= 0.04f;
                    }


                    InstancedGeometricPrimitive.InstanceType t = new InstancedGeometricPrimitive.InstanceType();
                    t.World = Matrix.Scaling(0.08f, 0.08f, 0.08f) *
                              Matrix.RotationX(p.getRotationX()) *
                              Matrix.RotationY(p.getRotationY()) *
                              Matrix.RotationZ(p.getRotationZ()) *
                              Matrix.Translation(screenToWorld(new Vector3(p.getX(), p.getY(), 5.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport));

                    t.Color   = p.getColor();
                    t.Color.W = p.lifespan / 300.0f;

                    instancedGeo.AddToRenderPass(gInstanced, t);

                    //basicEffect.World = Matrix.Scaling(0.08f, 0.08f, 0.08f) *
                    //    Matrix.RotationX(p.getRotationX()) *
                    //    Matrix.RotationY(p.getRotationY()) *
                    //    Matrix.RotationZ(p.getRotationZ()) *
                    //    Matrix.Translation(screenToWorld(new Vector3(p.getX(), p.getY(), 5.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport));

                    //// Color4 color = p.getColor();
                    //basicEffect.DiffuseColor = p.getColor(); //color;
                    ////basicEffect.Alpha = p.lifespan / 400;
                    //g.Draw(basicEffect);
                    //basicEffect.Alpha = 1.0f;
                }
            }

            instancedGeo.Draw();

            instancedGeo.ResetInstances(gInstanced);
            instancedGeo.ResetInstances(glowInstanced);
            instancedGeo.ResetInstances(fwInstanced);
            /**END PARTICLE DRAW********************************************************************/

            drawPoint(new Vector3(normalizedPos, 5.0f), (Vector4)pickColor(normalizedPos.Y, paletteColor));


            //So that you always see the drawing circle

            /*basicEffect.World = Matrix.Scaling(0.4f, 0.05f, 0.4f) *
             *  Matrix.RotationX(deg2rad(90.0f)) *
             *  Matrix.RotationY(0) *
             *  Matrix.RotationZ(0) *
             *  Matrix.Translation(screenToWorld(new Vector3(normalizedPos, 5.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport) + new Vector3(0, 0, -0.201f));
             * basicEffect.DiffuseColor = (Vector4)pickColor(normalizedPos.Y, paletteColor);
             * primitive.Draw(basicEffect);*/



            // ----- TIME LINE --------------------

            /* TimeSpan tmp = stopWatch.Elapsed;
             * float xTL = (float)((tmp.TotalMilliseconds % 10000) / (float)(10000));*/
            basicEffect.World = Matrix.Scaling(0.1f, 0.1f, graphicsDevice.BackBuffer.Height) *
                                Matrix.RotationX(deg2rad(90.0f)) *
                                Matrix.RotationY(0) *
                                Matrix.RotationZ(0) *
                                Matrix.Translation(screenToWorld(new Vector3(xTL, 0.0f, 0.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport));
            basicEffect.DiffuseColor = new Color4(0.466667f, 0.533333f, 0.6f, 1.0f);//new Color4(0.2f, 0.9f, 0.2f, 0.2f);
            timeLine.Draw(basicEffect);

            // ------- END TIME LINE -------------



            //-------PALETTE------------------------------
            float xPs = 0.7f;

            for (int i = 0; i < 4; i++)//foreach (Color4 pColor in palette2)
            {
                if (i == paletteColor)
                {
                    basicEffect.World = Matrix.Scaling(0.7f, 0.001f, 0.7f) *
                                        Matrix.RotationX(deg2rad(90.0f)) *
                                        Matrix.RotationY(0) *
                                        Matrix.RotationZ(0) *
                                        Matrix.Translation(screenToWorld(new Vector3(xPs, 0.93f, 0.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport) + new Vector3(0, 0, -0.199f));

                    basicEffect.DiffuseColor = new Color4(255, 255, 255, 255);
                    paletteCube.Draw(basicEffect);
                }

                basicEffect.World = Matrix.Scaling(0.6f, 0.001f, 0.6f) *
                                    Matrix.RotationX(deg2rad(90.0f)) *
                                    Matrix.RotationY(0) *
                                    Matrix.RotationZ(0) *
                                    Matrix.Translation(screenToWorld(new Vector3(xPs, 0.93f, 0.0f), basicEffect.View, basicEffect.Projection, Matrix.Identity, graphicsDevice.Viewport) + new Vector3(0, 0, -0.2f));

                basicEffect.DiffuseColor = palette2[i];
                paletteCube.Draw(basicEffect);

                xPs = xPs + 0.08f;
            }


            //----------END PALETTE-------------------------



            // --- Trying to add anti-aliasing
            //RasterizerState rState = GraphicsDevice.RasterizerStates.Default;
            //SharpDX.Direct3D11.RasterizerStateDescription rStateDesc = rState.Description;
            //rStateDesc.IsMultisampleEnabled = true;
            //rStateDesc.IsAntialiasedLineEnabled = true;
            //RasterizerState newRState = RasterizerState.New(GraphicsDevice, rStateDesc);
            //GraphicsDevice.SetRasterizerState(newRState);
            // --- End anti-aliasing

            //GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.Default);
            //GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);
            //GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);

            //const float brightPassThreshold = 0.5f;
            //GraphicsDevice.SetRenderTargets(renderTargetDownScales[0]);
            //bloomEffect.CurrentTechnique = bloomEffect.Techniques["BrightPassTechnique"];
            //bloomEffect.Parameters["Texture"].SetResource(renderTargetOffScreen);
            //bloomEffect.Parameters["PointSampler"].SetResource(GraphicsDevice.SamplerStates.PointClamp);
            //bloomEffect.Parameters["BrightPassThreshold"].SetValue(brightPassThreshold);
            //GraphicsDevice.DrawQuad(bloomEffect.CurrentTechnique.Passes[0]);

            //// Down scale passes
            //for (int i = 1; i < renderTargetDownScales.Length; i++)
            //{
            //    GraphicsDevice.SetRenderTargets(renderTargetDownScales[i]);
            //    GraphicsDevice.DrawQuad(renderTargetDownScales[0]);
            //}

            //// Horizontal blur pass
            //var renderTargetBlur = renderTargetDownScales[renderTargetDownScales.Length - 1];
            //GraphicsDevice.SetRenderTargets(renderTargetBlurTemp);
            //bloomEffect.CurrentTechnique = bloomEffect.Techniques["BlurPassTechnique"];
            //bloomEffect.Parameters["Texture"].SetResource(renderTargetBlur);
            //bloomEffect.Parameters["LinearSampler"].SetResource(GraphicsDevice.SamplerStates.LinearClamp);
            //bloomEffect.Parameters["TextureTexelSize"].SetValue(new Vector2(1.0f / renderTargetBlurTemp.Width, 1.0f / renderTargetBlurTemp.Height));
            //GraphicsDevice.DrawQuad(bloomEffect.CurrentTechnique.Passes[0]);

            //// Vertical blur pass
            //GraphicsDevice.SetRenderTargets(renderTargetBlur);
            //bloomEffect.Parameters["Texture"].SetResource(renderTargetBlurTemp);
            //GraphicsDevice.DrawQuad(bloomEffect.CurrentTechnique.Passes[1]);

            // Render to screen
            //GraphicsDevice.SetRenderTargets(GraphicsDevice.BackBuffer);
            //GraphicsDevice.DrawQuad(renderTargetOffScreen);

            //GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Additive);
            //GraphicsDevice.DrawQuad(renderTargetBlur);

            //GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);

            //Console.WriteLine(kinect.xYDepth);
        }
Пример #25
0
 private void DrawGeometry()
 {
     simpleEffect.Transform = worldViewProjection;
     simpleEffect.Apply();
     geometry.Draw();
 }
Пример #26
0
        protected override void Draw(GameTime gameTime)
        {
            // Use time in seconds directly
            var time = (float)gameTime.TotalGameTime.TotalSeconds;

            // Clears the screen with the Color.CornflowerBlue
            GraphicsDevice.Clear(Color.CornflowerBlue);


            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullFront);


            //draw a skybox
            skyEffect.Parameters["World"].SetValue(Matrix.Scaling(500));
            skyEffect.Parameters["Projection"].SetValue(projection);
            skyEffect.Parameters["View"].SetValue(view);
            skyEffect.Parameters["CameraPosition"].SetValue(eyePosition);
            skyCube.Draw(skyEffect);

            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullBack);

            //draw the cubes
            foreach (EffectTechnique effectTechnique in cubeEffect.Techniques)
            {
                foreach (EffectPass pass in effectTechnique.Passes)
                {
                    cubeEffect.Parameters["LightPosition"].SetValue(0, lights[0].position);
                    cubeEffect.Parameters["LightPosition"].SetValue(1, lights[1].position);
                    cubeEffect.Parameters["LightPosition"].SetValue(2, lights[2].position);
                    cubeEffect.Parameters["LightColor"].SetValue(0, lights[0].color.ToVector4());
                    cubeEffect.Parameters["LightColor"].SetValue(1, lights[1].color.ToVector4());
                    cubeEffect.Parameters["LightColor"].SetValue(2, lights[2].color.ToVector4());
                    Matrix world;

                    for (int i = 0; i < cubes.Length; ++i)
                    {
                        pass.Apply();
                        world = Matrix.Scaling(cubes[i].scale) * Matrix.Translation(cubes[i].position);
                        cubeEffect.Parameters["World"].SetValue(world);
                        Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(world));
                        cubeEffect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
                        cubeEffect.Parameters["Projection"].SetValue(projection);
                        cubeEffect.Parameters["View"].SetValue(view);
                        cubeEffect.Parameters["Camera"].SetValue(eyePosition);
                        cubeEffect.Parameters["DiffuseColor"].SetValue(cubes[i].color.ToVector4());
                        cubes[i].Draw(cubeEffect);
                    }
                }
            }

            //draw the lights
            basicEffect.Projection      = projection;
            basicEffect.View            = view;
            basicEffect.LightingEnabled = true;
            basicEffect.EnableDefaultLighting();
            for (int i = 0; i < 3; ++i)
            {
                basicEffect.World         = Matrix.Scaling(5) * Matrix.Translation(lights[i].position);
                basicEffect.DiffuseColor  = lights[i].color.ToVector4();
                basicEffect.EmissiveColor = lights[i].color.ToVector3();
                basicEffect.SpecularColor = Vector3.Zero;
                ballPrimitive.Draw(basicEffect);
            }
            spriteBatch.Begin();

            var text = new StringBuilder("Text is working~").AppendLine();

            List <Keys> keys = new List <Keys>();

            //Display pressed keys
            keyBoardState.GetDownKeys(keys);
            text.Append("Key Pressed: [");
            foreach (var key in keys)
            {
                text.Append(key.ToString());
                text.Append(" ");
            }
            text.Append("]").AppendLine();
            spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Пример #27
0
        protected override void Draw(GameTime gameTime)
        {
            // Use tempo diretamente em segundos
            var time = (float)gameTime.TotalGameTime.TotalSeconds;

            // Limpa a tela com a cor selecionada
            GraphicsDevice.Clear(Color.Black);

            //float translateX = 0.0f;


            // ------------------------------------------------------------------------
            // Desenha as primitivas usando dos efeitos pré carregados
            // ------------------------------------------------------------------------
            basicEffectPrimitive1.Texture = primitiveTexture;
            basicEffectPrimitive1.World   = Matrix.Scaling(0.5f, 2.0f, 0.5f) * // CANHAO
                                            Matrix.RotationX(-1.3f) *
                                            Matrix.RotationY(0f) *
                                            Matrix.RotationZ(0f) *
                                            Matrix.Translation(var_direcao, var_pulse - 1.0f, 3.5f);


            basicEffectPrimitive2.Texture = primitive2Texture;
            basicEffectPrimitive2.World   = Matrix.Scaling(1.0f, 1.0f, var_pulse + 1.0f) * // RODA 1
                                            Matrix.RotationX(0.0f) *
                                            Matrix.RotationY(time * 0.5f) *
                                            Matrix.RotationZ(1.6f) *
                                            Matrix.Translation(var_direcao - 0.4f, -1.3f, 4.0f);

            basicEffectPrimitive3.Texture = primitive3Texture;
            basicEffectPrimitive3.World   = Matrix.Scaling(var_pulse + 0.3f, var_pulse + 0.3f, var_pulse + 0.3f) * // BALA
                                            Matrix.RotationX(1.6f) *
                                            Matrix.RotationY(0f) *
                                            Matrix.RotationZ(0f) *
                                            Matrix.Translation(var_direcao_tiro, var_altura_tiro, var_distancia_tiro);

            basicEffectPrimitive4.Texture = primitive4Texture;
            basicEffectPrimitive4.World   = Matrix.Scaling(10f, 15.0f, 10f) * // CHAO
                                            Matrix.RotationX(0f) *
                                            Matrix.RotationY(time * 0.3f) *
                                            Matrix.RotationZ(-1.56f) *
                                            Matrix.Translation(0.0f, -7f, 0.0f);

            basicEffectPrimitive5.Texture = primitive5Texture;
            basicEffectPrimitive5.World   = Matrix.Scaling(var_pulse + 1.0f, var_pulse + 0.0f, var_pulse + 1.0f) * // ALVO
                                            Matrix.RotationX(time * giro) *
                                            Matrix.RotationY(0f) *
                                            Matrix.RotationZ(1.6f) *
                                            Matrix.Translation(var_vaivem * velocidade_vaivem, 0.0f, -1.0f);

            basicEffectPrimitive6.Texture = primitive6Texture;
            basicEffectPrimitive6.World   = Matrix.Scaling(1.0f, 1.0f, var_pulse + 1.0f) * // RODA 2
                                            Matrix.RotationX(0.0f) *
                                            Matrix.RotationY(time * 0.5f) *
                                            Matrix.RotationZ(1.6f) *
                                            Matrix.Translation(var_direcao + 0.4f, -1.3f, 4.0f);

            basicEffectPrimitive7.Texture = primitive7Texture;
            basicEffectPrimitive7.World   = Matrix.Scaling(35f, 0.1f, 35f) * // HORIZONTE
                                            Matrix.RotationX(1.56f) *
                                            Matrix.RotationY(0f) *
                                            Matrix.RotationZ(time * 0.05f) *
                                            Matrix.Translation(0f, 0f, -8f);

            basicEffectpilar1.Texture = primitivepilar1Texture;
            basicEffectpilar1.World   = Matrix.Scaling(2f, 15.0f, 2f) * // PILAR 1
                                        Matrix.RotationX(time * 0.3f) *
                                        Matrix.RotationY(0f) *
                                        Matrix.RotationZ(0f) *
                                        Matrix.Translation(-4f, -7f, 0.0f);

            basicEffectpilar2.Texture = primitivepilar2Texture;
            basicEffectpilar2.World   = Matrix.Scaling(2f, 17.0f, 2f) * // PILAR 2
                                        Matrix.RotationX(time * 0.3f) *
                                        Matrix.RotationY(0f) *
                                        Matrix.RotationZ(0f) *
                                        Matrix.Translation(4f, -7f, 0.0f);

            primitive.Draw(basicEffectPrimitive1);
            primitive2.Draw(basicEffectPrimitive2);
            primitive3.Draw(basicEffectPrimitive3);
            primitive4.Draw(basicEffectPrimitive4);
            primitive5.Draw(basicEffectPrimitive5);
            primitive6.Draw(basicEffectPrimitive6);
            primitive7.Draw(basicEffectPrimitive7);
            pilar1.Draw(basicEffectpilar1);
            pilar2.Draw(basicEffectpilar2);


            if (var_direcao_tiro > var_vaivem - 0.5 && var_direcao_tiro < var_vaivem + 0.5 && var_distancia_tiro < -1.0 && var_distancia_tiro > -2.0)
            {
                giro               = 20.0f;
                var_tiro           = 0;
                var_direcao_tiro   = 0.0f;
                var_distancia_tiro = 0.0f;
                var_altura_tiro    = 5.0f;
                GraphicsDevice.Clear(Color.LightYellow);
                velocidade_vaivem += 0.1f;
                var_score         += 100;
                var_acertos       += 1;
            }
            if (giro > 1.0f)
            {
                giro = giro - 0.1f;
            }

            // ------------------------------------------------------------------------
            // Mostra o texto
            // ------------------------------------------------------------------------
            spriteBatch.Begin();

            var text = new StringBuilder("Disciplina de jogos 3D 1 - PUC-PR 2014 - ENZO A. MARCHIORATO").AppendLine();

            text.Append("SCORE : ");
            text.Append(var_score);
            text.Append("  ERROS : ");
            text.Append(var_erros);
            text.Append("  ACERTOS : ");
            text.Append(var_acertos).AppendLine();
            text.Append("INSTRUCOES:").AppendLine();
            text.Append("Pressione as SETAS < e > do teclado para movimentar o canhao :").AppendLine();
            // Mostra as teclas pressionadas e atribui eventos a elas

            if (keyboardState.IsKeyDown(Keys.Left) == true)
            {
                text.Append("<").AppendLine();
                if (var_direcao > -3.0f)
                {
                    var_direcao -= 0.01f;
                }
            }
            if (keyboardState.IsKeyDown(Keys.Right) == true)
            {
                text.Append(">").AppendLine();
                if (var_direcao < 3.0f)
                {
                    var_direcao += 0.01f;
                }
            }

            text.Append("Pressione a tecla ESPACO para atirar :").AppendLine();

            if (keyboardState.IsKeyDown(Keys.Space) == true && var_tiro == 0)
            {
                var_tiro = 1;
                //SomTiro.Play(1.0f,1.0f,1.0f);
            }
            if (var_tiro == 1)
            {
                if (var_altura_tiro == 5.0f)
                {
                    var_altura_tiro = 0.0f;
                }
                text.Append("BUUUUMM").AppendLine();
                if (var_direcao_tiro == 0.0f)
                {
                    var_direcao_tiro   = var_direcao;
                    var_distancia_tiro = 1.0f;
                }
                if (var_distancia_tiro > -10.0f)
                {
                    if (var_distancia_tiro > -6.0f)
                    {
                        var_altura_tiro += 0.01f;
                    }
                    if (var_distancia_tiro < -6.0f)
                    {
                        var_altura_tiro -= 0.01f;
                    }
                    text.Append(var_distancia_tiro).AppendLine();
                }
                else
                {
                    var_tiro           = 0;
                    var_direcao_tiro   = 0.0f;
                    var_distancia_tiro = 0.0f;
                    var_altura_tiro    = 5.0f;
                    GraphicsDevice.Clear(Color.LightYellow);
                    var_erros += 1;
                }
                var_distancia_tiro -= 0.1f;
            }

            if (var_pulse < 0.1f && var_tamanho == 0)
            {
                var_pulse += 0.002f;
            }
            if (var_pulse > 0.0f && var_tamanho == 1)
            {
                var_pulse -= 0.002f;
            }

            if (var_pulse > 0.1f)
            {
                var_tamanho = 1;
            }
            if (var_pulse < 0.0f)
            {
                var_tamanho = 0;
            }

            if (var_vaivem_pos == 0)
            {
                var_vaivem += 0.05f;
            }
            if (var_vaivem_pos == 1)
            {
                var_vaivem -= 0.05f;
            }

            if (var_vaivem > 3.0f)
            {
                var_vaivem_pos = 1;
            }
            if (var_vaivem < -3.0f)
            {
                var_vaivem_pos = 0;
            }


            spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.Black);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Пример #28
0
        /*
         * Draw
         */

        protected override void Draw(GameTime gameTime)
        {
            var time = (float)gameTime.TotalGameTime.TotalSeconds;

            //GraphicsDevice.SetRenderTargets(GraphicsDevice.DepthStencilBuffer, renderTargetOffScreen);
            GraphicsDevice.Clear(Color.White);

            Matrix viewProjInverse = (basicEffect.Projection * basicEffect.View);

            viewProjInverse.Invert();

            /*basicEffect.World = Matrix.Scaling(6.0f, 6.0f, 1.0f) *
             *      Matrix.RotationX(0.0f) *
             *      Matrix.RotationY(0) *
             *      Matrix.RotationZ(0) *
             *      Matrix.Translation(new Vector3(0.0f, 0.0f, 0.0f));
             *
             * basicEffect.DiffuseColor = (Vector4)Color.SmoothStep(Color.Azure, Color.Orchid, 0.6f);
             * primitive2.Draw(basicEffect);
             *
             * basicEffect.World = Matrix.Scaling(1.0f, 1.0f, 1.0f) *
             *      Matrix.RotationX(0.0f) *
             *      Matrix.RotationY(0) *
             *      Matrix.RotationZ(0) *
             *      Matrix.Translation(new Vector3(3.0f, 3.0f, 0.0f));
             * basicEffect.DiffuseColor = (Vector4)Color.SmoothStep(Color.Green, Color.RoyalBlue, 0.7f);
             * primitive.Draw(basicEffect);
             *
             *
             * basicEffect.World = Matrix.Scaling(1.0f, 1.0f, 1.0f) *
             *      Matrix.RotationX(0.0f) *
             *      Matrix.RotationY(0) *
             *      Matrix.RotationZ(0) *
             *      Matrix.Translation(new Vector3(-3.0f, -3.0f, 0.0f));
             * basicEffect.DiffuseColor = (Vector4)Color.SmoothStep(Color.Silver, Color.YellowGreen, 0.5f);
             * primitive3.Draw(basicEffect);*/

            for (int i = 1; i < 20; i++)
            {
                tmp = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice));
                Color4 color;
                Random ran = new Random();

                /*color.Red = ran.NextFloat(0.0f, 1.0f);
                 * color.Green = ran.NextFloat(0.0f, 0.5f);
                 * color.Blue = ran.NextFloat(0.0f, 1.0f);
                 * color.Alpha = 1.0f;*/

                color = this.ptype.getColor();

                basicEffect.World = Matrix.Scaling(0.3f, 0.3f, 0.1f) *
                                    Matrix.RotationX(0.0f) *
                                    Matrix.RotationY(0) *
                                    Matrix.RotationZ(0) *
                                    Matrix.Translation(new Vector3(this.xpos, this.ypos + (0.5f * -i), 0));
                basicEffect.DiffuseColor = color;
                tmp.Draw(basicEffect);
            }



            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.Default);
            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);
            GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);

            // Render to screen
            GraphicsDevice.SetRenderTargets(GraphicsDevice.BackBuffer);

            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Additive);
            GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default);

            base.Draw(gameTime);
        }
Пример #29
0
 private void DrawGeometry()
 {
     parameterCollection.Set(SpriteBaseKeys.MatrixTransform, worldViewProjection);
     simpleEffect.Apply(GraphicsDevice, parameterCollectionGroup, true);
     geometry.Draw();
 }
Пример #30
0
        protected override void Draw(GameTime gameTime)
        {
            // Use time in seconds directly
            var time = (float)gameTime.TotalGameTime.TotalSeconds;

            if (loading)
            {
                GraphicsDevice.Clear(Color.Black);
                float loadingScale = 0.7f;
                loadingEffect.Parameters["World"].SetValue(Matrix.Scaling(loadingScreen.Width / (float)Window.ClientBounds.Width * loadingScale, loadingScreen.Height / (float)Window.ClientBounds.Height * loadingScale, 1.0f));
                loadingEffect.Parameters["Texture"].SetResource(loadingScreen);
                loadingEffect.Parameters["TileIndex"].SetValue((float)Math.Min(loadingProgress, 10));
                //GraphicsDevice.Quad.Draw(loadingEffect, false);
                plane.Draw(loadingEffect);
            }
            else
            {
                // Clears the screen with the Color.CornflowerBlue
                GraphicsDevice.Clear(Color.CornflowerBlue);

                // ------------------------------------------------------------------------
                // Draw the some 2d text
                // ------------------------------------------------------------------------
                spriteBatch.Begin();
                var text = new StringBuilder("Zoom").Append(zoom / 0.18f).AppendLine();

                // Display pressed keys
                var pressedKeys = new List <Keys>(); //keyboardState.GetDownKeys();
                keyboardState.GetDownKeys(pressedKeys);
                text.Append("Key Pressed: [");
                foreach (var key in pressedKeys)
                {
                    text.Append(key.ToString());
                    text.Append(" ");
                }
                text.Append("]").AppendLine();

                // Display mouse coordinates and mouse button status
                text.AppendFormat("Selected: {4},{5}", mouseState.X, mouseState.Y, mouseState.LeftButton, mouseState.RightButton, selectedTile.X, selectedTile.Y).AppendLine();

                spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White);
                spriteBatch.End();


                basicEffect.View = Matrix.LookAtLH(cameraPosition + cameraOffset, cameraPosition, Vector3.UnitZ);

                tristram.DrawFloors(GraphicsDevice, basicEffect.View, basicEffect.Projection, floorEffect, plane);

                // Selected Tile
                basicEffect.TextureEnabled = true;
                basicEffect.World          = Matrix.Translation(selectedTile.X * 5, selectedTile.Y * 5, 0);
                plane.Draw(basicEffect);

                tristram.DrawWalls(GraphicsDevice, basicEffect.View, basicEffect.Projection, floorEffect, billboard);

                // Test Billboard
                //basicEffect.World = Matrix.RotationX(MathUtil.DegreesToRadians(90)) * Matrix.RotationZ(MathUtil.DegreesToRadians(-45)) * Matrix.Translation(50, 50, 0);
                //billboard.Draw(basicEffect);

                GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullBack);
                basicEffect.TextureEnabled = false;
                basicEffect.World          = Matrix.Translation(0, 1, 0) * Matrix.RotationX(MathUtil.DegreesToRadians(90));
                player.Draw(basicEffect);


                spriteBatch.Begin();
                spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White);
                spriteBatch.End();

                // Draw the UI
                //quadEffect.Parameters["Texture"].SetResource(browser.Texture);
                //GraphicsDevice.Quad.Draw(quadEffect, true);
            }

            base.Draw(gameTime);
        }