コード例 #1
0
        protected override void Draw(GameTime gameTime)
        {
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1, 0);

            cCross.Draw(fpsCam.ViewMatrix, fpsCam.ProjectionMatrix);

            //draw triangles
            basicEffect.World              = Matrix.CreateScale(2.0f);
            basicEffect.View               = fpsCam.ViewMatrix;
            basicEffect.Projection         = fpsCam.ProjectionMatrix;
            basicEffect.VertexColorEnabled = true;

            basicEffect.Begin();
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                device.VertexDeclaration = myVertexDeclaration;
                device.DrawUserIndexedPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, 9, indices, 0, 8);
                pass.End();
            }
            basicEffect.End();

            base.Draw(gameTime);
        }
コード例 #2
0
ファイル: DrawTerrain.cs プロジェクト: robwor/openrails
        /// <summary>
        /// This is the method that does the actual drawing of the terrain
        /// </summary>
        /// <param name="drawArea">The area to draw upon (with physical location to pixel transformations)</param>
        public void Draw(DrawArea drawArea)
        {
            UpdateCamera(drawArea);

            device.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
            device.SamplerStates[0].AddressV = TextureAddressMode.Wrap;

            foreach (string textureName in vertexBuffers.Keys)
            {
                basicEffect.Texture = textureManager[textureName];
                basicEffect.Begin();
                foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                {
                    pass.Begin();
                    device.VertexDeclaration = this.vertexDeclaration;
                    device.Vertices[0].SetSource(vertexBuffers[textureName], 0, VertexPositionTexture.SizeInBytes);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, vertexBufferCounts[textureName]);
                    pass.End();
                }
                basicEffect.End();
            }

            UpdateStatusInformation(drawArea.MouseLocation);
        }
コード例 #3
0
ファイル: QuadDrawer.cs プロジェクト: nthfloor/Nebulon12
        /// <summary>
        /// Draws the Quad
        /// </summary>
        /// <param name="View">The view Matrix</param>
        /// <param name="World">The World matrix</param>
        /// <param name="Projection">The projection Matrix</param>
        /// <param name="effectSetup">A Basic Effect to draw with</param>
        public void Draw(Matrix View, Matrix World, Matrix Projection, BasicEffect effectSetup)
        {
            effectSetup.Texture            = texture;
            effectSetup.View               = View;
            effectSetup.World              = World;
            effectSetup.Projection         = Projection;
            effectSetup.TextureEnabled     = true;
            effectSetup.VertexColorEnabled = false;
            dev.VertexDeclaration          = this.quadVertexDecl;

            effectSetup.Begin();
            foreach (EffectPass pass in effectSetup.CurrentTechnique.Passes)
            {
                pass.Begin();

                dev.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                    PrimitiveType.TriangleList, this.Vertices, 0, 4, this.Indices, 0, 2);

                pass.End();
            }
            effectSetup.End();
            effectSetup.TextureEnabled     = false;
            effectSetup.VertexColorEnabled = true;
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: DFVSQY/LearnXNA
        /// <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)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                GraphicsDevice.VertexDeclaration = vertexDeclaration;

                // 使用顶点缓存
                GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, MyVertexPositionColor.SizeInBytes);
                GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

                // 不使用顶点缓存
                // GraphicsDevice.DrawUserPrimitives<MyVertexPositionColor>(PrimitiveType.TriangleList, vertexes, 0, 1);

                pass.End();
            }
            effect.End();

            base.Draw(gameTime);
        }
コード例 #5
0
        protected override void Draw(GameTime gameTime)
        {
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1, 0);

            //draw triangles
            device.RenderState.CullMode = CullMode.None;

            basicEffect.World          = Matrix.Identity;
            basicEffect.View           = fpsCam.ViewMatrix;
            basicEffect.Projection     = fpsCam.ProjectionMatrix;
            basicEffect.Texture        = blueTexture;
            basicEffect.TextureEnabled = true;

            Vector3 lightDirection = new Vector3(0, -3, -10);

            lightDirection.Normalize();
            basicEffect.LightingEnabled                 = true;
            basicEffect.DirectionalLight0.Direction     = lightDirection;
            basicEffect.DirectionalLight0.DiffuseColor  = Color.White.ToVector3();
            basicEffect.DirectionalLight0.Enabled       = true;
            basicEffect.PreferPerPixelLighting          = true;
            basicEffect.DirectionalLight0.SpecularColor = Color.White.ToVector3();
            basicEffect.SpecularPower = 32;

            basicEffect.Begin();
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                device.VertexDeclaration = myVertexDeclaration;
                device.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleStrip, vertices, 0, 2);
                pass.End();
            }
            basicEffect.End();

            base.Draw(gameTime);
        }
コード例 #6
0
ファイル: Debug.cs プロジェクト: nitro404/Asteroids
        public static void drawPoint(Vector2 position, Color colour)
        {
            if (!m_initialized)
            {
                return;
            }

            m_pointVertex[0].Position.X = position.X;
            m_pointVertex[0].Position.Y = position.Y;
            m_pointVertex[0].Color      = colour;

            m_effect.Begin();
            foreach (EffectPass p in m_effect.CurrentTechnique.Passes)
            {
                p.Begin();
                m_graphics.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.PointList, m_pointVertex, 0, 1);
                p.End();
            }
            m_effect.End();
        }
コード例 #7
0
        /// <summary>
        /// Draws the console to the screen if the console is currently open
        /// </summary>
        /// <param name="gameTime">The current game time</param>
        public override void Draw(GameTime gameTime)
        {
            if (!isEnabled)
            {
                return;
            }

            IGraphicsDeviceService graphics =
                (IGraphicsDeviceService)Game.Services.GetService(typeof(IGraphicsDeviceService));

            // measure the height of a line in the current font
            float height = (mFontHeight + mVerticalSpacing) * (mVisibleLineCount + 1);

            // create vertices for the background quad
            Vector3[] vertices = new Vector3[]
            {
                new Vector3(0, 0, 0),
                new Vector3(graphics.GraphicsDevice.Viewport.Width, 0, 0),
                new Vector3(graphics.GraphicsDevice.Viewport.Width, height, 0),
                new Vector3(0, height, 0),
            };

            // create indices for the background quad
            short[] indices = new short[] { 0, 1, 2, 2, 3, 0 };

            // set the vertex declaration
            graphics.GraphicsDevice.VertexDeclaration = mVertexDeclaration;

            // create an orthographic projection to draw the quad as a sprite
            mEffect.Projection = Matrix.CreateOrthographicOffCenter(0,
                                                                    graphics.GraphicsDevice.Viewport.Width,
                                                                    graphics.GraphicsDevice.Viewport.Height, 0,
                                                                    0, 1);

            mEffect.DiffuseColor = mBackgroundColor.ToVector3();
            mEffect.Alpha        = mBackgroundAlpha;

            // save current blending mode
            bool blend = graphics.GraphicsDevice.RenderState.AlphaBlendEnable;

            // enable alpha blending
            graphics.GraphicsDevice.RenderState.AlphaBlendEnable          = true;
            graphics.GraphicsDevice.RenderState.AlphaBlendOperation       = BlendFunction.Add;
            graphics.GraphicsDevice.RenderState.SourceBlend               = Blend.SourceAlpha;
            graphics.GraphicsDevice.RenderState.DestinationBlend          = Blend.InverseSourceAlpha;
            graphics.GraphicsDevice.RenderState.SeparateAlphaBlendEnabled = false;

            mEffect.Begin();

            // draw the quad
            foreach (EffectPass pass in mEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                graphics.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
                                                                  vertices, 0, 4, indices, 0, 2);

                pass.End();
            }

            mEffect.End();

            // restore previous alpha blend
            graphics.GraphicsDevice.RenderState.AlphaBlendEnable = blend;

            // begin drawing the console text
            mSpriteBatch.Begin(SpriteBlendMode.AlphaBlend,
                               SpriteSortMode.Immediate, SaveStateMode.None);

            // measure and draw the prompt
            float   promptsize = mFont.MeasureString(mInputPrompt + " ").X;
            Vector2 position   = new Vector2(mHorizontalPadding, height - mFontHeight - mVerticalSpacing);

            mSpriteBatch.DrawString(mFont, mInputPrompt + " ", position, mDefaultTextColor);
            position.X += promptsize;

            // measure and draw the current input text
            string current = mCurrentText.ToString();

            float cursorpos = position.X;

            cursorpos += mFont.MeasureString(current.Substring(0, mInputPosition)).X;

            if (cursorpos >= (graphics.GraphicsDevice.Viewport.Width - mHorizontalPadding))
            {
                position.X -= (cursorpos - (graphics.GraphicsDevice.Viewport.Width - mHorizontalPadding));
            }

            mSpriteBatch.DrawString(mFont, current, position, mDefaultTextColor);
            position.Y -= (mFontHeight + mVerticalSpacing);
            position.X  = mHorizontalPadding;

            // draw log text
            int messageIndex = (mLog.Count > 0) ? (mCurrentLine) : (-1);
            int lineIndex    = mVisibleLineCount;

            while ((messageIndex >= 0) && (lineIndex > 0))
            {
                if ((mDisplayLevelThreshold > 0) && (mLog[messageIndex].Level > (uint)mDisplayLevelThreshold))
                {
                    messageIndex--;
                    continue;
                }

                string text      = mLog[messageIndex].Text;
                Color  textcolor = (mTextColors.ContainsKey(mLog[messageIndex].Level))
                    ? (mTextColors[mLog[messageIndex].Level])
                    : (mDefaultTextColor);

                if ((mDisplayOptions & ConsoleDisplayOptions.LogLevel) == ConsoleDisplayOptions.LogLevel)
                {
                    text = text.Insert(0, string.Format("[{0}] ", mLog[messageIndex].Level));
                }

                if ((mDisplayOptions & ConsoleDisplayOptions.TimeStamp) == ConsoleDisplayOptions.TimeStamp)
                {
                    TimeSpan time      = mLog[messageIndex].RealTime;
                    string   timestamp = mTimestampFormat;

                    timestamp = timestamp.Replace("{Hr}", time.Hours.ToString());
                    timestamp = timestamp.Replace("{Min}", time.Minutes.ToString());
                    timestamp = timestamp.Replace("{Sec}", time.Seconds.ToString());
                    timestamp = timestamp.Replace("{Ms}", time.Milliseconds.ToString());

                    text = text.Insert(0, timestamp + " ");
                }

                List <string> lines = GetLines(graphics.GraphicsDevice.Viewport.Width, text);

                for (int i = lines.Count - 1; i >= 0; --i)
                {
                    mSpriteBatch.DrawString(mFont, lines[i], position, textcolor);

                    position.Y -= (mFontHeight + mVerticalSpacing);

                    if (--lineIndex <= 0)
                    {
                        break;
                    }
                }

                messageIndex--;
            }

            mSpriteBatch.End();

            // draw the cursor
            if (mDrawCursor)
            {
                position.Y           = height - mFontHeight - mVerticalSpacing;
                mEffect.DiffuseColor = mDefaultTextColor.ToVector3();
                mEffect.Alpha        = 1.0f;

                if (cursorpos >= (graphics.GraphicsDevice.Viewport.Width - mHorizontalPadding))
                {
                    cursorpos -= cursorpos - (graphics.GraphicsDevice.Viewport.Width - mHorizontalPadding);
                }

                Vector3[] cursorverts = new Vector3[]
                {
                    new Vector3(cursorpos, position.Y, 0),
                    new Vector3(cursorpos, position.Y + mFontHeight, 0),
                };

                graphics.GraphicsDevice.VertexDeclaration = mVertexDeclaration;

                mEffect.Begin();
                foreach (EffectPass pass in mEffect.CurrentTechnique.Passes)
                {
                    pass.Begin();
                    graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList,
                                                               cursorverts, 0, 1);
                    pass.End();
                }
                mEffect.End();
            }

            // Handle out-of-page notification
            if (mDrawNotify && (mCurrentLine < mLog.Count - 1))
            {
                float yofs = height - mFontHeight - (mVerticalSpacing * 1.5f);
                mEffect.DiffuseColor = mDefaultTextColor.ToVector3();
                mEffect.Alpha        = 1.0f;

                Vector3[] notifyverts = new Vector3[]
                {
                    new Vector3(0, yofs, 0),
                    new Vector3(graphics.GraphicsDevice.Viewport.Width, yofs, 0),
                };

                graphics.GraphicsDevice.VertexDeclaration = mVertexDeclaration;

                mEffect.Begin();
                foreach (EffectPass pass in mEffect.CurrentTechnique.Passes)
                {
                    pass.Begin();
                    graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList,
                                                               notifyverts, 0, 1);
                    pass.End();
                }
                mEffect.End();
            }

            base.Draw(gameTime);
        }
コード例 #8
0
        /// <summary>
        /// Dibuja nodos por nivel de detalle
        /// </summary>
        /// <param name="gameTime">Tiempo de juego</param>
        /// <param name="lod">Nivel de detalle</param>
        private void LODDraw(GameTime gameTime, LOD lod)
        {
            Color nodeColor = Color.White;

            if (lod == LOD.High)
            {
                nodeColor = Color.Red;
            }
            else if (lod == LOD.Medium)
            {
                nodeColor = Color.Orange;
            }
            else if (lod == LOD.Low)
            {
                nodeColor = Color.Green;
            }

            SceneryInfoNodeDrawn[] nodes = m_Scenery.Scenery.GetNodesDrawn(lod);
            int numVerts = ((nodes.Length * 4) > _MaxNodeVertexes) ? _MaxNodeVertexes : (nodes.Length * 4);

            if ((numVerts > 0) && (m_Scenery.Scenery.Width > 2))
            {
                // Inicializar el buffer de vértices
                int     n     = 0;
                Vector3 pos   = new Vector3();
                float   scale = (1.0f / m_Scenery.Scenery.Width) * 100.0f;
                for (int i = 0; i <= numVerts - 4; i += 4)
                {
                    SceneryInfoNodeDrawn node = nodes[n++];

                    pos.X             = scale * node.UpperLeft.X + 10.0f;
                    pos.Y             = scale * node.UpperLeft.Y + 10.0f;
                    pos.Z             = 0.0f;
                    m_NodeVertexes[i] = new VertexPositionColor(pos, nodeColor);

                    pos.X = scale * node.LowerRight.X + 10.0f;
                    pos.Y = scale * node.UpperLeft.Y + 10.0f;
                    pos.Z = 0.0f;
                    m_NodeVertexes[i + 1] = new VertexPositionColor(pos, nodeColor);

                    pos.X = scale * node.LowerRight.X + 10.0f;
                    pos.Y = scale * node.LowerRight.Y + 10.0f;
                    pos.Z = 0.0f;
                    m_NodeVertexes[i + 2] = new VertexPositionColor(pos, nodeColor);

                    pos.X = scale * node.UpperLeft.X + 10.0f;
                    pos.Y = scale * node.LowerRight.Y + 10.0f;
                    pos.Z = 0.0f;
                    m_NodeVertexes[i + 3] = new VertexPositionColor(pos, nodeColor);
                }

                // Establecer los vértices en el buffer de vértices
                //m_NodesVertexBuffer.SetData<VertexPositionColor>(
                //    m_NodeVertexes,
                //    0,
                //    numVerts,
                //    SetDataOptions.Discard);
                m_NodesVertexBuffer.SetData <VertexPositionColor>(m_NodeVertexes, 0, numVerts);

                // Crear la lista de líneas para los nodos

                // 4 líneas por nodo y 4 vértices por nodo
                int numLines   = numVerts;
                int numIndexes = numLines * 2;
                int v          = 0;
                for (int i = 0; i <= numIndexes - 8; i += 8)
                {
                    m_NodeIndexes[i + 0] = (short)(v + 0); m_NodeIndexes[i + 1] = (short)(v + 1);
                    m_NodeIndexes[i + 2] = (short)(v + 1); m_NodeIndexes[i + 3] = (short)(v + 2);
                    m_NodeIndexes[i + 4] = (short)(v + 2); m_NodeIndexes[i + 5] = (short)(v + 3);
                    m_NodeIndexes[i + 6] = (short)(v + 3); m_NodeIndexes[i + 7] = (short)(v + 0);
                    v += 4;
                }

                // Establecer los índices en el buffer de índices
                //m_NodesIndexBuffer.SetData<short>(
                //    m_NodeIndexes,
                //    0,
                //    numIndexes,
                //    SetDataOptions.Discard);
                m_NodesIndexBuffer.SetData <short>(m_NodeIndexes, 0, numIndexes);

                // Dibujar la lista de líneas
                m_Effect.Begin(SaveStateMode.SaveState);

                foreach (EffectPass pass in m_Effect.CurrentTechnique.Passes)
                {
                    pass.Begin();

                    this.GraphicsDevice.VertexDeclaration = m_NodesVertexDeclaration;
                    this.GraphicsDevice.Vertices[0].SetSource(m_NodesVertexBuffer, 0, VertexPositionColor.SizeInBytes);
                    this.GraphicsDevice.Indices = m_NodesIndexBuffer;

                    this.GraphicsDevice.DrawIndexedPrimitives(
                        PrimitiveType.LineList,
                        0,
                        0,
                        numVerts,
                        0,
                        numLines);

                    pass.End();
                }

                m_Effect.End();

                //Vaciar el dispositivo
                this.GraphicsDevice.VertexDeclaration = null;
                this.GraphicsDevice.Vertices[0].SetSource(null, 0, 0);
                this.GraphicsDevice.Indices = null;
            }
        }
コード例 #9
0
        //Draws the world to each viewport
        public void Draw(GameTime gameTime)
        {
            int cam = 0;

            foreach (Viewport v in ports)
            {
                basicEffect.View = cameras[cam];

                frustums[cam].Matrix = basicEffect.View * basicEffect.Projection;

                ContainmentType currentContainmentType = ContainmentType.Disjoint;

                //Generate HUD data
                Weapon equipDebug = core.players[cam].equipped;

                core.GraphicsDevice.Viewport = v;
                core.GraphicsDevice.Clear(voidColor);

                core.GraphicsDevice.VertexDeclaration = vertexDecl;

                //Pass parameters per viewport
                core.lighting.Parameters["World"].SetValue(Matrix.Identity);
                core.lighting.Parameters["View"].SetValue(cameras[cam]);
                core.lighting.Parameters["Projection"].SetValue(basicEffect.Projection);
                core.lighting.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(basicEffect.World)));

                core.lighting.CurrentTechnique = core.lighting.Techniques["Lighting"];

                //Draw each brush with effects
                //----------------------------------------------------------------------------------------
                foreach (Brush b in core.mapEngine.brushes)
                {
                    BoundingBox bb = b.boundingBox;
                    currentContainmentType = frustums[cam].Contains(bb);

                    if (currentContainmentType != ContainmentType.Disjoint)
                    {
                        foreach (Face face in b.faces)
                        {
                            core.lighting.Begin();
                            if (face.plane.texture != core.mapEngine.textures["common/caulk"])
                            {
                                core.lighting.Parameters["Tex"].SetValue(face.plane.texture);
                                foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes)
                                {
                                    pass.Begin();
                                    VertexPositionNormalTexture[] pointList = face.getPoints();
                                    short[] indices = new short[pointList.Length];
                                    for (int i = 0; i < pointList.Length; i++)
                                    {
                                        indices[i] = (short)i;
                                    }
                                    core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                                        PrimitiveType.TriangleFan,
                                        pointList,
                                        0,
                                        pointList.Length,
                                        indices,
                                        0,
                                        pointList.Length - 2);
                                    pass.End();
                                }
                            }

                            core.lighting.End();
                        }
                    }
                }

                //Draw AI info
                //----------------------------------------------------------------------------------------------------

                basicEffect.Begin();

                /*Vector3 antiLift = new Vector3(0, AIEngine.nodeHeight, 0);
                 * Vector3 renderLift = new Vector3(0, AIEngine.nodeRenderHeight, 0);
                 * foreach (MeshNode m in core.aiEngine.mesh) {
                 *  drawLine(m.position, m.position, new Vector3(1, 1, 1));
                 *  foreach(MeshNode m2 in m.neighbours)
                 *      drawLine(m2.position, m.position, new Vector3(1, 1, 1));
                 * }*/

                //draw the collision grid

                /*for(int k = 0; k < core.physicsEngine.grid.GetLength(2); k++)
                 *  for (int j = 0; j < core.physicsEngine.grid.GetLength(1); j++)
                 *      for (int i = 0; i < core.physicsEngine.grid.GetLength(0); i++) {
                 *          if (!core.physicsEngine.grid[i, j, k].elements.Contains(core.getPlayerForIndex(PlayerIndex.One)))
                 *              continue;
                 *          Vector3 center = new Vector3((i + 0.5f) * core.physicsEngine.cellSize,
                 *                                       (j + 0.5f) * core.physicsEngine.cellSize,
                 *                                       (k + 0.5f) * core.physicsEngine.cellSize);
                 *          drawLine(new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset,
                 *              new Vector3((i + 1) * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, new Vector3(0, 1, 0));
                 *          drawLine(new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset,
                 *              new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, (k + 1) * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, new Vector3(0, 1, 0));
                 *          drawLine(new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset,
                 *              new Vector3(i * core.physicsEngine.cellSize, (j + 1) * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, new Vector3(0, 1, 0));
                 *      }*/

                // basicEffect.End();

                //draw the ai agents

                /*foreach (AIAgent a in core.aiEngine.agents) {
                 *
                 *  if (a.spawnTime > 0) continue;
                 *  BoundingBox bb = a.getBoundingBox();
                 *  currentContainmentType = frustums[cam].Contains(bb);
                 *  if (currentContainmentType != ContainmentType.Disjoint)
                 *  drawBoundingBox(bb, new Vector3(1, 0, 0));
                 *
                 *  //also draw the path
                 *  MeshNode last = null;
                 *  foreach (MeshNode m in a.path) {
                 *      if (last == null) {
                 *          last = m;
                 *          continue;
                 *      }
                 *      drawLine(m.position, last.position, new Vector3(1, 0, 0));
                 *      last = m;
                 *  }
                 * }
                 *
                 * foreach (Player p in core.players) {
                 *
                 *  BoundingBox bb = p.getBoundingBox();
                 *  currentContainmentType = frustums[cam].Contains(bb);
                 *
                 *  if (p.spawnTime > 0) continue;
                 *  if (currentContainmentType != ContainmentType.Disjoint)
                 *      drawBoundingBox(p.getBoundingBox(), new Vector3(0, 1, 0));
                 *  foreach (AIAgent a in core.aiEngine.agents)
                 *      drawLine(p.getPosition() + new Vector3(0, 32, 0), a.getPosition() + new Vector3(0, 32, 0), new Vector3(0, 0, 1));
                 * }*/

                basicEffect.End();



                //Draw each players bullets
                //--------------------------------------------------------------------------------------------

                /*core.lighting.CurrentTechnique = core.lighting.Techniques["Texturing"];
                 * core.lighting.Parameters["Tex"].SetValue(core.bulletTex);
                 * foreach(Player p in core.players){
                 *
                 *  VertexPositionColor[,] bVerts = new VertexPositionColor[p.bullets.Count, 1];
                 *  int i = 0;
                 *
                 *  foreach (Bullet b in p.bullets) {
                 *
                 *      bVerts[i++,0].Position = b.pos;
                 *
                 *  }
                 *
                 *  //If bullets exist for the player
                 *  if (bVerts.Length > 0)
                 *  {
                 *
                 *      for (int j = 0; j < bVerts.Length; ++j )
                 *      {
                 *          VertexPositionColor[] point = new VertexPositionColor[1];
                 *          point[0] = bVerts[j,0];
                 *
                 *          core.lighting.Begin();
                 *          core.GraphicsDevice.RenderState.PointSpriteEnable = true;
                 *          core.GraphicsDevice.RenderState.AlphaBlendEnable = true;
                 *          core.GraphicsDevice.RenderState.SourceBlend = Blend.One;
                 *          core.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
                 *          core.GraphicsDevice.RenderState.DepthBufferWriteEnable = false;
                 *
                 *          core.GraphicsDevice.RenderState.PointSize = (64f * 100) / Vector3.Distance(p.position, point[0].Position);
                 *          foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes)
                 *          {
                 *              pass.Begin();
                 *              core.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
                 *                  PrimitiveType.PointList,
                 *                  point,
                 *                  0,
                 *                  1);
                 *              pass.End();
                 *          }
                 *
                 *          core.lighting.End();
                 *
                 *      }
                 *      core.GraphicsDevice.RenderState.PointSpriteEnable = false;
                 *      core.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
                 *      core.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                 *      core.GraphicsDevice.RenderState.SourceBlend = Blend.One;
                 *      core.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
                 *
                 *  }
                 * }*/

                core.GraphicsDevice.RenderState.AlphaBlendEnable       = true;
                core.GraphicsDevice.RenderState.SourceBlend            = Blend.SourceAlpha;
                core.GraphicsDevice.RenderState.DestinationBlend       = Blend.InverseSourceAlpha;
                core.GraphicsDevice.RenderState.AlphaTestEnable        = true;
                core.GraphicsDevice.RenderState.DepthBufferWriteEnable = false;

                core.lighting.CurrentTechnique = core.lighting.Techniques["FadeTexturing"];

                foreach (Laser l in lasers)
                {
                    if (l.texture == null)
                    {
                        continue;
                    }
                    core.lighting.Parameters["Tex"].SetValue(l.texture);
                    core.lighting.Parameters["Opacity"].SetValue(l.timeLeft / 600f);
                    core.lighting.Begin();
                    foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes)
                    {
                        pass.Begin();
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.horizVerts,
                            0,
                            4,
                            l.indices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.horizVerts,
                            0,
                            4,
                            l.revIndices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.vertVerts,
                            0,
                            4,
                            l.indices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.vertVerts,
                            0,
                            4,
                            l.revIndices,
                            0,
                            2);

                        pass.End();
                    }
                    core.lighting.End();
                }
                core.lighting.Parameters["Opacity"].SetValue(1);
                foreach (Projectile l in projectilesAndExplosions())
                {
                    if (l.texture == null)
                    {
                        continue;
                    }
                    core.lighting.Parameters["Tex"].SetValue(l.texture);
                    core.lighting.Begin();
                    foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes)
                    {
                        pass.Begin();
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.a,
                            0,
                            4,
                            l.indices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.a,
                            0,
                            4,
                            l.revIndices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.b,
                            0,
                            4,
                            l.indices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.b,
                            0,
                            4,
                            l.revIndices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.c,
                            0,
                            4,
                            l.indices,
                            0,
                            2);
                        core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                            PrimitiveType.TriangleList,
                            l.c,
                            0,
                            4,
                            l.revIndices,
                            0,
                            2);

                        pass.End();
                    }
                    core.lighting.End();
                }

                core.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
                core.GraphicsDevice.RenderState.AlphaBlendEnable       = false;
                core.GraphicsDevice.RenderState.SourceBlend            = Blend.One;
                core.GraphicsDevice.RenderState.DestinationBlend       = Blend.InverseSourceAlpha;
                core.GraphicsDevice.RenderState.AlphaTestEnable        = false;

                //Draw item spawner locations
                //----------------------------------------------------------------------------------------------------
                foreach (PickUpGen gen in core.pickupEngine.gens)
                {
                    /*foreach (ModelMesh mesh in core.debugSphere.Meshes) {
                     *
                     *  foreach (BasicEffect effect in mesh.Effects) {
                     *
                     *      effect.World = Matrix.CreateScale(10) * Matrix.CreateTranslation(gen.pos);
                     *      effect.View = cameras[cam];
                     *      effect.Projection = basicEffect.Projection;
                     *
                     *      effect.LightingEnabled = true;
                     *      effect.AmbientLightColor = Color.Brown.ToVector3();
                     *
                     *  }
                     *
                     *  mesh.Draw();
                     *
                     * }*/

                    if (gen.held != null)
                    {
                        Model pickUpModel = core.arrow;

                        switch (gen.itemType)
                        {
                        case PickUp.PickUpType.AMMO: pickUpModel = core.ammoUp; break;

                        case PickUp.PickUpType.HEALTH: pickUpModel = core.medicross; break;
                        }

                        foreach (ModelMesh mesh in pickUpModel.Meshes)
                        {
                            foreach (BasicEffect effect in mesh.Effects)
                            {
                                effect.World           = Matrix.CreateScale(5) * Matrix.CreateRotationY(gen.held.rotation) * Matrix.CreateTranslation(gen.held.pos);
                                effect.View            = cameras[cam];
                                effect.Projection      = basicEffect.Projection;
                                effect.LightingEnabled = true;

                                switch (gen.held.type)
                                {
                                case PickUp.PickUpType.AMMO: { effect.AmbientLightColor = Color.Yellow.ToVector3(); break; }

                                case PickUp.PickUpType.HEALTH: { effect.AmbientLightColor = Color.Green.ToVector3(); break; }

                                case PickUp.PickUpType.LEFT: { effect.AmbientLightColor = Color.DarkBlue.ToVector3(); break; }

                                case PickUp.PickUpType.RIGHT: { effect.AmbientLightColor = Color.Red.ToVector3(); break; }
                                }
                            }

                            mesh.Draw();
                        }
                    }
                }

                //draw rockets
                foreach (Rocket gen in rockets)
                {
                    foreach (ModelMesh mesh in core.debugSphere.Meshes)
                    {
                        foreach (BasicEffect effect in mesh.Effects)
                        {
                            effect.World      = Matrix.CreateScale(10) * Matrix.CreateTranslation(gen.position);
                            effect.View       = cameras[cam];
                            effect.Projection = basicEffect.Projection;

                            effect.LightingEnabled   = true;
                            effect.AmbientLightColor = Color.Brown.ToVector3();
                        }

                        mesh.Draw();
                    }
                }

                //draw explosions


                //--------------------------------------------------------------------------------------------

                //--------------------------------------------------------------------------------------------

                foreach (AIAgent ai in core.aiEngine.agents)
                {
                    if (ai.spawnTime == 0)
                    {
                        foreach (ModelMesh mesh in core.steve.Meshes)
                        {
                            foreach (BasicEffect effect in mesh.Effects)
                            {
                                effect.World      = Matrix.CreateScale(1.5f) * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateRotationY(MathHelper.PiOver2 - ai.direction.X) * Matrix.CreateTranslation(ai.getPosition() + new Vector3(0, core.steve.Meshes[0].BoundingSphere.Radius * 1.5f, 0));
                                effect.View       = cameras[cam];
                                effect.Projection = basicEffect.Projection;

                                //effect.LightingEnabled = true;
                                //effect.AmbientLightColor = Color.Brown.ToVector3();
                            }
                            mesh.Draw();
                        }
                    }
                }

                foreach (Player p in core.players)
                {
                    if (playerMap[p.playerIndex] != cam)
                    {
                        foreach (ModelMesh mesh in core.steve.Meshes)
                        {
                            foreach (BasicEffect effect in mesh.Effects)
                            {
                                effect.World      = Matrix.CreateScale(1.5f) * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateRotationY(MathHelper.PiOver2 - p.direction.X) * Matrix.CreateTranslation(p.getPosition() + new Vector3(0, core.steve.Meshes[0].BoundingSphere.Radius * 1.5f, 0));
                                effect.View       = cameras[cam];
                                effect.Projection = basicEffect.Projection;

                                //effect.LightingEnabled = true;
                                //effect.AmbientLightColor = Color.Brown.ToVector3();
                            }

                            mesh.Draw();
                        }
                    }
                }

                Player    player     = core.players[cam];
                Texture2D weaponIcon = core.weaponIcons[player.equipped.GetType()];
                core.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);

                Vector2 screenCenter = new Vector2(v.Width / 2, v.Height / 2);

                Vector2 ammoPos = new Vector2(screenCenter.X, v.Height - 80);
                core.spriteBatch.Draw(weaponIcon, ammoPos, Color.White);
                core.spriteBatch.DrawString(core.debugFont, player.ammo.ToString(), new Vector2(ammoPos.X + weaponIcon.Width, ammoPos.Y + weaponIcon.Height / 3), Color.White);


                Vector2 hpPos = new Vector2(screenCenter.X, v.Height - 80);
                core.spriteBatch.Draw(core.hudIcons["Health"], hpPos -= new Vector2(core.hudIcons["Health"].Width, 0), Color.White);
                core.spriteBatch.DrawString(core.debugFont, player.health.ToString(), new Vector2(hpPos.X - core.debugFont.MeasureString(player.health.ToString()).X, hpPos.Y + weaponIcon.Height / 3), Color.White);


                String mins = "" + Math.Floor(core.roundTime / 60);
                String secs = "" + Math.Round(core.roundTime % 60);
                core.spriteBatch.DrawString(core.debugFont, mins + ":" + secs, new Vector2(screenCenter.X, 80) - (core.debugFont.MeasureString(mins + ":" + secs) / 2), Color.White);

                core.spriteBatch.Draw(MenuScreen.crossHair, screenCenter, new Rectangle(0, 0, MenuScreen.crossHair.Width, MenuScreen.crossHair.Height),
                                      new Color(new Vector4(Color.White.ToVector3(), 0.65f)),
                                      0f, new Vector2(MenuScreen.crossHair.Width / 2, MenuScreen.crossHair.Height / 2 + 25),
                                      0.05f, SpriteEffects.None, 0);


                if (core.players[cam].drawUpgradePath)
                {
                    //Texture2D downGradeTexture = MenuScreen.selectWheel;
                    Vector2 wheelCenter = new Vector2(screenCenter.X, v.Height - player.currentPathsWheelHeight + MenuScreen.selectWheel.Height / 2);

                    core.spriteBatch.Draw(MenuScreen.loadWheel, wheelCenter, new Rectangle(0, 0, MenuScreen.loadWheel.Width, MenuScreen.loadWheel.Height),
                                          Color.White, MathHelper.PiOver4, new Vector2(MenuScreen.loadWheel.Width / 2, MenuScreen.loadWheel.Height / 2 + 25),
                                          0.5f, SpriteEffects.None, 0);

                    core.spriteBatch.Draw(MenuScreen.ugLeft, wheelCenter, new Rectangle(0, 0, MenuScreen.ugLeft.Width, MenuScreen.ugLeft.Height),
                                          Color.White, -MathHelper.PiOver4, new Vector2(MenuScreen.ugLeft.Width / 2, MenuScreen.ugLeft.Height / 2 + 25),
                                          0.5f, SpriteEffects.None, 0);

                    core.spriteBatch.Draw(MenuScreen.ugRight, wheelCenter, new Rectangle(0, 0, MenuScreen.ugRight.Width, MenuScreen.ugRight.Height),
                                          Color.White, MathHelper.PiOver4, new Vector2(MenuScreen.ugRight.Width / 2, MenuScreen.ugRight.Height / 2 + 25),
                                          0.5f, SpriteEffects.None, 0);

                    Texture2D leftWeaponIcon  = core.weaponIcons[player.equipped.upgradeLeft().GetType()];
                    Texture2D rightWeaponIcon = core.weaponIcons[player.equipped.upgradeRight().GetType()];

                    Vector2 rightPos = new Vector2(wheelCenter.X + v.Width / 4, wheelCenter.Y - 280);
                    core.spriteBatch.Draw(rightWeaponIcon, rightPos - new Vector2(rightWeaponIcon.Width, 0), Color.White);
                    String right = player.equipped.upgradeRight().GetType().ToString();
                    core.spriteBatch.DrawString(core.debugFont, right.Substring(right.LastIndexOf(".") + 1), new Vector2(rightPos.X, rightPos.Y + rightWeaponIcon.Height / 3), Color.White);

                    Vector2 leftPos = new Vector2(wheelCenter.X - v.Width / 4, wheelCenter.Y - 280);
                    core.spriteBatch.Draw(leftWeaponIcon, leftPos, Color.White);
                    String left = player.equipped.upgradeLeft().GetType().ToString();
                    core.spriteBatch.DrawString(core.debugFont, left.Substring(left.LastIndexOf(".") + 1), new Vector2(leftPos.X - core.debugFont.MeasureString(left.Substring(left.LastIndexOf(".") + 1)).X, leftPos.Y + leftWeaponIcon.Height / 3), Color.White);
                }

                if (core.players[cam].showScoreboard)
                {
                    core.spriteBatch.Draw(MenuScreen.loadWheel, screenCenter, new Rectangle(0, 0, MenuScreen.loadWheel.Width, MenuScreen.loadWheel.Height),
                                          Color.White, 0f, new Vector2(MenuScreen.loadWheel.Width / 2, MenuScreen.loadWheel.Height / 2 + 25),
                                          0.5f, SpriteEffects.None, 1f);
                }

                if (core.players[cam].damageAlpha1 != 0 || core.players[cam].damageAlpha2 != 0)
                {
                    core.spriteBatch.Draw(MenuScreen.splatter1,
                                          new Rectangle((int)screenCenter.X - v.Width / 2, (int)screenCenter.Y - v.Height / 2, v.Width, v.Height),
                                          new Rectangle(0, 0, 1024, 576),
                                          new Color((new Vector4(Color.White.ToVector3(), core.players[cam].damageAlpha1)))
                                          , 0f, Vector2.Zero,
                                          SpriteEffects.None, 1f);

                    core.spriteBatch.Draw(MenuScreen.splatter2,
                                          new Rectangle((int)screenCenter.X - v.Width / 2, (int)screenCenter.Y - v.Height / 2, v.Width, v.Height),
                                          new Rectangle(0, 0, 1024, 576),
                                          new Color((new Vector4(Color.White.ToVector3(), core.players[cam].damageAlpha2)))
                                          , 0f, Vector2.Zero,
                                          SpriteEffects.None, 1f);
                }

                core.spriteBatch.End();
                cam++;
            }
        }
コード例 #10
0
        private static void drawHeightfield(HeightFieldShape heightFieldShape, GraphicsDevice device)
        {
            VertexPositionNormalTexture[] cubeVertices;
            VertexDeclaration             basicEffectVertexDeclaration;
            VertexBuffer vertexBuffer;
            var          white     = new Color(1, 1, 1, 1);
            int          vertexNum = (heightFieldShape.HeightField.NumberOfRows - 1) *
                                     (heightFieldShape.HeightField.NumberOfColumns - 1) * 3 * 2;
            var     vertices = new VertexPositionColor[vertexNum];
            int     triangleIndex;
            Vector3 pos;
            int     vertexIndex = 0;

            HeightFieldShape.GetTriangleResult triangle;
            Camera _camera = CamerasManager.Instance.GetActiveCamera();

            for (int row = 0; row < heightFieldShape.HeightField.NumberOfRows - 1; row++)
            {
                for (int column = 0; column < heightFieldShape.HeightField.NumberOfColumns - 1; column++)
                {
                    triangleIndex = 2 * (row * heightFieldShape.HeightField.NumberOfColumns + column);

                    triangle = heightFieldShape.GetTriangle(triangleIndex);


                    pos = new Vector3(triangle.WorldTriangle.Vertex2.X, triangle.WorldTriangle.Vertex2.Y,
                                      triangle.WorldTriangle.Vertex2.Z);
                    vertices[vertexIndex++] = new VertexPositionColor(pos, white);

                    pos = new Vector3(triangle.WorldTriangle.Vertex1.X, triangle.WorldTriangle.Vertex1.Y,
                                      triangle.WorldTriangle.Vertex1.Z);
                    vertices[vertexIndex++] = new VertexPositionColor(pos, white);

                    pos = new Vector3(triangle.WorldTriangle.Vertex0.X, triangle.WorldTriangle.Vertex0.Y,
                                      triangle.WorldTriangle.Vertex0.Z);
                    vertices[vertexIndex++] = new VertexPositionColor(pos, white);

                    triangleIndex++;

                    triangle = heightFieldShape.GetTriangle(triangleIndex);

                    pos = new Vector3(triangle.WorldTriangle.Vertex2.X, triangle.WorldTriangle.Vertex2.Y,
                                      triangle.WorldTriangle.Vertex2.Z);
                    vertices[vertexIndex++] = new VertexPositionColor(pos, white);

                    pos = new Vector3(triangle.WorldTriangle.Vertex1.X, triangle.WorldTriangle.Vertex1.Y,
                                      triangle.WorldTriangle.Vertex1.Z);
                    vertices[vertexIndex++] = new VertexPositionColor(pos, white);

                    pos = new Vector3(triangle.WorldTriangle.Vertex0.X, triangle.WorldTriangle.Vertex0.Y,
                                      triangle.WorldTriangle.Vertex0.Z);
                    vertices[vertexIndex++] = new VertexPositionColor(pos, white);
                }
            }
            //inicio do código do cubo
            //InitializeCube();

            basicEffectVertexDeclaration = new VertexDeclaration(
                device, VertexPositionNormalTexture.VertexElements);

            var basicEffect = new BasicEffect(device, null);

            basicEffect.Alpha             = 1.0f;
            basicEffect.DiffuseColor      = new Vector3(0.2f, 0.0f, 1.0f);
            basicEffect.SpecularColor     = new Vector3(0.25f, 0.25f, 0.25f);
            basicEffect.SpecularPower     = 5.0f;
            basicEffect.AmbientLightColor = new Vector3(0.75f, 0.75f, 0.75f);

            //basicEffect.DirectionalLight0.Enabled = true;
            //basicEffect.DirectionalLight0.DiffuseColor = Vector3.One;
            //basicEffect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(1.0f, -1.0f, -1.0f));
            //basicEffect.DirectionalLight0.SpecularColor = Vector3.One;

            //basicEffect.DirectionalLight1.Enabled = true;
            //basicEffect.DirectionalLight1.DiffuseColor = new Vector3(0.5f, 0.5f, 0.5f);
            //basicEffect.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(-1.0f, -1.0f, 1.0f));
            //basicEffect.DirectionalLight1.SpecularColor = new Vector3(0.5f, 0.5f, 0.5f);

            //basicEffect.LightingEnabled = true;

            basicEffect.World      = Matrix.CreateScale(1, 1, 1);
            basicEffect.View       = _camera.View;
            basicEffect.Projection = _camera.Projection;

            //NoNameEngine.Instance.Device.Clear(Color.SteelBlue);
            //NoNameEngine.Instance.Device.RenderState.CullMode = CullMode.CullClockwiseFace;

            device.VertexDeclaration = basicEffectVertexDeclaration;

            vertexBuffer = new VertexBuffer(
                device,
                VertexPositionColor.SizeInBytes * vertexNum,
                BufferUsage.None
                );

            vertexBuffer.SetData(vertices);

            device.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionColor.SizeInBytes);


            // This code would go between a NoNameEngine.Instance.Device
            // BeginScene-EndScene block.
            basicEffect.Begin();
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                //this.NoNameEngine.Instance.Device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, vertexNum / 3);

                device.DrawPrimitives(
                    PrimitiveType.TriangleList,
                    0,
                    vertexNum / 3
                    );

                //NoNameEngine.Instance.Device.DrawPrimitives(
                //     PrimitiveType.TriangleList,
                //     0,
                //     12
                // );


                pass.End();
            }
            basicEffect.End();
        }
コード例 #11
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)
        {
            GraphicsDevice.Clear(bgColor);

            GraphicsDevice.RenderState.CullMode = CullMode.None;

            GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionNormalTexture.VertexElements);

            effect.Texture = pistolPete;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleStrip, frontVertices, 0, 2);
                pass.End();
            }
            effect.End();

            effect.Texture = osuLogo;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleStrip, backVertices, 0, 2);
                pass.End();
            }
            effect.End();

            effect.Texture = red;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleStrip, leftVertices, 0, 2);
                pass.End();
            }
            effect.End();

            effect.Texture = blue;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleStrip, rightVertices, 0, 2);
                pass.End();
            }
            effect.End();

            effect.Texture = orange;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleStrip, topVertices, 0, 2);
                pass.End();
            }
            effect.End();

            effect.Texture = black;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleStrip, bottomVertices, 0, 2);
                pass.End();
            }
            effect.End();

            base.Draw(gameTime);
        }
コード例 #12
0
        public void Render(IXNAGame _game)
        {
            if (!enabled)
            {
                return;
            }
            //game.GraphicsDevice.Clear(Color.LightBlue);

            game.GraphicsDevice.VertexDeclaration            = vertexDecl;
            game.GraphicsDevice.RenderState.AlphaBlendEnable = false;
            _visualizationEffect.World      = Matrix.Identity;
            _visualizationEffect.View       = game.Camera.View;
            _visualizationEffect.Projection = game.Camera.Projection;

            DebugRenderable data = physXScene.GetDebugRenderable();

            _visualizationEffect.Begin();

            foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                if (data.PointCount > 0)
                {
                    DebugPoint[] points = data.GetDebugPoints();

                    game.GraphicsDevice.DrawUserPrimitives <DebugPoint>(PrimitiveType.PointList, points, 0, points.Length);
                }

                if (data.LineCount > 0)
                {
                    DebugLine[] lines = data.GetDebugLines();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2 * 2];
                    for (int x = 0; x < data.LineCount; x++)
                    {
                        DebugLine line = lines[x];

                        vertices[x * 4 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color));
                        vertices[x * 4 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color));

                        vertices[x * 4 + 2] = new VertexPositionColor(new Vector3(line.Point0.X, 0, line.Point0.Z), Color.Black);
                        vertices[x * 4 + 3] = new VertexPositionColor(new Vector3(line.Point1.X, 0, line.Point1.Z), Color.Black);
                    }

                    game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length * 2);
                }

                if (data.TriangleCount > 0)
                {
                    DebugTriangle[] triangles = data.GetDebugTriangles();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3];
                    for (int x = 0; x < data.TriangleCount; x++)
                    {
                        DebugTriangle triangle = triangles[x];

                        vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color));
                    }

                    game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length);
                }

                pass.End();
            }

            _visualizationEffect.End();
        }
コード例 #13
0
ファイル: PhysX.cs プロジェクト: ARLM-Attic/xna-physy-tools
        /// <summary>
        /// Allows physics to draw itself information, only if DebugMode state is activated
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Draw()
        {
            _camera = CamerasManager.Instance.GetActiveCamera();

            graphicsDevice.VertexDeclaration = new VertexDeclaration(graphicsDevice, VertexPositionColor.VertexElements);


            _visualizationEffect.World      = Matrix.Identity;
            _visualizationEffect.View       = _camera.View;
            _visualizationEffect.Projection = _camera.Projection;

            DebugRenderable data = Scene.GetDebugRenderable();

            _visualizationEffect.Begin();

            foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                if (data.PointCount > 0)
                {
                    DebugPoint[] points = data.GetDebugPoints();

                    graphicsDevice.DrawUserPrimitives(PrimitiveType.PointList, points, 0, points.Length);
                }

                if (data.LineCount > 0)
                {
                    DebugLine[] lines = data.GetDebugLines();

                    var vertices = new VertexPositionColor[data.LineCount * 2];
                    for (int x = 0; x < data.LineCount; x++)
                    {
                        DebugLine line = lines[x];

                        vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color));
                        vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color));
                    }

                    graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, lines.Length);
                }

                if (data.TriangleCount > 0)
                {
                    DebugTriangle[] triangles = data.GetDebugTriangles();

                    var vertices = new VertexPositionColor[data.TriangleCount * 3];
                    for (int x = 0; x < data.TriangleCount; x++)
                    {
                        DebugTriangle triangle = triangles[x];

                        vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color));
                    }

                    graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, triangles.Length);
                }

                pass.End();
            }

            _visualizationEffect.End();
        }
コード例 #14
0
ファイル: DebugOverlay.cs プロジェクト: doggan/xna-debug-draw
    public void Draw(Matrix projectionMatrix, Matrix viewMatrix)
    {
        if (!IsEnabled)
        {
            return;
        }

        mBasicEffect.Projection = projectionMatrix;
        mBasicEffect.World      = Matrix.Identity;
        mBasicEffect.View       = viewMatrix;

        bool savedDepthBuffer = mGraphicsDevice.RenderState.DepthBufferEnable;

        mGraphicsDevice.RenderState.DepthBufferEnable = true;

        #region Triangle primitives.
        // Change device states.
        FillMode savedFillMode = mGraphicsDevice.RenderState.FillMode;
        mGraphicsDevice.RenderState.FillMode = FillMode.WireFrame;
        mGraphicsDevice.VertexDeclaration    = mVertexDeclaration;

        foreach (Primitive p in mTrianglePrimitives)
        {
            // Index buffer.
            short[] triListIndices = new short[p.mVertices.Count];

            // Populate the array with references to indices in the vertex buffer.
            for (int i = 0; i < triListIndices.Length; i++)
            {
                triListIndices[i] = (short)i;
            }

            // Vertex buffer setup.
            VertexBuffer vertexBuffer = new VertexBuffer(
                mGraphicsDevice,
                VertexPositionColor.SizeInBytes * p.mVertices.Count,
                BufferUsage.None);

            vertexBuffer.SetData <VertexPositionColor>(p.mVertices.ToArray());

            // Effect setup.
            mBasicEffect.DiffuseColor = p.mColor.ToVector3();

            mBasicEffect.Begin();

            foreach (EffectPass pass in mBasicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                mGraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>(
                    PrimitiveType.TriangleList,
                    p.mVertices.ToArray(),                      // Vertex data.
                    0,                                          // Vertex buffer offset for each element in index buffer.
                    p.mVertices.Count,                          // # of vertices.
                    triListIndices,                             // Index buffer.
                    0,                                          // First index element to read.
                    p.mVertices.Count / 3                       // # of primitives to draw.
                    );

                pass.End();
            }
            mBasicEffect.End();
        }

        // Reset changed device states.
        mGraphicsDevice.RenderState.FillMode = savedFillMode;

        mTrianglePrimitives.Clear();
        #endregion

        #region Line primitives.
        foreach (Primitive p in mLinePrimitives)
        {
            // Index buffer.
            short[] lineListIndices = new short[p.mVertices.Count];

            // Populate the array with references to indices in the vertex buffer.
            for (int i = 0; i < lineListIndices.Length - 1; i += 2)
            {
                lineListIndices[i]     = (short)(i);
                lineListIndices[i + 1] = (short)(i + 1);
            }

            // Vertex buffer setup.
            VertexBuffer vertexBuffer = new VertexBuffer(
                mGraphicsDevice,
                VertexPositionColor.SizeInBytes * p.mVertices.Count,
                BufferUsage.None);

            vertexBuffer.SetData <VertexPositionColor>(p.mVertices.ToArray());

            // Effect setup.
            mBasicEffect.DiffuseColor = p.mColor.ToVector3();

            mGraphicsDevice.VertexDeclaration = mVertexDeclaration;

            mBasicEffect.Begin();

            foreach (EffectPass pass in mBasicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                mGraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>(
                    PrimitiveType.LineStrip,
                    p.mVertices.ToArray(),                      // Vertex data.
                    0,                                          // Vertex buffer offset for each element in index buffer.
                    p.mVertices.Count,                          // # of vertices.
                    lineListIndices,                            // Index buffer.
                    0,                                          // First index element to read.
                    p.mVertices.Count - 1                       // # of primitives to draw.
                    );

                pass.End();
            }
            mBasicEffect.End();
        }

        mLinePrimitives.Clear();
        #endregion

        #region Point primitives.
        foreach (Primitive p in mPointPrimitives)
        {
            if (p.mVertices.Count > 0)
            {
                // Vertex buffer setup.
                VertexBuffer pointVertexBuffer = new VertexBuffer(
                    mGraphicsDevice,
                    VertexPositionColor.SizeInBytes * p.mVertices.Count,
                    BufferUsage.None);

                pointVertexBuffer.SetData <VertexPositionColor>(p.mVertices.ToArray());

                // Effect setup.
                mBasicEffect.DiffuseColor = p.mColor.ToVector3();

                mGraphicsDevice.VertexDeclaration = mVertexDeclaration;

                mBasicEffect.Begin();

                foreach (EffectPass pass in mBasicEffect.CurrentTechnique.Passes)
                {
                    pass.Begin();

                    mGraphicsDevice.DrawUserPrimitives <VertexPositionColor>(
                        PrimitiveType.PointList,
                        p.mVertices.ToArray(),
                        0,
                        p.mVertices.Count
                        );

                    pass.End();
                }
                mBasicEffect.End();
            }
        }

        mPointPrimitives.Clear();
        #endregion

        #region Screen text.
        // Change device states.
        savedFillMode = mGraphicsDevice.RenderState.FillMode;
        mGraphicsDevice.RenderState.FillMode = FillMode.Solid;

        mBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);

        foreach (ScreenTextPrimitive st in mScreenText)
        {
            mBatch.DrawString(mFont, st.mText, st.mPos, st.mColor);
        }

        mBatch.End();

        // Reset changed device states.
        mGraphicsDevice.RenderState.FillMode = savedFillMode;

        mScreenText.Clear();
        #endregion

        mGraphicsDevice.RenderState.DepthBufferEnable = savedDepthBuffer;
    }
コード例 #15
0
        /// <summary>
        /// Renders the scene.
        /// </summary>
        private void mWinForm_OnFrameRender(GraphicsDevice pDevice)
        {
            Device.RenderState.DepthBufferEnable      = true;
            Device.RenderState.DepthBufferWriteEnable = true;
            Device.RenderState.AlphaBlendEnable       = false;
            Device.RenderState.PointSize = 10.0f;

            // Configure effects
            m_HeadEffect.World      = this.mWorldMat;
            m_HeadEffect.View       = mViewMat;
            m_HeadEffect.Projection = mProjectionMat;

            m_BodyEffect.World      = this.mWorldMat;
            m_BodyEffect.View       = mViewMat;
            m_BodyEffect.Projection = mProjectionMat;

            m_SkeletonEffect.World      = this.mWorldMat;
            m_SkeletonEffect.View       = mViewMat;
            m_SkeletonEffect.Projection = mProjectionMat;
            m_SkeletonEffect.EnableDefaultLighting();

            if (m_RenderSim.GetHeadTexture() != null)
            {
                m_HeadEffect.Texture        = m_RenderSim.GetHeadTexture();
                m_HeadEffect.TextureEnabled = true;

                m_HeadEffect.EnableDefaultLighting();
            }

            if (m_RenderSim.GetBodyTexture() != null)
            {
                m_BodyEffect.Texture        = m_RenderSim.GetBodyTexture();
                m_BodyEffect.TextureEnabled = true;

                m_BodyEffect.EnableDefaultLighting();
            }

            m_HeadEffect.CommitChanges();
            m_BodyEffect.CommitChanges();
            m_SkeletonEffect.CommitChanges();

            if (m_LoadBodyComplete)
            {
                if (!m_RenderSkeleton)
                {
                    foreach (Face Fce in m_RenderSim.GetBodyMesh().FaceData)
                    {
                        // Draw
                        m_BodyEffect.Begin();
                        m_BodyEffect.Techniques[0].Passes[0].Begin();

                        VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                        Vertex[0] = m_RenderSim.GetBodyMesh().VertexTexNormalPositions[Fce.VertexA];
                        Vertex[1] = m_RenderSim.GetBodyMesh().VertexTexNormalPositions[Fce.VertexB];
                        Vertex[2] = m_RenderSim.GetBodyMesh().VertexTexNormalPositions[Fce.VertexC];

                        Vertex[0].TextureCoordinate = m_RenderSim.GetBodyMesh().VertexTexNormalPositions[Fce.VertexA].TextureCoordinate;
                        Vertex[1].TextureCoordinate = m_RenderSim.GetBodyMesh().VertexTexNormalPositions[Fce.VertexB].TextureCoordinate;
                        Vertex[2].TextureCoordinate = m_RenderSim.GetBodyMesh().VertexTexNormalPositions[Fce.VertexC].TextureCoordinate;

                        pDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                                                                                 Vertex, 0, 1);

                        m_BodyEffect.Techniques[0].Passes[0].End();
                        m_BodyEffect.End();
                    }

                    m_RenderSim.GetBodyMesh().TransformVertices(m_RenderSim.SimSkeleton.RootBone);
                    m_RenderSim.GetBodyMesh().ProcessMesh(m_RenderSim.SimSkeleton, false);
                }
                else
                {
                    DrawSkeleton(m_RenderSim.SimSkeleton);
                }
            }

            if (m_LoadHeadComplete)
            {
                foreach (Face Fce in m_RenderSim.GetHeadMesh().FaceData)
                {
                    // Draw
                    m_HeadEffect.Begin();
                    m_HeadEffect.Techniques[0].Passes[0].Begin();

                    VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                    Vertex[0] = m_RenderSim.GetHeadMesh().VertexTexNormalPositions[Fce.VertexA];
                    Vertex[1] = m_RenderSim.GetHeadMesh().VertexTexNormalPositions[Fce.VertexB];
                    Vertex[2] = m_RenderSim.GetHeadMesh().VertexTexNormalPositions[Fce.VertexC];

                    Vertex[0].TextureCoordinate = m_RenderSim.GetHeadMesh().VertexTexNormalPositions[Fce.VertexA].TextureCoordinate;
                    Vertex[1].TextureCoordinate = m_RenderSim.GetHeadMesh().VertexTexNormalPositions[Fce.VertexB].TextureCoordinate;
                    Vertex[2].TextureCoordinate = m_RenderSim.GetHeadMesh().VertexTexNormalPositions[Fce.VertexC].TextureCoordinate;

                    pDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                                                                             Vertex, 0, 1);

                    m_HeadEffect.Techniques[0].Passes[0].End();
                    m_HeadEffect.End();
                }

                m_RenderSim.GetHeadMesh().ProcessMesh(m_RenderSim.SimSkeleton, true);
            }
        }
コード例 #16
0
        protected override void Draw()
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            GraphicsDevice.VertexDeclaration             = vertexDeclaration;
            GraphicsDevice.RenderState.DepthBufferEnable = true;

            GraphicsDevice.RenderState.CullMode = CullMode.None;

            textureEffect.World      = World;
            textureEffect.View       = View;
            textureEffect.Projection = Projection;

            textureEffect.EnableDefaultLighting();

            textureEffect.TextureEnabled = true;
            textureEffect.Texture        = glassTexture;

            textureEffect.DirectionalLight0.Enabled       = true;
            textureEffect.DirectionalLight0.DiffuseColor  = Vector3.One;
            textureEffect.DirectionalLight0.Direction     = Vector3.Normalize(new Vector3(1.0f, 1.0f, -1.0f));
            textureEffect.DirectionalLight0.SpecularColor = Vector3.One;

            textureEffect.Begin();

            foreach (EffectPass pass in textureEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                for (int i = 0; i < vertexData.Count; i++)
                {
                    GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                                                                                           vertexData[i], 0, vertexData[i].Length, indexData[i], 0, indexData[i].Length / 3);
                }

                /*GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                 *  vertexData, 0, vertexData.Length, indexDataTriangles, 0, indexDataTriangles.Length / 3);              */

                pass.End();
            }

            textureEffect.End();

            /* colorEffect.World = World;
             * colorEffect.View = View;
             * colorEffect.Projection = Projection;
             *
             * GraphicsDevice.VertexDeclaration = vertexDeclaration2;
             *
             * colorEffect.Begin();
             *
             * foreach (EffectPass pass in colorEffect.CurrentTechnique.Passes)
             * {
             *   pass.Begin();
             *
             *   GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
             * vertexData, 0, vertexData.Length, indexDataTriangles, 0, indexDataTriangles.Length / 3);
             *
             *
             *   pass.End();
             * }
             *
             * colorEffect.End();*/
        }
コード例 #17
0
        public void Render()
        {
            if (selectedBoneIndex < 0 || renderedBonesCount == 0)
            {
                return;
            }
            Color DefaultBoneColor = new Color(Color.White, 0.35f);

            Armature.Bone selectedBone     = null;
            Vector3       selectedBoneProj = Vector3.Zero;

            VertexPositionColor[] points = new VertexPositionColor[renderedBonesCount];
            int j = 0;

            for (int i = 0; i < visibleBones.Count; i++)
            {
                Vector3 boneProj = visibleBonesProjections[i];
                if (boneProj.Z < 0)
                {
                    continue;
                }
                Color color;
                if (i == selectedBoneIndex)
                {
                    color            = Color.Red;
                    selectedBone     = visibleBones[i];
                    selectedBoneProj = boneProj;
                }
                else
                {
                    color = DefaultBoneColor;
                }
                points[j] = new VertexPositionColor(boneProj, color);
                j++;
            }

            graphicsDevice.RenderState.PointSize = 5;
            graphicsDevice.VertexDeclaration     = vertexDeclaration;

            graphicsDevice.RenderState.AlphaBlendEnable = true;
            graphicsDevice.RenderState.SourceBlend      = Blend.SourceAlpha;
            graphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;

            basicEffect.VertexColorEnabled = true;
            basicEffect.World      = Matrix.Identity;
            basicEffect.View       = viewMatrix;
            basicEffect.Projection = projectionMatrix;

            basicEffect.Begin();
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.PointList, points, 0, points.Length);
                pass.End();
            }
            basicEffect.End();

            graphicsDevice.RenderState.AlphaBlendEnable = false;

            if (game.DisplayBoneNames && selectedBone != null)
            {
                spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
                int    x     = (int)Math.Round(selectedBoneProj.X);
                int    y     = (int)Math.Round(screenHeight - 1 - selectedBoneProj.Y - font.LineSpacing - 3);
                string label = selectedBone.name;
                spriteBatch.DrawString(font, label, new Vector2(x + 1, y + 1), Color.Black);
                spriteBatch.DrawString(font, label, new Vector2(x, y), Color.Yellow);
                spriteBatch.End();
            }
        }
コード例 #18
0
    void DrawTriangle(GraphicsDevice graphicsDevice, Vector3 p0, Vector3 p1, Vector3 p2, Microsoft.Xna.Framework.Graphics.Color c)
    {
        /*
         * DrawLine_c.DrawLine(graphicsDevice, p0, p1, c);
         * DrawLine_c.DrawLine(graphicsDevice, p1, p2, c);
         * DrawLine_c.DrawLine(graphicsDevice, p2, p0, c);
         */
        if (s_basicEffect == null)
        {
            s_basicEffect = new BasicEffect(graphicsDevice, null);
        }
        s_basicEffect.VertexColorEnabled = false;
        s_basicEffect.Alpha          = 0.5f;
        s_basicEffect.View           = Camera_c.s_view;
        s_basicEffect.Projection     = Camera_c.s_projection;
        s_basicEffect.World          = Matrix.Identity;
        s_basicEffect.TextureEnabled = false;
        s_basicEffect.DiffuseColor   = new Vector3(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f);
        s_basicEffect.EmissiveColor  = new Vector3(0.0f, 0.0f, 0.0f);

        s_basicEffect.EnableDefaultLighting();
        s_basicEffect.DirectionalLight0.Enabled = true;


        graphicsDevice.RenderState.AlphaBlendEnable  = true;
        graphicsDevice.RenderState.SourceBlend       = Blend.SourceAlpha;
        graphicsDevice.RenderState.DestinationBlend  = Blend.InverseSourceAlpha;
        graphicsDevice.RenderState.DepthBufferEnable = true;
        graphicsDevice.RenderState.CullMode          = CullMode.CullClockwiseFace;
        graphicsDevice.RenderState.FillMode          = FillMode.Solid;

        if (s_vertexDeclaration == null)
        {
            s_vertexDeclaration =
                new VertexDeclaration(graphicsDevice, Microsoft.Xna.Framework.Graphics.VertexPositionNormalTexture.VertexElements);
        }

        graphicsDevice.VertexDeclaration = s_vertexDeclaration;


        Vector3 n = Vector3.Cross(p0 - p1, p1 - p2);
        List <VertexPositionNormalTexture> points = new List <VertexPositionNormalTexture>();

        points.Add(new VertexPositionNormalTexture(p0, n, Vector2.Zero));
        points.Add(new VertexPositionNormalTexture(p1, n, Vector2.Zero));
        points.Add(new VertexPositionNormalTexture(p2, n, Vector2.Zero));
        int numTris = 1;

        s_basicEffect.Begin();
        foreach (EffectPass effectPass in s_basicEffect.CurrentTechnique.Passes)
        {
            effectPass.Begin();
            graphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                                                                            points.ToArray(),
                                                                            0,
                                                                            numTris);

            effectPass.End();
        }
        s_basicEffect.End();
    }
コード例 #19
0
ファイル: ScoreVisual.cs プロジェクト: winterdl/LD10
        public override void Draw()
        {
            GraphicsDevice device = GameContainer.Graphics.GraphicsDevice;

            device.RenderState.AlphaBlendEnable = true;
            device.RenderState.SourceBlend      = Blend.SourceAlpha;
            device.RenderState.DestinationBlend = Blend.InverseSourceAlpha;

            effect.LightingEnabled    = false;
            effect.VertexColorEnabled = false;
            effect.TextureEnabled     = true;
            effect.Alpha = 1;

            float scoreOffset = 1.85f;

            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.VertexDeclaration = vertexDecl;
                device.Indices           = ib;
                device.Vertices[0].SetSource(vb, 0, VertexPositionColorTexture.SizeInBytes);

                switch (counter[PlayerIndex.One])
                {
                default: effect.Texture = score0; break;

                case 0: effect.Texture = score0; break;

                case 1: effect.Texture = score1; break;

                case 2: effect.Texture = score2; break;
                    //case 3: effect.Texture = score3; break;
                }

                effect.World      = Matrix.CreateTranslation(new Vector3(-(field.Width / 2) + (width / 2) + scoreOffset, 0.2f, 0));
                effect.View       = camera.View;
                effect.Projection = camera.Projection;
                effect.CommitChanges();

                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);

                switch (counter[PlayerIndex.Two])
                {
                default: effect.Texture = score0; break;

                case 0: effect.Texture = score0; break;

                case 1: effect.Texture = score1; break;

                case 2: effect.Texture = score2; break;
                    //case 3: effect.Texture = score3; break;
                }

                effect.World      = Matrix.CreateTranslation(new Vector3((field.Width / 2) - (width / 2) - scoreOffset, 0.2f, 0));
                effect.View       = camera.View;
                effect.Projection = camera.Projection;
                effect.CommitChanges();

                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);

                pass.End();
            }
            effect.End();

            device.RenderState.AlphaBlendEnable = false;
        }
コード例 #20
0
ファイル: Grid.cs プロジェクト: jhauberg-archived/LD14
        public void Draw(GameTime gameTime)
        {
            device.VertexDeclaration = gridVertexDeclaration;

            device.RenderState.AlphaBlendEnable = true;
            device.RenderState.SourceBlend      = Blend.SourceAlpha;
            device.RenderState.DestinationBlend = Blend.InverseSourceAlpha;

            bfx.Projection = Projection;
            bfx.View       = View;

            bfx.World = Matrix.Identity;

            bfx.Alpha = 0.35f;

            bfx.Begin();
            foreach (EffectPass pass in bfx.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.DrawUserPrimitives(PrimitiveType.LineList, gridVertices, 0, gridVertices.Length / 2);
                device.DrawUserPrimitives(PrimitiveType.TriangleStrip, gridFillVertices, 0, 2);

                pass.End();
            }
            bfx.End();

            bfx.Alpha = 0.45f;

            if (MovableTiles.Count > 0 && ShowMovableTiles)
            {
                foreach (Vector2 tile in MovableTiles)
                {
                    if (tile.X >= columns || tile.X < 0 || tile.Y >= rows || tile.Y < 0)
                    {
                        continue;
                    }

                    bfx.World = Matrix.CreateTranslation(new Vector3(tile.X * tileSize, 0, tile.Y * tileSize));

                    bfx.Begin();
                    foreach (EffectPass pass in bfx.CurrentTechnique.Passes)
                    {
                        pass.Begin();

                        device.DrawUserPrimitives(PrimitiveType.TriangleStrip, gridSelectionVertices, 0, 2);

                        pass.End();
                    }
                    bfx.End();
                }
            }

            bfx.Alpha = 0.35f;

            if (isHoveringOnTile)
            {
                bfx.World = Matrix.CreateTranslation(new Vector3(tx * tileSize, 0, tz * tileSize));

                bfx.Begin();
                foreach (EffectPass pass in bfx.CurrentTechnique.Passes)
                {
                    pass.Begin();

                    device.DrawUserPrimitives(PrimitiveType.TriangleStrip, gridSelectionVertices, 0, 2);

                    pass.End();
                }
                bfx.End();
            }
        }
コード例 #21
0
        public override void Draw(GameTime gameTime)
        {
            this.Device.Clear(Color.LightBlue);

            this.Device.VertexDeclaration = new VertexDeclaration(this.Device, VertexPositionColor.VertexElements);

            _visualizationEffect.World      = Matrix.Identity;
            _visualizationEffect.View       = this.Camera.View;
            _visualizationEffect.Projection = this.Camera.Projection;

            DebugRenderable data = this.Scene.GetDebugRenderable();

            _visualizationEffect.Begin();

            foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                if (data.PointCount > 0)
                {
                    DebugPoint[] points = data.GetDebugPoints();

                    this.Device.DrawUserPrimitives <DebugPoint>(PrimitiveType.PointList, points, 0, points.Length);
                }

                if (data.LineCount > 0)
                {
                    DebugLine[] lines = data.GetDebugLines();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2];
                    for (int x = 0; x < data.LineCount; x++)
                    {
                        DebugLine line = lines[x];

                        vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color));
                        vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color));
                    }

                    this.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length);
                }

                if (data.TriangleCount > 0)
                {
                    DebugTriangle[] triangles = data.GetDebugTriangles();

                    VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3];
                    for (int x = 0; x < data.TriangleCount; x++)
                    {
                        DebugTriangle triangle = triangles[x];

                        vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color));
                        vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color));
                    }

                    this.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length);
                }

                pass.End();
            }

            _visualizationEffect.End();
        }
コード例 #22
0
        public static void Draw(GameTime gameTime, Matrix view, Matrix projection)
        {
            // Update our effect with the matrices.
            effect.View       = view;
            effect.Projection = projection;

            // Calculate the total number of vertices we're going to be rendering.
            int vertexCount = 0;

            foreach (var shape in activeShapes)
            {
                vertexCount += shape.LineCount * 2;
            }

            // If we have some vertices to draw
            if (vertexCount > 0)
            {
                // Make sure our array is large enough
                if (verts.Length < vertexCount)
                {
                    // If we have to resize, we make our array twice as large as necessary so
                    // we hopefully won't have to resize it for a while.
                    verts = new VertexPositionColor[vertexCount * 2];
                }

                // Now go through the shapes again to move the vertices to our array and
                // add up the number of lines to draw.
                int lineCount = 0;
                int vertIndex = 0;
                foreach (DebugShape shape in activeShapes)
                {
                    lineCount += shape.LineCount;
                    int shapeVerts = shape.LineCount * 2;
                    for (int i = 0; i < shapeVerts; i++)
                    {
                        verts[vertIndex++] = shape.Vertices[i];
                    }
                }

                // Start our effect to begin rendering.
                effect.Begin();
                effect.CurrentTechnique.Passes[0].Begin();

                // We draw in a loop because the Reach profile only supports 65,535 primitives. While it's
                // not incredibly likely, if a game tries to render more than 65,535 lines we don't want to
                // crash. We handle this by doing a loop and drawing as many lines as we can at a time, capped
                // at our limit. We then move ahead in our vertex array and draw the next set of lines.
                int vertexOffset = 0;
                while (lineCount > 0)
                {
                    // Figure out how many lines we're going to draw
                    int linesToDraw = Math.Min(lineCount, 65535);

                    // Draw the lines
                    graphics.DrawUserPrimitives(PrimitiveType.LineList, verts, vertexOffset, linesToDraw);

                    // Move our vertex offset ahead based on the lines we drew
                    vertexOffset += linesToDraw * 2;

                    // Remove these lines from our total line count
                    lineCount -= linesToDraw;
                }

                effect.CurrentTechnique.Passes[0].End();

                effect.End();
            }

            // Go through our active shapes and retire any shapes that have expired to the
            // cache list.
            bool resort = false;

            for (int i = activeShapes.Count - 1; i >= 0; i--)
            {
                DebugShape s = activeShapes[i];
                s.Lifetime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (s.Lifetime <= 0)
                {
                    cachedShapes.Add(s);
                    activeShapes.RemoveAt(i);
                    resort = true;
                }
            }

            // If we move any shapes around, we need to resort the cached list
            // to ensure that the smallest shapes are first in the list.
            if (resort)
            {
                cachedShapes.Sort(CachedShapesSort);
            }
        }
コード例 #23
0
ファイル: ChessModel.cs プロジェクト: samibader/3DChess
        public override void Draw(GameTime gameTime)
        {
            owner = (Chessboard)Game.Services.GetService(typeof(Chessboard));
            Matrix m1 = modelProvider.getModelMatrix(logicalPieceRef.name);
            Matrix m2 = owner.CheckerAt(logicalPieceRef.position).World;
            Matrix m3 = owner.CheckerAt(newPos).World;

            if (IsCaptured() == true)
            {
                if (c)
                {
                    m1 = modelProvider.getModelMatrix(logicalPieceRef.name);
                    m2 = Matrix.Identity;
                    if (logicalPieceRef.player is Player2)
                    {
                        m2 = owner.CheckerAt(new Position(0, 0, 0)).World *Matrix.CreateTranslation(-1 - owner.GetCapturedPieces(logicalPieceRef.player) / 8, 0, owner.GetCapturedPieces(logicalPieceRef.player) % 8);
                    }
                    else
                    {
                        m2 = owner.CheckerAt(new Position(0, 0, 0)).World *Matrix.CreateTranslation(8 + owner.GetCapturedPieces(logicalPieceRef.player) / 8, 0, owner.GetCapturedPieces(logicalPieceRef.player) % 8);
                    }

                    worldMatrix           = m1 * m2 * calibrationMatrix;
                    Visible               = true;
                    fireParticles.Visible = false;
                }
                c = false;
            }
            else if (fadeIn)
            {
                worldMatrix = Matrix.Lerp(worldMatrix, m1 * m3 * calibrationMatrix, 0.3f);
            }
            else
            {
                worldMatrix           = m1 * m2 * calibrationMatrix;
                fireParticles.Visible = true;
            }
            modelEffect.Projection = cam.ProjectionMatrix;
            modelEffect.View       = cam.ViewMatrix;
            modelEffect.World      = worldMatrix * cam.WorldMatrix;
            modelEffect.Alpha      = alpha;
            modelEffect.Texture    = texture;


            //Game.GraphicsDevice.RenderState.AlphaBlendEnable = false;
            if (fadeOut)
            {
                if (alpha > 0.2) // begin fade out
                {
                    alpha -= alphaStep;
                }
                else
                {
                    fadeOut = false; // end fade out

                    fadeIn = true;
                    logicalPieceRef.moveTo(newPos);
                }
            }

            //if (IsCapturing)
            //{
            //    if (modelIndex > 51)
            //        modelIndex -= 50;
            //    else
            //    {
            //        logicalPieceRef.isCaptured = true;
            //        isCapturing = false;
            //    }

            //}
            if (fadeIn)
            {
                if (alpha < 0.9f)
                {
                    alpha += alphaStep;
                }
                else
                {
                    fadeIn        = false;
                    owner.Blocked = false;
                    logicalPieceRef.isSelected = false;
                    GameManager.getReference(null).toggleTurn(false);
                }
            }



            foreach (ModelMesh mesh in model.Meshes)
            {
                vertexBuffer = mesh.VertexBuffer;
                indexBuffer  = mesh.IndexBuffer;
            }

            if (modelIndex == -1)
            {
                modelIndex = indexBuffer.SizeInBytes / 6;
            }


            //if (modelIndex > 31)
            //    modelIndex -= 30;

            Game.GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
            Game.GraphicsDevice.Indices = indexBuffer;

            Game.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
                Game.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

            //Game.GraphicsDevice.RenderState.FillMode = FillMode.WireFrame;
            modelEffect.Begin();
            foreach (EffectPass pass in modelEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                //graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, buffer.SizeInBytes, 0, 2730);
                Game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.SizeInBytes, 0, modelIndex);
                //Game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.SizeInBytes, 0, modelIndex);

                pass.End();
            }
            modelEffect.End();



            //foreach (ModelMesh mesh in model.Meshes)
            //{
            //    foreach (ModelMeshPart part in mesh.MeshParts)
            //    {
            //        part.Effect = ModelEffect;
            //    }
            //}

            //Game.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
            // Game.GraphicsDevice.RenderState.DestinationBlend = Blend.DestinationAlpha;
            //foreach (ModelMesh mesh in model.Meshes)
            //{
            //    foreach (Effect eff in mesh.Effects)
            //    {
            //        modelEffect.Projection = cam.ProjectionMatrix;
            //        modelEffect.View = cam.ViewMatrix;
            //        modelEffect.World = worldMatrix * cam.WorldMatrix;
            //        modelEffect.Alpha = alpha;
            //        modelEffect.Texture = texture;
            //    }
            //    mesh.Draw();
            //}
            // Game.GraphicsDevice.RenderState.SourceBlend = Blend.One;
            // Game.GraphicsDevice.RenderState.DestinationBlend = Blend.Zero;
            fireParticles.SetCamera(cam.ViewMatrix, cam.ProjectionMatrix);
            if (logicalPieceRef.isSelected)
            {
                fireParticles.Visible = true;
            }
            else
            {
                fireParticles.Visible = false;
            }
            // draw the shadow

            //Game.GraphicsDevice.Clear(ClearOptions.Stencil, Color.Black, 0, 0);
            //Game.GraphicsDevice.RenderState.StencilEnable = true;
            //// Draw on screen if 0 is the stencil buffer value
            //Game.GraphicsDevice.RenderState.ReferenceStencil = 0;
            //Game.GraphicsDevice.RenderState.StencilFunction =
            //    CompareFunction.Equal;
            //// Increment the stencil buffer if we draw
            //Game.GraphicsDevice.RenderState.StencilPass =
            //    StencilOperation.Increment;
            //// Setup alpha blending to make the shadow semi-transparent
            //Game.GraphicsDevice.RenderState.AlphaBlendEnable = true;
            //Game.GraphicsDevice.RenderState.SourceBlend =
            //    Blend.SourceAlpha;
            //Game.GraphicsDevice.RenderState.DestinationBlend =
            //    Blend.InverseSourceAlpha;

            //foreach (ModelMesh mesh in model.Meshes)
            //{
            //    foreach (Effect eff in mesh.Effects)
            //    {

            //        modelEffect.setProjectionMatrix(cam.ProjectionMatrix);
            //        modelEffect.setViewInverseMatrix(Matrix.Invert(cam.ViewMatrix));
            //        modelEffect.setViewMatrix(cam.ViewMatrix);
            //        modelEffect.setWorldInverseTransposeMatrix(Matrix.Transpose(Matrix.Invert(worldMatrix * cam.WorldMatrix * shadow)));
            //        modelEffect.setWorldMatrix(worldMatrix * cam.WorldMatrix * shadow);
            //        modelEffect.setWorldViewProjectionMatrix(worldMatrix * cam.WorldMatrix * shadow * cam.ViewMatrix * cam.ProjectionMatrix);

            //        modelEffect.setWorldViewMatrix(worldMatrix * cam.WorldMatrix * shadow * cam.ViewMatrix);
            //    }
            //    mesh.Draw();
            //}

            // Game.GraphicsDevice.RenderState.StencilEnable = false;
            // turn alpha blending off
            // Game.GraphicsDevice.RenderState.AlphaBlendEnable = false;


            base.Draw(gameTime);
        }
コード例 #24
0
        /// <summary>
        /// Draws the static body
        /// </summary>
        ///
        public virtual void Draw()
        {
            // Rotation Disabled for Static Shapes

            /*if (Keyboard.GetState().IsKeyDown(Keys.Left))
             * {
             *  angle = 0.01f;
             *  //angle = MathHelper.Clamp(angle, -360, 360);
             *  Rotate(angle);
             * }
             * else if (Keyboard.GetState().IsKeyDown(Keys.Right))
             * {
             *  angle = -0.01f;
             *  //angle = MathHelper.Clamp(angle, -360, 360);
             *  Rotate(angle);
             * }*/


            //show bounding box
            if (Keyboard.GetState().IsKeyDown(Keys.B))
            {
                batch.Begin(PrimitiveType.LineList);
                //top line
                batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.t), Color.Green);
                batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.t), Color.Green);

                //left line
                batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.t), Color.Green);
                batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.b), Color.Green);

                //right line
                batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.t), Color.Green);
                batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.b), Color.Green);

                //bottom line
                batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.b), Color.Green);
                batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.b), Color.Green);
                batch.End();
            }

            graphics.VertexDeclaration = vertDecl;
            graphics.Indices           = indexBuffer;
            graphics.Vertices[0].SetSource(vertBuffer, 0, VertexPositionColor.SizeInBytes);

            // if holding 'W' key, render in wireframe
            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                graphics.RenderState.FillMode = FillMode.WireFrame;
            }
            else
            {
                graphics.RenderState.FillMode = FillMode.Solid;
            }

            effect.Begin();
            effect.World = Matrix.CreateTranslation(new Vector3(GetScreenPosition(), 0));
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numPrimitives);
                pass.End();
            }
            effect.End();
        }
コード例 #25
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            spriteBatch.Draw(backgroundTexture, new Vector2(0, 0), Color.White);

            //spriteBatch.DrawString(spriteFont, "" + lastGameTime.TotalGameTime.Seconds + ":" + (lastGameTime.TotalGameTime - lastGameTime.ElapsedGameTime).Seconds, new Vector2(10, 10), Color.White);
            //spriteBatch.DrawString(spriteFont, "" + player1.selectedCube.Value.X + ":" + player1.selectedCube.Value.Y, new Vector2(10, 30), Color.White);
            //spriteBatch.DrawString(spriteFont, "" + lol, new Vector2(10, 50), Color.White);

            if (currentRound != null)
            {
                currentRound.floors[0].draw(spriteBatch);
                currentRound.floors[1].draw(spriteBatch);
                currentRound.floors[2].draw(spriteBatch);
                currentRound.floors[3].draw(spriteBatch);

                foreach (PhysicsGameObject phy in currentRound.physicsController.physicsObjects)
                {
                    phy.draw(spriteBatch);
                }

                for (int i = 0; i < currentRound.physicsController.damageTotalPlayer1 / 100; i++)
                {
                    spriteBatch.Draw(textureStore.damageTexture, new Vector2(1024 / 2 - 100 - (i) * 10, 700), null, Color.White, 0, new Vector2(), 0.1f, SpriteEffects.None, 1.0f);
                }
                for (int i = 0; i < currentRound.physicsController.damageTotalPlayer2 / 100; i++)
                {
                    spriteBatch.Draw(textureStore.damageTexture, new Vector2(1024 / 2 + 100 + (i) * 10, 700), null, Color.White, 0, new Vector2(), 0.1f, SpriteEffects.None, 1.0f);
                }
            }


            //If the main menu is active, draw the menuObjects
            if (currentApplicationState == GameState.MainMenu)
            {
                if (tutActive)
                {
                    tutCount = (tutCount + 1) % 7;
                    if (tutCount == 0)
                    {
                        tutorial.getTextureSet("Default").currentTextureListIndex = (tutorial.getTextureSet("Default").currentTextureListIndex + 1) % 7;
                    }
                    tutorial.draw(spriteBatch);
                    tutorialOverlay.draw(spriteBatch);
                }
                else
                {
                    menuObjects[0].draw(spriteBatch);
                    menuObjects[1].draw(spriteBatch);
                    menuObjects[2].draw(spriteBatch);
                }
                //menuObjects[3].draw(spriteBatch);
            }
            else if (currentApplicationState == GameState.Pause)
            {
                if (tutActive)
                {
                    tutCount = (tutCount + 1) % 7;
                    if (tutCount == 0)
                    {
                        tutorial.getTextureSet("Default").currentTextureListIndex = (tutorial.getTextureSet("Default").currentTextureListIndex + 1) % 7;
                    }
                    tutorial.draw(spriteBatch);
                    tutorialOverlay.draw(spriteBatch);
                }
                else
                {
                    menuObjects[0].draw(spriteBatch);
                    menuObjects[2].draw(spriteBatch);
                }
            }

            //spriteBatch.Draw(backgroundTexture, new Vector2(0,0), null, Color.White, 0, new Vector2(0,0), 1.0f, SpriteEffects.None, -0.5f);

            /*foreach (Vector2 vertex in cannon.boxGeom.WorldVertices)
             * {
             *  spriteBatch.DrawString(spriteFont, "" + vertex.X + ":" + vertex.Y, vertex, Color.White);
             * }*/

            if (currentGame != null)
            {
                for (int i = 0; i < currentGame.p1.money; i++)
                {
                    spriteBatch.Draw(textureStore.coinTexture, new Vector2(10, 10 + ((currentGame.p1.money - i) * 10)), null, Color.White, 0, new Vector2(), 0.1f, SpriteEffects.None, 1.0f);
                }
                for (int i = 0; i < currentGame.p2.money; i++)
                {
                    spriteBatch.Draw(textureStore.coinTexture, new Vector2(1024 - 10 - (textureStore.coinTexture.Width * 0.1f), 10 + ((currentGame.p2.money - i) * 10)), null, Color.White, 0, new Vector2(), 0.1f, SpriteEffects.None, 1.0f);
                }
            }

            spriteBatch.End();



            basicEffect.Begin();

            if (currentRound != null)
            {
                foreach (PhysicsGameJoint phy in currentRound.physicsController.physicsJoints)
                {
                    phy.draw(basicEffect, GraphicsDevice);
                }
            }

            //cannon.draw(basicEffect, GraphicsDevice);
            //floor.draw(basicEffect, GraphicsDevice);

            basicEffect.End();

            //GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, pointList, 0, points);

            base.Draw(gameTime);
        }
コード例 #26
0
ファイル: ExtraFunctions.cs プロジェクト: RuiVarela/atlas
        public static void DrawBoundingBox(BoundingBox boundingBox, Matrix view, Matrix projection)
        {
            if (_boxVertexBuffer == null) //was never setup
            {
                float alpha = 0.5f;
                if (_boxVertexDeclaration == null)
                {
                    _boxVertexDeclaration = new VertexDeclaration(ResourceMgr.Instance.Game.GraphicsDevice, VertexPositionColor.VertexElements);
                }
                _boxVertexBuffer = new VertexBuffer(ResourceMgr.Instance.Game.GraphicsDevice, VertexPositionColor.SizeInBytes * 24, BufferUsage.WriteOnly);
                if (_boxIndexBuffer == null)
                {
                    _boxIndexBuffer = new IndexBuffer(ResourceMgr.Instance.Game.GraphicsDevice, 2 /*bytes*/ * 6 * 6, BufferUsage.WriteOnly, IndexElementSize.SixteenBits);
                    short[] indices = new short[36];
                    indices[0]  = 0;
                    indices[1]  = 1;
                    indices[2]  = 2;
                    indices[3]  = 1;
                    indices[4]  = 3;
                    indices[5]  = 2;
                    indices[6]  = 4;
                    indices[7]  = 5;
                    indices[8]  = 6;
                    indices[9]  = 6;
                    indices[10] = 5;
                    indices[11] = 7;
                    indices[12] = 8;
                    indices[13] = 9;
                    indices[14] = 10;
                    indices[15] = 8;
                    indices[16] = 11;
                    indices[17] = 9;
                    indices[18] = 12;
                    indices[19] = 13;
                    indices[20] = 14;
                    indices[21] = 12;
                    indices[22] = 14;
                    indices[23] = 15;
                    indices[24] = 16;
                    indices[25] = 17;
                    indices[26] = 18;
                    indices[27] = 19;
                    indices[28] = 17;
                    indices[29] = 16;
                    indices[30] = 20;
                    indices[31] = 21;
                    indices[32] = 22;
                    indices[33] = 23;
                    indices[34] = 20;
                    indices[35] = 22;
                    _boxIndexBuffer.SetData <short>(indices);
                }
                _boxEffect = new BasicEffect(ResourceMgr.Instance.Game.GraphicsDevice, null);
                _boxEffect.VertexColorEnabled = true;
                _boxEffect.Alpha = alpha;
                VertexPositionColor[] vertices = new VertexPositionColor[24];

                Vector3 topLeftFront     = new Vector3(-0.5f, 0.5f, 0.5f);
                Vector3 bottomLeftFront  = new Vector3(-0.5f, -0.5f, 0.5f);
                Vector3 topRightFront    = new Vector3(0.5f, 0.5f, 0.5f);
                Vector3 bottomRightFront = new Vector3(0.5f, -0.5f, 0.5f);
                Vector3 topLeftBack      = new Vector3(-0.5f, 0.5f, -0.5f);
                Vector3 topRightBack     = new Vector3(0.5f, 0.5f, -0.5f);
                Vector3 bottomLeftBack   = new Vector3(-0.5f, -0.5f, -0.5f);
                Vector3 bottomRightBack  = new Vector3(0.5f, -0.5f, -0.5f);

                //front
                vertices[0] = new VertexPositionColor(topLeftFront, Color.Red);
                vertices[1] = new VertexPositionColor(bottomLeftFront, Color.Red);
                vertices[2] = new VertexPositionColor(topRightFront, Color.Red);
                vertices[3] = new VertexPositionColor(bottomRightFront, Color.Red);

                //back
                vertices[4] = new VertexPositionColor(topLeftBack, Color.Orange);
                vertices[5] = new VertexPositionColor(topRightBack, Color.Orange);
                vertices[6] = new VertexPositionColor(bottomLeftBack, Color.Orange);
                vertices[7] = new VertexPositionColor(bottomRightBack, Color.Orange);

                //top
                vertices[8]  = new VertexPositionColor(topLeftFront, Color.Yellow);
                vertices[9]  = new VertexPositionColor(topRightBack, Color.Yellow);
                vertices[10] = new VertexPositionColor(topLeftBack, Color.Yellow);
                vertices[11] = new VertexPositionColor(topRightFront, Color.Yellow);

                //bottom
                vertices[12] = new VertexPositionColor(bottomLeftFront, Color.Purple);
                vertices[13] = new VertexPositionColor(bottomLeftBack, Color.Purple);
                vertices[14] = new VertexPositionColor(bottomRightBack, Color.Purple);
                vertices[15] = new VertexPositionColor(bottomRightFront, Color.Purple);

                //left
                vertices[16] = new VertexPositionColor(topLeftFront, Color.Blue);
                vertices[17] = new VertexPositionColor(bottomLeftBack, Color.Blue);
                vertices[18] = new VertexPositionColor(bottomLeftFront, Color.Blue);
                vertices[19] = new VertexPositionColor(topLeftBack, Color.Blue);

                //right
                vertices[20] = new VertexPositionColor(topRightFront, Color.Green);
                vertices[21] = new VertexPositionColor(bottomRightFront, Color.Green);
                vertices[22] = new VertexPositionColor(bottomRightBack, Color.Green);
                vertices[23] = new VertexPositionColor(topRightBack, Color.Green);

                _boxVertexBuffer.SetData <VertexPositionColor>(vertices);
            }

            Matrix scale = Matrix.CreateScale(boundingBox.Max.X - boundingBox.Min.X,
                                              boundingBox.Max.Y - boundingBox.Min.Y,
                                              boundingBox.Max.Z - boundingBox.Min.Z);
            Matrix translation = Matrix.CreateTranslation(BoxCenter(boundingBox));
            Matrix adjustment  = scale * translation;

            ResourceMgr.Instance.Game.GraphicsDevice.RenderState.CullMode = CullMode.None;
            ResourceMgr.Instance.Game.GraphicsDevice.Vertices[0].SetSource(_boxVertexBuffer, 0, VertexPositionColor.SizeInBytes);
            ResourceMgr.Instance.Game.GraphicsDevice.Indices = _boxIndexBuffer;
            VertexDeclaration old = ResourceMgr.Instance.Game.GraphicsDevice.VertexDeclaration;

            ResourceMgr.Instance.Game.GraphicsDevice.VertexDeclaration = _boxVertexDeclaration;

            ResourceMgr.Instance.Game.GraphicsDevice.RenderState.AlphaBlendEnable = true;
            ResourceMgr.Instance.Game.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
            ResourceMgr.Instance.Game.GraphicsDevice.RenderState.SourceBlend      = Blend.SourceAlpha;

            _boxEffect.Begin();
            _boxEffect.View       = view;
            _boxEffect.Projection = projection;
            _boxEffect.World      = adjustment;
            foreach (EffectPass pass in _boxEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                ResourceMgr.Instance.Game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 24, 0, 12);
                pass.End();
            }
            _boxEffect.End();

            ResourceMgr.Instance.Game.GraphicsDevice.VertexDeclaration    = old;
            ResourceMgr.Instance.Game.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;

            ResourceMgr.Instance.Game.GraphicsDevice.RenderState.AlphaBlendEnable = false;
        }
コード例 #27
0
        /// <summary>
        /// the mesh is drawn by using the vertexData.
        /// When the userPrimitive member is set to true,
        /// it is drawn without using the vertex buffer and the index buffer.
        /// </summary>
        /// <param name="renderTracer"></param>
        protected override void OnDraw(RenderTracer renderTracer)
        {
            GraphicsDevice device      = renderTracer.Device;
            RenderState    renderState = device.RenderState;

            basicEffect.Texture         = this.textureResource;
            basicEffect.World           = this.TransformedMatrix;
            basicEffect.View            = renderTracer.View;
            basicEffect.Projection      = renderTracer.Projection;
            basicEffect.LightingEnabled = false;

            device.VertexDeclaration          = vertexDeclaration;
            device.SamplerStates[0].AddressU  = TextureAddressMode.Wrap;
            device.SamplerStates[0].AddressV  = TextureAddressMode.Wrap;
            device.SamplerStates[0].MinFilter = TextureFilter.Linear;
            device.SamplerStates[0].MagFilter = TextureFilter.Linear;
            device.SamplerStates[0].MipFilter = TextureFilter.Point;

            renderState.AlphaTestEnable  = alphaTestEnable;
            renderState.AlphaBlendEnable = alphaBlendEnable;
            renderState.AlphaFunction    = alphaFunction;

            renderState.SourceBlend      = sourceBlend;
            renderState.DestinationBlend = destinationBlend;
            renderState.BlendFunction    = blendFunction;

            renderState.ReferenceAlpha         = referenceAlpha;
            renderState.DepthBufferEnable      = depthBufferEnable;
            renderState.DepthBufferWriteEnable = depthBufferWriteEnable;
            renderState.DepthBufferFunction    = depthBufferFunction;
            renderState.CullMode = cullMode;

            basicEffect.Begin();

            for (int i = 0; i < basicEffect.CurrentTechnique.Passes.Count; i++)
            {
                EffectPass pass = basicEffect.CurrentTechnique.Passes[i];

                pass.Begin();

                if (userPrimitive)
                {
                    //  Use index?
                    if (indexData != null)
                    {
                        // only use vertex and index data
                        device.DrawUserIndexedPrimitives <VertexPositionColorTexture>(
                            PrimitiveType.TriangleList,
                            vertexData,
                            0,
                            vertexData.Length,
                            indexData,
                            0,
                            this.primitiveCount);
                    }
                    else
                    {
                        device.DrawUserPrimitives <VertexPositionColorTexture>(
                            PrimitiveType.TriangleList,
                            vertexData,
                            0,
                            this.primitiveCount);
                    }
                }
                else
                {
                    //  Use vertex buffer
                    device.Vertices[0].SetSource(vertexBuffer,
                                                 0,
                                                 VertexPositionColorTexture.SizeInBytes);

                    //  Use index?
                    if (indexBuffer != null)
                    {
                        //  Use index buffer
                        device.Indices = indexBuffer;

                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                     0,
                                                     0,
                                                     updateVertexCount,
                                                     0,
                                                     this.primitiveCount);
                    }
                    else
                    {
                        device.DrawPrimitives(PrimitiveType.TriangleList,
                                              0,
                                              this.primitiveCount);
                    }
                }

                pass.End();
            }

            basicEffect.End();

            device.RenderState.DepthBufferWriteEnable = true;
        }
コード例 #28
0
ファイル: SpaceBalls.cs プロジェクト: Kimau/ludumdare
        /// <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)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Draw Balls in Space
            // Get Aspect Ratio
            float aspectRatio = m_GraphicsDev.PreferredBackBufferWidth /
                                m_GraphicsDev.PreferredBackBufferHeight;

            // Get Matrix
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                    aspectRatio,
                                                                    1,
                                                                    10000);

            m_baseFx.View       = m_cam.ViewMatrix;
            m_baseFx.Projection = projection;

            foreach (StickyBall ball in m_BallList)
            {
                m_baseFx.World = ball.Transform;
                Vector3 dir = ball.Position;
                dir.Normalize();
                m_baseFx.DirectionalLight0.Direction = dir;

                foreach (ModelMesh mesh in m_BallModel.Meshes)
                {
                    foreach (ModelMeshPart mp in mesh.MeshParts)
                    {
                        m_baseFx.GraphicsDevice.VertexDeclaration = mp.VertexDeclaration;

                        m_baseFx.Begin();
                        foreach (EffectPass pass in m_baseFx.CurrentTechnique.Passes)
                        {
                            pass.Begin();

                            m_baseFx.GraphicsDevice.Indices = mesh.IndexBuffer;

                            m_baseFx.GraphicsDevice.Vertices[0].SetSource(
                                mesh.VertexBuffer,
                                mp.StreamOffset,
                                mp.VertexStride);

                            m_baseFx.GraphicsDevice.DrawIndexedPrimitives(
                                PrimitiveType.TriangleList,
                                mp.BaseVertex, 0,
                                mp.NumVertices,
                                mp.StartIndex,
                                mp.PrimitiveCount);

                            pass.End();
                        }
                        m_baseFx.End();
                    }
                }
            }

            for (int xP = 0; xP < 40; xP++)
            {
                for (int yP = 0; yP < 1; yP++)
                {
                    for (int zP = 0; zP < 40; zP++)
                    {
                        int alterYPoint = (yP + yScan) % 40;

                        Vector3 gravPoint = new Vector3(
                            xP * 5.0f - 100.0f,
                            alterYPoint * 5.0f - 100.0f,
                            zP * 5.0f - 100.0f);

                        m_DebugRenderComp.WorldLine(
                            new Color(1, 0, 0, (yP + 0.5f) / 5.5f),
                            gravPoint,
                            gravPoint + (m_GravityPoints[xP, alterYPoint, zP] * 5.0f));
                    }
                }
            }

            base.Draw(gameTime);
        }
コード例 #29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pDevice"></param>
        private void mWinForm_OnFrameRender(GraphicsDevice pDevice)
        {
            /*m_SBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.SaveState);
             *
             * m_SBatch.Draw(m_BackgroundTex, new Microsoft.Xna.Framework.Rectangle(0, 0, m_BackgroundTex.Width,
             *  m_BackgroundTex.Height), Microsoft.Xna.Framework.Graphics.Color.White);
             *
             * m_SBatch.End();*/

            Device.RenderState.DepthBufferEnable      = true;
            Device.RenderState.DepthBufferWriteEnable = true;
            Device.RenderState.AlphaBlendEnable       = false;
            Device.RenderState.PointSize = 10.0f;

            // Configure effects
            m_HeadEffect.World      = this.mWorldMat;
            m_HeadEffect.View       = mViewMat;
            m_HeadEffect.Projection = mProjectionMat;

            m_BodyEffect.World      = this.mWorldMat;
            m_BodyEffect.View       = mViewMat;
            m_BodyEffect.Projection = mProjectionMat;

            if (m_HeadTex != null)
            {
                m_HeadEffect.Texture        = m_HeadTex;
                m_HeadEffect.TextureEnabled = true;

                m_HeadEffect.EnableDefaultLighting();
            }

            if (m_BodyTex != null)
            {
                m_BodyEffect.Texture        = m_BodyTex;
                m_BodyEffect.TextureEnabled = true;

                m_BodyEffect.EnableDefaultLighting();
            }

            m_HeadEffect.CommitChanges();
            m_BodyEffect.CommitChanges();

            if (m_LoadBodyComplete)
            {
                /*m_CurrentMesh.TransformVertices2(m_Skeleton.Bones[0], ref mWorldMat);
                 * m_CurrentMesh.BlendVertices2();
                 * m_CurrentMesh.ProcessMesh();*/

                if (!m_RenderSkeleton)
                {
                    foreach (Face Fce in m_CurrentBodyMesh.Faces)
                    {
                        // Draw
                        m_BodyEffect.Begin();
                        m_BodyEffect.Techniques[0].Passes[0].Begin();

                        VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                        Vertex[0] = m_CurrentBodyMesh.VertexTexNormalPositions[Fce.AVertexIndex];
                        Vertex[1] = m_CurrentBodyMesh.VertexTexNormalPositions[Fce.BVertexIndex];
                        Vertex[2] = m_CurrentBodyMesh.VertexTexNormalPositions[Fce.CVertexIndex];

                        Vertex[0].TextureCoordinate = m_CurrentBodyMesh.VertexTexNormalPositions[Fce.AVertexIndex].TextureCoordinate;
                        Vertex[1].TextureCoordinate = m_CurrentBodyMesh.VertexTexNormalPositions[Fce.BVertexIndex].TextureCoordinate;
                        Vertex[2].TextureCoordinate = m_CurrentBodyMesh.VertexTexNormalPositions[Fce.CVertexIndex].TextureCoordinate;

                        pDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                                                                                 Vertex, 0, 1);

                        m_BodyEffect.Techniques[0].Passes[0].End();
                        m_BodyEffect.End();
                    }
                }
                else
                {
                    if (m_SkelPoints != null)
                    {
                        m_BodyEffect.Begin();
                        m_BodyEffect.Techniques[0].Passes[0].Begin();
                        pDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.PointList,
                                                                                 m_SkelPoints, 0, m_Skeleton.Bones.Length);
                        m_BodyEffect.Techniques[0].Passes[0].End();
                        m_BodyEffect.End();
                    }
                }
            }

            if (m_LoadHeadComplete)
            {
                foreach (Face Fce in m_CurrentHeadMesh.Faces)
                {
                    // Draw
                    m_HeadEffect.Begin();
                    m_HeadEffect.Techniques[0].Passes[0].Begin();

                    VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                    Vertex[0] = m_CurrentHeadMesh.VertexTexNormalPositions[Fce.AVertexIndex];
                    Vertex[1] = m_CurrentHeadMesh.VertexTexNormalPositions[Fce.BVertexIndex];
                    Vertex[2] = m_CurrentHeadMesh.VertexTexNormalPositions[Fce.CVertexIndex];

                    Vertex[0].TextureCoordinate = m_CurrentHeadMesh.VertexTexNormalPositions[Fce.AVertexIndex].TextureCoordinate;
                    Vertex[1].TextureCoordinate = m_CurrentHeadMesh.VertexTexNormalPositions[Fce.BVertexIndex].TextureCoordinate;
                    Vertex[2].TextureCoordinate = m_CurrentHeadMesh.VertexTexNormalPositions[Fce.CVertexIndex].TextureCoordinate;

                    pDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                                                                             Vertex, 0, 1);

                    m_HeadEffect.Techniques[0].Passes[0].End();
                    m_HeadEffect.End();
                }
            }
        }
コード例 #30
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            GraphicsDevice.RenderState.DepthBufferEnable = false;

            GraphicsDevice.VertexDeclaration = backdropVertexDeclaration;

            bfx.Begin();
            foreach (EffectPass pass in bfx.CurrentTechnique.Passes)
            {
                pass.Begin();

                GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, backdropVertices, 0, 2);

                pass.End();
            }
            bfx.End();

            GraphicsDevice.RenderState.DepthBufferEnable = true;

            grid.Draw(gameTime);

            DrawGridPieces(gameTime);

            DrawUnitAnimations(gameTime);

            sprite.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
            if (!gameEnded && enemyPieces.Count > 0 && playerPieces.Count > 0)
            {
                DrawTurnQueue(gameTime);
            }

            DrawActions(gameTime);

            DrawHoverInfoBubble(gameTime);

            if (gameEnded)
            {
                string textResult   = gameWon ? String.Format("Level {0} completed!", level) : String.Format("level {0} failed!", level);
                string textContinue = gameWon ? "Press 'RETURN' to continue." : "Press 'ENTER' to try again.";

                Vector2 textResultSize   = uiUnitFont.MeasureString(textResult);
                Vector2 textContinueSize = uiUnitFont.MeasureString(textContinue);

                sprite.DrawString(uiUnitFont, textResult, new Vector2((GraphicsDevice.Viewport.Width / 2) - (textResultSize.X / 2), (GraphicsDevice.Viewport.Height / 5) - (textResultSize.Y / 2)), Color.Black);
                sprite.DrawString(uiUnitFont, textContinue, new Vector2((GraphicsDevice.Viewport.Width / 2) - (textContinueSize.X / 2), (GraphicsDevice.Viewport.Height / 5) - (textContinueSize.Y / 2) + 18), Color.Black);
            }

            if (!gameStarted || levelIntroIsFading)
            {
                Color levelIntroColor       = Color.White;
                Color levelIntroColorShadow = Color.Gray;

                levelIntroColor.A       = (byte)(255.0f * levelIntroAlpha);
                levelIntroColorShadow.A = (byte)(255.0f * levelIntroAlpha);

                string  text         = String.Format("Level {0}", level);
                Vector2 textSize     = levelFont.MeasureString(text);
                Vector2 textPosition = new Vector2((GraphicsDevice.Viewport.Width / 2) - (textSize.X / 2), (GraphicsDevice.Viewport.Height / 2) - (textSize.Y / 2));

                sprite.DrawString(levelFont, text, textPosition + Vector2.One, levelIntroColorShadow);
                sprite.DrawString(levelFont, text, textPosition, levelIntroColor);
            }

            sprite.End();

            base.Draw(gameTime);
        }