Monogame 程序不断随机丢弃大量帧

我遇到的问题是程序以 60 fps 流畅运行,但随后 fps 随机下降到接近 0。帧丢失的频率似乎与矩形的数量有关。


这是每帧调用的绘制代码(块是矩形数组)


/// <summary>

/// Draw logic. Activates every frame.

/// </summary>

/// <param name="gameTime">How long the program has been running for</param>

protected override void Draw(GameTime gameTime)

{

    GraphicsDevice.Clear(Color.Chocolate);


    foreach (var a in blocks)

        a.Draw();


     fps++;


     if (gameTime.TotalGameTime.Milliseconds % 1000 == 0 && enableFpsCounter)

     {

         Console.WriteLine(fps);


         fps = 0;

     }


     base.Draw(gameTime);

}

只有在有大量矩形(~25 个矩形)时才会出现此问题


这是展示此问题的 gif: https://gyazo.com/ec41cacd6c89a41c330e151108590050


感谢您的阅读,我很感激能得到的任何帮助。


12345678_0001
浏览 91回答 1
1回答

繁星coding

我设法通过使 RasterizerState 在构造函数而不是 Draw 方法中启动来解决这个问题:using System;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Graphics;namespace BlockMonglerFixed1{&nbsp; &nbsp; public class Rectangle&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Width of the rectangle&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public int Width { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Height of the rectangle&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public int Height { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Length of the rectangle&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public int Length { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Position of the rectangle&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public Vector3 Position { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Rotation vector3 of the rectangle. X = pitch. Y = yaw. Z = roll&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public Vector3 Rotation { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// GraphicsDevice used to draw the rectangle&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public GraphicsDevice GraphicsDevice { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// BasicEffect used to to draw the rectangle&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public BasicEffect Effect { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Color of the rectangle. Not used if a texture is being used&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public Color Color { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Texture of the rectangle. Not used if a color is being used.&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public Texture3D Texture { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Determines if the rectangle should move based on its rotation&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public bool MoveBasedOnRotation { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; int _vertexLength;&nbsp; &nbsp; &nbsp; &nbsp; VertexBuffer _buffer;&nbsp; &nbsp; &nbsp; &nbsp; RasterizerState _rasterizerState;&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Cube constructor. Generates a new rectangle&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="width">Width of rectangle</param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="height">Height of rectangle</param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="length">Length of rectangle</param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="position">Position of the rectangle></param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="rotation">Rotation of the rectangle. This value rotates the rectangle</param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="graphicsDevice">GraphicsDevice used to draw the rectangle</param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="effect">Effect of rectangle</param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="color">Color of rectangle</param>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="moveBasedOnRotation">Determines if the rectangle should move based on its rotation</param>&nbsp; &nbsp; &nbsp; &nbsp; public Rectangle(int width, int height, int length, Vector3 position,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 rotation, GraphicsDevice graphicsDevice, BasicEffect effect, Color color, bool moveBasedOnRotation)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Dimensions of the rectangle&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width = width;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Height = height;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Length = length * 2;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Position setup&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Position = position;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Rotation setup&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rotation = rotation;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MoveBasedOnRotation = moveBasedOnRotation;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Effect setup&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Effect = effect;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Color setup&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Color = color;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Graphics device setup.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GraphicsDevice = graphicsDevice;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Cube setup&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VertexPositionColor[] vertexPositionColors =&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Face 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Face 2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Side 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Side 2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Bottom&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, -Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Top&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(-Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, -Length), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new VertexPositionColor(new Vector3(Width, Height, 0), Color),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Length setup&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _vertexLength = vertexPositionColors.Length;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Buffer setup&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _buffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), _vertexLength,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BufferUsage.WriteOnly);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Set data of the buffer to the vertexList&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _buffer.SetData(vertexPositionColors);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _rasterizerState = new RasterizerState {CullMode = CullMode.None};&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GraphicsDevice.RasterizerState = _rasterizerState;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public Rectangle(int width, int height, int length, Matrix worldMatrix, Matrix projectionMatrix,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Matrix viewMatrix,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GraphicsDevice graphicsDevice, BasicEffect effect, Texture3D texture)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new NotImplementedException();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Sees if the rectangle collides with another object&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; /// <param name="otherRectangle">Rectangle to detect collision with</param>&nbsp; &nbsp; &nbsp; &nbsp; public bool IsColliding(Rectangle otherRectangle)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the minimum values of our position&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float minX = Position.X - Width;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float minY = Position.Y - Height;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float minZ = Position.Z - Length / 2f;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the maximum values of our position&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float maxX = Position.X + Width;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float maxY = Position.Y + Height;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float maxZ = Position.Z + Length / 2f;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the minimum values of the other rectangle's position&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float otherMinX = otherRectangle.Position.X - otherRectangle.Width;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float otherMinY = otherRectangle.Position.Y - otherRectangle.Height;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float otherMinZ = otherRectangle.Position.Z - otherRectangle.Length / 2f;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the maximum values of the other rectangle's positions&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float otherMaxX = otherRectangle.Position.X + otherRectangle.Width;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float otherMaxY = otherRectangle.Position.Y + otherRectangle.Height;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float otherMaxZ = otherRectangle.Position.Z + otherRectangle.Length / 2f;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //We can calculate if one rectangle is in another by seeing if one of our sides is inside another rectangle&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return minX <= otherMaxX && maxX >= otherMinX &&&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minY <= otherMaxY && maxY >= otherMinY &&&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minZ <= otherMaxZ && maxZ >= otherMinZ;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; /// <summary>&nbsp; &nbsp; &nbsp; &nbsp; /// Draws the triangle to the screen&nbsp; &nbsp; &nbsp; &nbsp; /// </summary>&nbsp; &nbsp; &nbsp; &nbsp; public void Draw()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Hold the current position&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 tempPosition = Position;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Create a new matrix with the position and rotation&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Matrix effectWorldMatrix = Matrix.CreateWorld(Vector3.Zero, Vector3.Forward, Vector3.Up) *&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Matrix.CreateTranslation(-new Vector3(0, 0, -Length / 2f)) *&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Matrix.CreateRotationX(Rotation.X) *&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Matrix.CreateRotationY(Rotation.Y) *&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Matrix.CreateRotationZ(Rotation.Z) *&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Matrix.CreateTranslation(Position);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //If MoveBasedOnRotation is true, set the translation of our new matrix to the previous translation&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //if (!MoveBasedOnRotation) effectWorldMatrix.Translation = tempPosition;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Set the effect to our respective matrices;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Effect.World = effectWorldMatrix;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Effect.View = Camera.ViewMatrix;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Effect.Projection = Camera.ProjectionMatrix;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Apply our vertex buffer to the graphics device&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GraphicsDevice.SetVertexBuffer(_buffer);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (EffectPass pass in Effect.CurrentTechnique.Passes)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Apply the pass&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass.Apply();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Use the graphics device to draw the triangle&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, _vertexLength);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP