Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pDevice"></param>
        public void Render(GraphicsDevice pDevice)
        {
            if (this.mPoints.Count == 0)
            {
                return;
            }

            // Draw lines
            mPrimitiveBatch.Begin(PrimitiveType.LineList);
            for (int i = 0; i < this.mPoints.Count - 1; i++)
            {
                mPrimitiveBatch.AddVertex(this.mPoints[i], this.mColor);
                mPrimitiveBatch.AddVertex(this.mPoints[i + 1], this.mColor);
                //batch.AddVertex(this.mPoints[(i + 1) % transformedVertices.Length], ShapeColor);
            }
            mPrimitiveBatch.End();

            // Draw Nodes
            for (int i = 0; i < this.mPoints.Count; i++)
            {
                mPrimitiveBatch.Begin(PrimitiveType.LineList);
                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor);
                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor);

                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor);
                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, cHalfRadiusNodes), this.mColor);

                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(cHalfRadiusNodes, cHalfRadiusNodes), this.mColor);
                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, cHalfRadiusNodes), this.mColor);

                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, cHalfRadiusNodes), this.mColor);
                mPrimitiveBatch.AddVertex(this.mPoints[i] + new Vector2(-cHalfRadiusNodes, -cHalfRadiusNodes), this.mColor);
                mPrimitiveBatch.End();
            }
        }
Exemplo n.º 2
0
        public static void Begin(Matrix view, Matrix projection)
        {
            Vector3 lightDirection = new Vector3(1, 1, 0);
            Vector3 lightColor     = new Vector3(0.3f, 0.4f, 0.2f);

            effect.View               = view;
            effect.Projection         = projection;
            effect.VertexColorEnabled = true;
            effect.LightingEnabled    = true;
            effect.EnableDefaultLighting();
            effect.DirectionalLight0.Enabled       = true;
            effect.DirectionalLight0.Direction     = lightDirection;
            effect.DirectionalLight0.DiffuseColor  = lightColor;
            effect.DirectionalLight0.SpecularColor = lightColor;
            effect.CurrentTechnique.Passes[0].Apply();

            if (Wireframe)
            {
                graphicsDevice.SetRasterizerState(graphicsDevice.RasterizerStates.WireFrameCullNone);
            }
            else
            {
                graphicsDevice.SetRasterizerState(graphicsDevice.RasterizerStates.CullNone);
            }

            batch.Begin();
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.DarkSlateGray);

            GraphicsDevice.BlendState        = BlendState.AlphaBlend;
            GraphicsDevice.DepthStencilState = DepthStencilState.None;

            BoundingFrustum frustum = new BoundingFrustum(
                Matrix.CreateLookAt(new Vector3(0, 15, 15), Vector3.Zero, Vector3.UnitZ) *
                Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1, 1, 10));

            primitiveBatch.Begin(PrimitiveSortMode.Deferred, camera.View, camera.Projection);
            {
                primitiveBatch.DrawSphere(new BoundingSphere(Vector3.UnitX * 4, 1), 24, null, Color.White);
                primitiveBatch.DrawGrid(1, 128, 128, null, Color.White * 0.25f);
                primitiveBatch.DrawGrid(8, 16, 16, null, Color.Black);
                primitiveBatch.DrawLine(new Vector3(5, 5, 0), new Vector3(5, 5, 5), Color.Blue);
                primitiveBatch.DrawConstrainedBillboard(null, new Vector3(5, -5, 0), new Vector3(5, -5, 5), 0.05f, null, null, Color.Yellow);
                primitiveBatch.DrawArrow(Vector3.Zero, Vector3.UnitZ * 2, null, Color.White);
                primitiveBatch.DrawBox(new BoundingBox(-Vector3.One, Vector3.One), null, Color.White);
                primitiveBatch.DrawSolidBox(new BoundingBox(-Vector3.One, Vector3.One), null, Color.Yellow * 0.2f);
                primitiveBatch.DrawCircle(Vector3.UnitX * 2, 1, 24, null, Color.Yellow);
                primitiveBatch.DrawSolidSphere(new BoundingSphere(Vector3.UnitX * 4, 1), 24, null, Color.Red * 0.2f);
                primitiveBatch.DrawAxis(Matrix.CreateTranslation(-4, 0, 0));
                primitiveBatch.DrawFrustum(frustum, null, Color.White);
                primitiveBatch.DrawSolidFrustum(frustum, null, Color.Pink * 0.5f);
                primitiveBatch.DrawCentrum(new Vector3(-5, -2, 0), 2, 1, 24, null, Color.WhiteSmoke * 0.5f);
                primitiveBatch.DrawSolidCentrum(new Vector3(-5, -2, 0), 2, 1, 24, null, Color.LawnGreen * 0.3f);
                primitiveBatch.DrawCylinder(new Vector3(-5, -6, 0), 2, 1, 24, null, Color.WhiteSmoke * 0.5f);
                primitiveBatch.DrawSolidCylinder(new Vector3(-5, -6, 0), 2, 1, 24, null, Color.Lavender * 0.3f);
            }
            primitiveBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 4
0
        public override void Draw(GameTime gameTime)
        {
            LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Splash Screen");
            Vector2 screenTitlePos           = GlobalValues.GetWordCenterPos("Splash Screen", true);

            if (GlobalValues.ValuesInitialized)
            {
                if (spriteBatch != null)
                {
                    spriteBatch.Begin();

                    spriteBatch.Draw(myImage, new Vector2(0, 0));

                    spriteBatch.End();
                }

                if (pb != null)
                {
                    pb.Begin(PrimitiveType.LineList);

                    DrawLander();
                    DrawLanderRocket();
                    DisplayKeys();

                    pb.End();
                }
                else
                {
                    pb = GlobalValues.PrimitiveBatch;
                }
            }
        }
Exemplo n.º 5
0
        public void Draw(GraphicsDevice device)
        {
            if (material == null)
            {
                Warm(device);
            }

            material.Projection = proj;
            material.View       = view;
            material.World      = Matrix.Identity;
            material.CurrentTechnique.Passes[0].Apply();

            PrimitiveBatch instance = PrimitiveBatch.GetInstance(device);

            instance.Begin(Primitive.Line);

            instance.SetColor(color);
            for (int p = 1; p < points.Length; p++)
            {
                instance.AddVertex(points[p - 1]);
                instance.AddVertex(points[p - 0]);
            }

            instance.AddVertex(points[points.Length - 1]);
            instance.AddVertex(points[0]);

            instance.End();
        }
Exemplo n.º 6
0
        public void Draw3D(PrimitiveBatch primitiveBatch, Matrix world, Matrix projection, Matrix view, Vector3 where)
        {
            // the sun is made from 4 lines in a circle.
            primitiveBatch.Begin(PrimitiveType.LineList, world, projection, view);

            // draw the vertical and horizontal lines
            primitiveBatch.AddVertex(where + new Vector3(0, LIGHT_SIZE, 0), Color.White);
            primitiveBatch.AddVertex(where + new Vector3(0, -LIGHT_SIZE, 0), Color.White);

            primitiveBatch.AddVertex(where + new Vector3(LIGHT_SIZE, 0, 0), Color.White);
            primitiveBatch.AddVertex(where + new Vector3(-LIGHT_SIZE, 0, 0), Color.White);

            // to know where to draw the diagonal lines, we need to use trig.
            // cosine of pi / 4 tells us what the x coordinate of a circle's radius is
            // at 45 degrees. the y coordinate normally would come from sin, but sin and
            // cos 45 are the same, so we can reuse cos for both x and y.
            float sunSizeDiagonal = (float)Math.Cos(MathHelper.PiOver4);

            // since that trig tells us the x and y for a unit circle, which has a
            // radius of 1, we need scale that result by the sun's radius.
            sunSizeDiagonal *= LIGHT_SIZE;

            primitiveBatch.AddVertex(
                where + new Vector3(-sunSizeDiagonal, sunSizeDiagonal, 0), Color.Gray);
            primitiveBatch.AddVertex(
                where + new Vector3(sunSizeDiagonal, -sunSizeDiagonal, 0), Color.Gray);

            primitiveBatch.AddVertex(
                where + new Vector3(sunSizeDiagonal, sunSizeDiagonal, 0), Color.Gray);
            primitiveBatch.AddVertex(
                where + new Vector3(-sunSizeDiagonal, -sunSizeDiagonal, 0), Color.Gray);

            primitiveBatch.End();
        }
Exemplo n.º 7
0
        protected override void Draw(GameTime gameTime)
        {
            _localProjection = Matrix.CreateOrthographicOffCenter(0f, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0f, 0f, 1f);
            _localView       = Matrix.Identity;

            _primitiveBatch.Begin(ref _localProjection, ref _localView);

            _primitiveDrawing.DrawPoint(new Vector2(10, 10), Color.Brown);

            _primitiveDrawing.DrawRectangle(new Vector2(20, 20), 50, 50, Color.Yellow);
            _primitiveDrawing.DrawSolidRectangle(new Vector2(20, 120), 50, 50, Color.Yellow);

            _primitiveDrawing.DrawCircle(new Vector2(120, 45), 25, Color.Green);
            _primitiveDrawing.DrawSolidCircle(new Vector2(120, 145), 25, Color.Green);

            _primitiveDrawing.DrawEllipse(new Vector2(220, 45), new Vector2(50, 25), 32, Color.Orange);
            _primitiveDrawing.DrawSolidEllipse(new Vector2(220, 145), new Vector2(50, 25), 32, Color.Orange);

            _primitiveDrawing.DrawSegment(new Vector2(320, 20), new Vector2(370, 170), Color.White);

            _primitiveDrawing.DrawPolygon(new Vector2(420, 20), _polygon.Vertices, Color.Aqua);
            _primitiveDrawing.DrawSolidPolygon(new Vector2(420, 120), _polygon.Vertices, Color.Aqua);

            _primitiveBatch.End();
        }
Exemplo n.º 8
0
        public override void Draw(GameTime gameTime)
        {
            if (!GlobalValues.GoToMainMenu)
            {
                if (GlobalValues.LevelLoaded == "Random")
                {
                    Terrain.BuildTerrain(mapShiftPosition);
                    Terrain.BuildPads(mapShiftPosition);
                }
                else
                {
                    Terrain.BuildTerrain(Vector2.Zero);
                    Terrain.BuildPads(Vector2.Zero);
                }

                pb.Begin(PrimitiveType.LineList);

                ShowGUIWords();
                ShowGUINumbers();
                ShowControls();
                ShowTitle();

                pb.End();

                lander.Draw(gameTime);
            }
        }
Exemplo n.º 9
0
        protected override void Draw(GameTime gameTime)
        {
            if (!MazeData.MazeExists)
            {
                return;
            }

            GraphicsDevice.Clear(MazeData.MazeColors[CellState.Wall]);

            _mainBasicEffect.CurrentTechnique.Passes[0].Apply();
            _mainPrimitiveBatch.Begin();

            for (var i = 0; i < MazeData.MazeSize; i++)
            {
                for (var j = 0; j < MazeData.MazeSize; j++)
                {
                    // TODO: fix this hack (add a mutex)
                    try
                    {
                        if (MazeData.MazeMatrix[i, j] != null && MazeData.MazeMatrix[i, j].Display != MazeData.MazeColors[CellState.Wall])
                        {
                            DrawCell(i, j, MazeData.MazeMatrix[i, j].Display);
                        }
                    }
                    catch (NullReferenceException)
                    {
                    }
                }
            }

            _mainPrimitiveBatch.End();
        }
        private void DrawBox(Vector2[] lineList, bool selected)
        {
            var colour = (selected ? Color.Blue : Color.White);

            lineList[0].X -= 1;
            lineList[0].Y -= 1;

            lineList[1].X += 1;
            lineList[1].Y -= 1;

            lineList[2].X += 1;
            lineList[2].Y += 1;

            lineList[3].X -= 1;
            lineList[3].Y += 1;

            primitiveBatch.Begin(PrimitiveType.LineList, Camera.get_Transformation(GraphicsDevice));

            primitiveBatch.AddVertex(lineList[0], colour);
            primitiveBatch.AddVertex(lineList[1], colour);

            primitiveBatch.AddVertex(lineList[1], colour);
            primitiveBatch.AddVertex(lineList[2], colour);

            primitiveBatch.AddVertex(lineList[2], colour);
            primitiveBatch.AddVertex(lineList[3], colour);

            primitiveBatch.AddVertex(lineList[3], colour);
            primitiveBatch.AddVertex(lineList[0], colour);

            primitiveBatch.End();
        }
Exemplo n.º 11
0
        public override void Draw(GameTime gameTime)
        {
            pb.Begin(PrimitiveType.LineList);

            ShowMenuOptions();

            pb.End();
        }
Exemplo n.º 12
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            RectangleF clip;
            RectangleF destRect   = Bounds;
            Rectangle? sourceRect = null;

            if (HasClip(out clip))
            {
                RectangleF inter = RectangleF.Empty;
                inter.Left   = Math.Max(clip.Left, destRect.Left);
                inter.Top    = Math.Max(clip.Top, destRect.Top);
                inter.Right  = Math.Min(clip.Right, destRect.Right);
                inter.Bottom = Math.Min(clip.Bottom, destRect.Bottom);

                int leftClip      = (int)(inter.Left - DrawPosition.X);
                int rightClip     = (int)(inter.Right - (DrawPosition.X + Width));
                int topClip       = (int)(inter.Top - DrawPosition.Y);
                int bottomClip    = (int)(inter.Bottom - (DrawPosition.Y + Height));
                int clippedWidth  = rightClip - leftClip;
                int clippedHeight = bottomClip - topClip;

                Rectangle source = Rectangle.Empty;
                source.X      = leftClip;
                source.Y      = topClip;
                source.Width  = (int)Width + clippedWidth;
                source.Height = (int)Height + clippedHeight;
                sourceRect    = source;

                destRect.X     += leftClip;
                destRect.Y     += topClip;
                destRect.Width  = Math.Max(destRect.Width + clippedWidth, 0);
                destRect.Height = Math.Max(destRect.Height + clippedHeight, 0);

                if (UIManager.DrawDebug)
                {
                    PrimitiveBatch.Begin();
                    PRect rect = new PRect(clip, 1);
                    rect.Color = Color.Yellow;
                    rect.Draw();
                    PrimitiveBatch.End();

                    PrimitiveBatch.Begin();
                    rect       = new PRect(inter, 1);
                    rect.Color = Color.Magenta;
                    rect.Draw();
                    PrimitiveBatch.End();
                }

                //int rC = (int)(  inter.Right - ( DrawPosition.X + Width ) - location.X + location.X);
                //int lC = (int)( location.X + inter.Left - DrawPosition.X - location.X );
                //int bC = (int)( location.Y + inter.Bottom - ( DrawPosition.Y + Height ) - location.Y );
                //int tC = (int)( location.Y + inter.Top - DrawPosition.Y - location.Y );
            }

            spriteBatch.Draw(texture, destRect, sourceRect, Color, 0f, Vector2.Zero, SpriteEffect, LayerDepth);
        }
Exemplo n.º 13
0
        public override void Draw(GameTime gameTime)
        {
            pb.Begin(PrimitiveType.LineList);

            guiManager.ShowGUI(guiItems);
            guiManager.ShowSelectedIcon(currentSelectedItem);

            pb.End();
        }
Exemplo n.º 14
0
        public void End()
        {
            if (!has_begun)
            {
                throw new InvalidOperationException("Begin must be called before End can be called.");
            }

            if (primitivebatch == null || material == null)
            {
                Warm(device);
            }

            material.Parameters["TextureEnabled"].SetValue(true);
            material.Parameters["World"].SetValue(Matrix.Identity);
            material.Parameters["View"].SetValue(camera.view);
            material.Parameters["Projection"].SetValue(camera.projection);

            foreach (Texture2D texture in particles.Keys)
            {
                List <ParticleInfo> list = particles[texture];

                if (list.Count <= 0)
                {
                    continue;
                }

                material.Parameters["Texture"].SetValue(texture);
                material.CurrentTechnique.Passes[0].Apply();

                primitivebatch.Begin(Primitive.Quad);
                float texture_pixel_width  = 1.0f / texture.Width;
                float texture_pixel_height = 1.0f / texture.Height;

                for (int i = 0; i < list.Count; i++)
                {
                    ParticleInfo  particle = list[i];
                    TextureRegion region   = particle.region;

                    primitivebatch.SetTransform(ref particle.transform);
                    primitivebatch.SetColor(particle.color);
                    primitivebatch.SetTextureCoords(region.u * texture_pixel_width, region.v * texture_pixel_height);

                    primitivebatch.AddVertex(-0.5f, 0.5f, 0, 0, 0);
                    primitivebatch.AddVertex(-0.5f, -0.5f, 0, 0, region.height * texture_pixel_height);
                    primitivebatch.AddVertex(0.5f, -0.5f, 0, region.width * texture_pixel_width, region.height * texture_pixel_height);
                    primitivebatch.AddVertex(0.5f, 0.5f, 0, region.width * texture_pixel_width, 0);
                }

                primitivebatch.End();

                list.Clear();
            }

            has_begun = false;
        }
Exemplo n.º 15
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            _basicEffect.Projection         = Matrix.OrthoOffCenterRH(0, Game.Device.Viewport.Width, Game.Device.Viewport.Height, 0, 0, 1);
            _basicEffect.Alpha              = 1.0f;
            _basicEffect.VertexColorEnabled = true;
            _basicEffect.CurrentTechnique.Passes[0].Apply();

            _primitiveBatch.Begin();

            if (_drawMap)
            {
                DrawPlayer();
                DrawMapGridLines();
            }

            if (_drawRays)
            {
                DrawRays();
            }

            if (!_drawMap && !_drawWalls)
            {
                DrawSolidWalls();
            }

            if (!_drawMap)
            {
                DrawHorizon();
            }


            _primitiveBatch.End();

            _spriteBatch.Begin();

            if (!_drawMap)
            {
                DrawSky();
            }

            if (_drawMap)
            {
                DrawMapWallTextures();
            }

            if (!_drawMap && _drawWalls)
            {
                DrawTexturedWall();
            }

            _spriteBatch.End();
        }
Exemplo n.º 16
0
        public void Draw(Vector2 scroll, float size)
        {
            float width  = this.window.Control.ClientSize.Width;
            float height = this.window.Control.ClientSize.Height;
            float bSize  = size;

            while (bSize < targetBlockSize / subDivisions)
            {
                bSize *= 2;
            }
            while (bSize > targetBlockSize)
            {
                bSize /= subDivisions;
            }
            Vector2 blockSize = new Vector2(bSize / width, bSize / height);

            Vector2 dest = new Vector2(scroll.X / width, -scroll.Y / height) * 2;
            int     xPos = 0, yPos = 0;

            while (dest.X > -1)
            {
                dest.X -= blockSize.X; xPos--;
            }
            while (dest.Y > -1)
            {
                dest.Y -= blockSize.Y; yPos--;
            }

            VertexPositionColor start = new VertexPositionColor();
            VertexPositionColor end   = new VertexPositionColor();

            effect.CurrentTechnique.Passes[0].Apply();
            batch.Begin();

            start.Position.Y = -1;
            end.Position.Y   = 1;
            for ( ; dest.X <= 1; dest.X += blockSize.X, xPos++)
            {
                start.Color      = end.Color = (xPos % subDivisions == 0) ? Colors[0] : Colors[1];
                start.Position.X = end.Position.X = dest.X;
                batch.DrawLine(start, end);
            }

            start.Position.X = -1;
            end.Position.X   = 1;
            for ( ; dest.Y <= 1; dest.Y += blockSize.Y, yPos++)
            {
                start.Color      = end.Color = (yPos % subDivisions == 0) ? Colors[0] : Colors[1];
                start.Position.Y = end.Position.Y = dest.Y;
                batch.DrawLine(start, end);
            }

            batch.End();
        }
Exemplo n.º 17
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(BackgroundColor);

            basicEffect.CurrentTechnique.Passes[0].Apply();
            primitiveBatch.Begin();
            primitiveBatch.DrawTriangle(
                new VertexPositionColor(new Vector3(-0.8f, -0.8f, 0.0f), ForegroundColor),
                new VertexPositionColor(new Vector3(0.0f, 0.8f, 0.0f), ForegroundColor),
                new VertexPositionColor(new Vector3(0.8f, -0.8f, 0.0f), ForegroundColor)
                );
            primitiveBatch.End();
        }
Exemplo n.º 18
0
 public override void Draw(GameTime gameTime)
 {
     pb.Begin(PrimitiveType.LineList);
     foreach (Vector2 v2 in land)
     {
         pb.AddVertex(v2, landColor);
     }
     foreach (Vector2 v2 in landingPads)
     {
         pb.AddVertex(v2, padColor);
     }
     pb.End();
     base.Draw(gameTime);
 }
Exemplo n.º 19
0
        public override void Draw(GameTime gameTime)
        {
            //GraphicsDevice.Clear(Color.TransparentBlack);

            pb.Begin(PrimitiveType.LineList);

            DrawLaser();

            DrawLaserCollision();

            pb.End();

            base.Draw(gameTime);
        }
Exemplo n.º 20
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
           graphics.GraphicsDevice.Clear(backgroundColor);


            primitiveBatch.Begin();


            demo.Draw(debugDraw);


            primitiveBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 21
0
        protected override void Draw(GameTime gameTime)
        {
            _effect.World      = _camera.World;
            _effect.View       = _camera.View;
            _effect.Projection = _camera.Projection;

            _graphics.ScissorRectangle = _graphics.Viewport.Bounds;
            _spriteBatch.Begin(sortMode: SpriteSortMode.Immediate, blendState: BlendState.AlphaBlend, samplerState: SamplerState.PointWrap, rasterizerState: _rasterizerState, effect: _effect);
            _primitiveBatch.Begin(_camera, BlendState.AlphaBlend);

            base.Draw(gameTime);

            _primitiveBatch.End();
            _spriteBatch.End();
        }
Exemplo n.º 22
0
        public override void Draw(GameTime gameTime)
        {
            pb.Begin(PrimitiveType.LineList);

            if (!showConfirmation)
            {
                ShowMenuOptions();
            }
            else
            {
                ShowConfirmationOptions();
            }

            pb.End();
        }
Exemplo n.º 23
0
        protected override void Draw(Matrix view, Matrix Projection, RenderHelper render, PrimitiveBatch batch)
        {
            if (fill == false)
            {
                render.PushRasterizerState(state);
            }

            batch.Begin(PrimitiveType.TriangleList,view,Projection);
            foreach (var item in point)
            {
                batch.AddVertex(item, color);
            }
            batch.End();

            render.PopRasterizerState();
        }
Exemplo n.º 24
0
        public void Draw()
        {
            if (_drawCollisionRects)
            {
                _primitiveBatch.Begin(SamplerType.Point, _playState.Camera.GetViewMatrix());

                foreach (var entity in _playState.ColliderGroup.Entities)
                {
                    var rect = EntityUtility.GetEntityCollisionRect(entity);
                    _primitiveBatch.DrawFilledRect(rect, _collisionRectColor);
                }

                _primitiveBatch.End();
            }

            ref var transform = ref _player.GetComponent <TransformComponent>();
Exemplo n.º 25
0
 public void DrawSelectedItems(ref Matrix projection, ref Matrix view)
 {
     _primitiveBatch.Begin(ref projection, ref view);
     foreach (Joint joint in _selectedJoints)
     {
         DrawJoint(joint, Color.Red);
     }
     foreach (GameObjectPart gop in _selectedGameObjectParts)
     {
         DrawObjectPart(gop, Color.Red);
     }
     foreach (GameObject go in _selectedGameObjects)
     {
         DrawObject(go, Color.Yellow);
     }
     _primitiveBatch.End();
 }
Exemplo n.º 26
0
        public override void Draw(GameTime gameTime)
        {
            // TODO: Add your draw code here
            if (isVisible)
            {
                pb.Begin(PrimitiveType.LineList);

                foreach (Vector2 v in landerCraft)
                {
                    pb.AddVertex(v, Color.Green);
                }

                pb.End();
            }

            base.Draw(gameTime);
        }
Exemplo n.º 27
0
        public void Draw(SpriteBatch spriteBatch)
        {
            if (!layoutDone)
            {
                DoLayout();
            }
#if DEBUG
            if (EnableProfilling)
            {
                drawProfiler.Start();
            }
#endif
            spriteBatch.Begin(SpriteSortMode.Deferred, spriteBatch.GraphicsDevice.BlendStates.NonPremultiplied);
            PrimitiveBatch.Begin();

            foreach (UIControl control in this)
            {
                if (control.Enabled && control.Visible)
                {
                    control.Draw(spriteBatch);
                }
            }

            PrimitiveBatch.End();
            spriteBatch.End();
#if DEBUG
            if (EnableProfilling)
            {
                drawProfiler.Stop();
                debugPanel.SetDebugValue("UI time", (drawProfiler.TotalElapsed + updateProfiler.TotalElapsed + layoutProfiler.TotalElapsed).ToString("0.00"));
                debugPanel.SetDebugValue("  Draw", drawProfiler.FullOutput(2, 4));
                debugPanel.SetDebugValue("  Layout", layoutProfiler.FullOutput());
                debugPanel.SetDebugValue("Primitives", PrimitiveBatch.DrawCount.ToString());

                spriteBatch.Begin(SpriteSortMode.Deferred, spriteBatch.GraphicsDevice.BlendStates.NonPremultiplied);
                PrimitiveBatch.Begin();

                debugPanel.Draw(spriteBatch);

                PrimitiveBatch.End();
                spriteBatch.End();
            }
#endif
        }
Exemplo n.º 28
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.TransparentBlack);

            if (gameEnded)
            {
                GraphicsDevice.Clear(Color.Red);
            }
            else
            {
                GraphicsDevice.Clear(Color.TransparentBlack);
            }

            pb.Begin(PrimitiveType.LineList);

            DrawPlayerShip();

            DrawRockCollision();

            DisplayLives();

            pb.End();

            #region User Interface

            DisplayTitle();
            DisplayAngle();
            DisplayScore();


            if (crashed && !gameEnded)
            {
                DisplayCrashed();
            }
            else if (gameEnded)
            {
                DisplayGameOver();
            }

            #endregion

            base.Draw(gameTime);
        }
Exemplo n.º 29
0
        public static void ShowEntireFont(PrimitiveBatch pb)
        {
            int scaleForFontDisplay = 8;

            LinkedList <Vector2> row1 = new LinkedList <Vector2>();
            LinkedList <Vector2> row2 = new LinkedList <Vector2>();
            LinkedList <Vector2> row3 = new LinkedList <Vector2>();
            LinkedList <Vector2> row4 = new LinkedList <Vector2>();

            Vector2 row1Position = new Vector2(10, 50);
            Vector2 row2Position = new Vector2(10, 100);
            Vector2 row3Position = new Vector2(10, 150);
            Vector2 row4Position = new Vector2(10, 200);

            row1 = MyFont.GetWord(scaleForFontDisplay, "a b c d e f g h i j");
            row2 = MyFont.GetWord(scaleForFontDisplay, "k l m n o p q r s t");
            row3 = MyFont.GetWord(scaleForFontDisplay, "u v w x y z 1 2 3 4");
            row4 = MyFont.GetWord(scaleForFontDisplay, "5 6 7 8 9 0 .");

            pb.Begin(PrimitiveType.LineList);

            foreach (Vector2 v2 in row1)
            {
                pb.AddVertex(v2 + row1Position, Color.White);
            }

            foreach (Vector2 v2 in row2)
            {
                pb.AddVertex(v2 + row2Position, Color.White);
            }

            foreach (Vector2 v2 in row3)
            {
                pb.AddVertex(v2 + row3Position, Color.White);
            }

            foreach (Vector2 v2 in row4)
            {
                pb.AddVertex(v2 + row4Position, Color.White);
            }

            pb.End();
        }
Exemplo n.º 30
0
        public override void Draw(GameTime gameTime)
        {
            //GraphicsDevice.Clear(Color.TransparentBlack);

            pb.Begin(PrimitiveType.LineList);

            DrawRocks();

            DrawSquare();

            DrawRockCollision();

            //pb.AddLine(new Vector2(center.X, center.Y - 10), new Vector2(center.X, center.Y + 10), Color.Violet, 5);
            //pb.AddLine(new Vector2(center.X - 10, center.Y), new Vector2(center.X + 10, center.Y), Color.Violet, 5);


            pb.AddVertex(new Vector2(position.X, position.Y - 10), Color.Violet);
            pb.AddVertex(new Vector2(position.X, position.Y + 10), Color.Violet);

            pb.AddVertex(new Vector2(position.X - 10, position.Y), Color.Violet);
            pb.AddVertex(new Vector2(position.X + 10, position.Y), Color.Violet);

            //pb.AddVertex(new Vector2(242.1367f, 275.431f), Color.Violet);
            //pb.AddVertex(new Vector2(242.1367f, 295.431f), Color.Violet);

            //pb.AddVertex(new Vector2(300, 375), Color.Violet);
            //pb.AddVertex(new Vector2(300, 300), Color.Violet);

            /*
             * Laser Collision: l1.StartX (242.1367, 275.431) l1.EndX (242.1367, 295.431)
             * Rock Collision:  l2.StartX (300, 375) l2.EndX (300, 300)
             */
            Line2D.Intersects(new Line2D(238.5262f, 283.2247f, 238.5262f, 303.2247f),
                              new Line2D(300, 375, 300, 300));



            pb.End();


            base.Draw(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(new Color(32, 32, 32));

            _primitiveBatch.Begin(_camera.View, _camera.Projection);
            _grid.Render(_primitiveBatch, Matrix.Identity);
            _primitiveBatch.End();

            var viewport    = GraphicsDevice.Viewport;
            var translation = _camera.View.Translation;
            var spriteBatchTransformation = Matrix.CreateTranslation(viewport.Width / 2 / zoom, viewport.Height / 2 / zoom, 0) *
                                            Matrix.CreateTranslation(translation.X, -translation.Y, 0)
                                            * Matrix.CreateScale(zoom);

            _spriteBatch.Begin(transformMatrix: spriteBatchTransformation, samplerState: SamplerState.PointClamp);

            foreach (var entity in _state.Entities.Values)
            {
                var posProperty = _state.PropertyDefinitions[POSITION_PROPERTY];
                var position    = entity.GetCurrentPropertyValue <Vector2>(posProperty);

                var frameIndexProperty = _state.PropertyDefinitions[FRAMEINDEX_PROPERTY];
                var frameIndex         = entity.GetCurrentPropertyValue <int>(frameIndexProperty);

                var texture = _state.Textures[entity.TextureId];
                int framesX = (int)(texture.Width / texture.FrameSize.X);

                int x = frameIndex % framesX;
                int y = frameIndex / framesX;

                var sourceRect = new Rectangle((int)(x * texture.FrameSize.X), (int)(y * texture.FrameSize.Y),
                                               (int)texture.FrameSize.X, (int)texture.FrameSize.Y);

                _spriteBatch.Draw(texture, position, sourceRect, Color.White,
                                  0f, new Vector2(texture.Pivot.X, texture.Pivot.Y),
                                  1.0f, SpriteEffects.None, 0f);
            }

            _spriteBatch.End();

            DrawUi(gameTime);
        }
Exemplo n.º 32
0
        public override void Draw(GameTime gameTime)
        {
            pb.Begin(PrimitiveType.LineList);

            foreach (Vector2 x in terrain.terrainList)
            {
                pb.AddVertex(x, Color.White);
            }

            foreach (Vector2 x in terrain.padsList)
            {
                pb.AddVertex(x, Color.Green);
            }

            foreach (Vector2 x in fuelWord.sentence)
            {
                pb.AddVertex(x + new Vector2(10, 10), Color.White);
            }

            if (terInt || padsInt)
            {
                if (terInt)
                {
                    StateManager.graphicsDevice.Clear(Color.DarkRed);
                }

                if (padsInt)
                {
                    StateManager.graphicsDevice.Clear(Color.DarkGreen);
                }
            }

            lander.Draw(gameTime);

            pb.End();

            spriteBatch.Begin();

            AllTheWords();

            spriteBatch.End();
        }
        protected override void Draw(Matrix view, Matrix Projection, RenderHelper render, PrimitiveBatch batch)
        {
            if (fill == false)
            {
                render.PushRasterizerState(state);
            }

            if (point.Count < 3)
            {
                throw new InvalidOperationException("Need at least 3 points to make a triangle strip");
            }

            batch.Begin(PrimitiveType.TriangleStrip,view,Projection);
            foreach (var item in point)
            {
                batch.AddVertex(item, color);       
            }
            batch.End();

            if (fill == false)
            {
                render.PopRasterizerState();
            }
        }
Exemplo n.º 34
0
        private void DrawGrid(float gridSize)
        {
            // where can we put the stars?
            int screenWidth = graphics.GraphicsDevice.Viewport.Width;
            int screenHeight = graphics.GraphicsDevice.Viewport.Height;

            PrimitiveBatch primitiveBatch = new PrimitiveBatch(this.GraphicsDevice);
            primitiveBatch.Begin(PrimitiveType.LineList);

            for (float i = gridSize; i < screenWidth; i += gridSize)
            {
                //draw line verticaly
                primitiveBatch.AddVertex(new Vector2(i, 0), Color.White);
                primitiveBatch.AddVertex(new Vector2(i, screenHeight), Color.White);
            }

            for (float i = gridSize; i < screenHeight; i += gridSize)
            {
                //draw line verticaly
                primitiveBatch.AddVertex(new Vector2(0, i), Color.White);
                primitiveBatch.AddVertex(new Vector2(screenWidth, i), Color.White);
            }

            primitiveBatch.End();
        }
Exemplo n.º 35
0
      public void FillPath(Color fillColor) {
         var fillClipper = new Clipper(Clipper.ioStrictlySimple);
         var points = pathSegments.SelectMany(s => new[] { new IntPoint(s.Head.Location.X * 1000, s.Head.Location.Y * 1000), new IntPoint(s.Tail.Location.X * 1000, s.Tail.Location.Y * 1000) });
         fillClipper.AddPath(points.ToList(), PolyType.ptSubject, true);
         var polytree = new PolyTree();
         fillClipper.Execute(ClipType.ctUnion, polytree, PolyFillType.pftEvenOdd, PolyFillType.pftNonZero);
         var triangles = new Triangulator().TriangulateComplex(polytree);

         using (RenderTargetSwap()) {
            GraphicsDevice.SetRasterizerState(rasterizerState);

            foreach (var pass in effect.CurrentTechnique.Passes) {
               pass.Apply();
               var x = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
               x.Begin();
               foreach (var triangle in triangles) {
                  var p1 = triangle.Points[0];
                  var p2 = triangle.Points[1];
                  var p3 = triangle.Points[2];
                  x.DrawTriangle(
                     new VertexPositionColor(new Vector3((float)p1.X, (float)p1.Y, 100), fillColor),
                     new VertexPositionColor(new Vector3((float)p2.X, (float)p2.Y, 100), fillColor),
                     new VertexPositionColor(new Vector3((float)p3.X, (float)p3.Y, 100), fillColor)
                     );
               }
               x.End();
            }
         }
      }
Exemplo n.º 36
0
      public void Stroke() {
         using (RenderTargetSwap()) {
            GraphicsDevice.SetRasterizerState(rasterizerState);

            foreach (var pass in effect.CurrentTechnique.Passes) {
               pass.Apply();

               var x = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
               x.Begin();

               Color lastTailColor = Color.Transparent;
               Point2D lastP3 = null;
               Point2D lastP4 = null;
               foreach (var pathSegment in pathSegments) {
                  var a = pathSegment.Head;
                  var b = pathSegment.Tail;

                  var v = b.Location - a.Location;
                  var vPerpUnit = v.Perp().ToUnitVector();
                  var vR1 = vPerpUnit * a.Thickness / 2;
                  var vR2 = vPerpUnit * b.Thickness / 2;

                  var p1 = a.Location - vR1;
                  var p2 = a.Location + vR1;
                  var p3 = b.Location + vR2;
                  var p4 = b.Location - vR2;

                  if (!a.IsNewPathStart && lastP3 != null) {
                     var hull = GeometryUtilities.ConvexHull(
                        new[] { lastP3, lastP4, p1, p2 });
                     if (hull.Length == 5) {
                        x.DrawQuad(
                           new VertexPositionColor(new Vector3((float)hull[0].X, (float)hull[0].Y, 100), (hull[0] == p1 || hull[0] == p2) ? a.Color : lastTailColor),
                           new VertexPositionColor(new Vector3((float)hull[1].X, (float)hull[1].Y, 100), (hull[1] == p1 || hull[1] == p2) ? a.Color : lastTailColor),
                           new VertexPositionColor(new Vector3((float)hull[2].X, (float)hull[2].Y, 100), (hull[2] == p1 || hull[2] == p2) ? a.Color : lastTailColor),
                           new VertexPositionColor(new Vector3((float)hull[3].X, (float)hull[3].Y, 100), (hull[3] == p1 || hull[3] == p2) ? a.Color : lastTailColor)
                           );
                     } else {
                        x.DrawTriangle(
                           new VertexPositionColor(new Vector3((float)hull[0].X, (float)hull[0].Y, 100), (hull[0] == p1 || hull[0] == p2) ? a.Color : lastTailColor),
                           new VertexPositionColor(new Vector3((float)hull[1].X, (float)hull[1].Y, 100), (hull[1] == p1 || hull[1] == p2) ? a.Color : lastTailColor),
                           new VertexPositionColor(new Vector3((float)hull[2].X, (float)hull[2].Y, 100), (hull[2] == p1 || hull[2] == p2) ? a.Color : lastTailColor));
                     }
                  }

                  lastTailColor = b.Color;
                  lastP3 = p3;
                  lastP4 = p4;

                  x.DrawQuad(
                        new VertexPositionColor(new Vector3((float)p1.X, (float)p1.Y, 100), a.Color),
                        new VertexPositionColor(new Vector3((float)p2.X, (float)p2.Y, 100), a.Color),
                        new VertexPositionColor(new Vector3((float)p3.X, (float)p3.Y, 100), b.Color),
                        new VertexPositionColor(new Vector3((float)p4.X, (float)p4.Y, 100), b.Color)
                     );
               }
               x.End();
            }
         }
      }
Exemplo n.º 37
0
        public void Draw(PrimitiveBatch batch)
        {
            batch.Begin(PrimitiveType.LineList);

            switch (type)
            {
                case DrawType.LineStrip:
                    for (int i = 0; i < transformedVertices.Length -1; i++)
                    {
                        batch.AddVertex(transformedVertices[i], lineColor[i]);
                        batch.AddVertex(transformedVertices[(i + 1)], lineColor[i]);
                    }
                    break;
                case DrawType.LineLoop:
                    for (int i = 0; i < transformedVertices.Length; i++)
                    {
                        batch.AddVertex(transformedVertices[i], lineColor[i]);
                        batch.AddVertex(transformedVertices[(i + 1) % transformedVertices.Length], lineColor[i]);
                    }
                    break;
                case DrawType.LineList:
                    for (int i = 0; i < transformedVertices.Length; i++)
                    {
                        batch.AddVertex(transformedVertices[i], lineColor[i]);
                    }
                    break;
                default:
                    break;
            }

            batch.End();
        }