public static void Draw(GameTime gameTime, Matrix4x4 view, Matrix4x4 projection) { // Update our effect with the matrices. _effect.View = view.ToXNA(); _effect.Projection = projection.ToXNA(); // 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.CurrentTechnique.Passes[0].Apply(); // 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; } } // 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); }
public static void SetValue(this EffectParameter collection, Matrix4x4 value) { Contract.Requires(collection != null); collection.SetValue(value.ToXNA()); }
public static void SetValue(this EffectParameter collection, Matrix4x4 value) { collection.SetValue(value.ToXNA()); }