Jypeli 10
The simple game programming library
LineBatch.cs
Siirry tämän tiedoston dokumentaatioon.
1using System.Diagnostics;
2using Microsoft.Xna.Framework;
3using Microsoft.Xna.Framework.Graphics;
4
5namespace Jypeli
6{
7 internal class LineBatch
8 {
9 VertexPositionColor[] vertexBuffer = new VertexPositionColor[512];
10 Effect effect;
13 bool beginHasBeenCalled = false;
14 public bool LightingEnabled = true;
15
16
17 public void Begin( ref Matrix matrix )
18 {
19 Debug.Assert( !beginHasBeenCalled );
20 beginHasBeenCalled = true;
21
22 this.matrix = matrix;
23 iVertexBuffer = 0;
24 }
25
26 public void End()
27 {
28 Debug.Assert( beginHasBeenCalled );
29 Flush();
30 beginHasBeenCalled = false;
31 }
32
33 private void Flush()
34 {
35 if ( iVertexBuffer > 0 )
36 {
38 for ( int i = 0; i < effect.CurrentTechnique.Passes.Count; i++ )
39 effect.CurrentTechnique.Passes[i].Apply();
40
41 Game.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
42 PrimitiveType.LineList, vertexBuffer, 0, iVertexBuffer / 2);
43 }
44
45 iVertexBuffer = 0;
46 }
47
48 public void Draw(Vector startPoint, Vector endPoint, Color color)
49 {
50 if ((iVertexBuffer + 2) > vertexBuffer.Length)
51 {
52 Flush();
53 }
54
55 vertexBuffer[iVertexBuffer++] = new VertexPositionColor(
56 new Vector3((float)startPoint.X, (float)startPoint.Y, 0f),
57 color.AsXnaColor());
58 vertexBuffer[iVertexBuffer++] = new VertexPositionColor(
59 new Vector3((float)endPoint.X, (float)endPoint.Y, 0f),
60 color.AsXnaColor());
61 }
62 }
63}
static new GraphicsDevice GraphicsDevice
XNA:n grafiikkakortti.
Definition: Graphics.cs:49
Contains graphics resources.
Definition: Graphics.cs:36
static Effect GetColorEffect(ref Matrix worldMatrix, bool lightingEnabled)
Definition: Graphics.cs:167
void Draw(Vector startPoint, Vector endPoint, Color color)
Definition: LineBatch.cs:48
void Begin(ref Matrix matrix)
Definition: LineBatch.cs:17
VertexPositionColor[] vertexBuffer
Definition: LineBatch.cs:9
bool beginHasBeenCalled
Definition: LineBatch.cs:13
bool LightingEnabled
Definition: LineBatch.cs:14
Microsoft.Xna.Framework.Matrix Matrix
Definition: Mouse.cs:36
Väri.
Definition: Color.cs:13
XnaColor AsXnaColor()
Definition: Color.cs:46
2D-vektori.
Definition: Vector.cs:67
double Y
Vektorin Y-komponentti
Definition: Vector.cs:339
double X
Vektorin X-komponentti.
Definition: Vector.cs:334