-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLine.cs
40 lines (37 loc) · 1.39 KB
/
Line.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace TheraWii
{
// A straight, single-segment line.
class Line
{
GraphicsDevice graphicsDevice;
VertexPositionColor[] pointList;
VertexBuffer vertexBuffer;
public Line(GraphicsDevice gd, Vector3 start, Vector3 end, Color color)
{
graphicsDevice = gd;
pointList = new VertexPositionColor[2];
pointList[0] = new VertexPositionColor(start, color);
pointList[1] = new VertexPositionColor(end, color);
// Initialize the vertex buffer, allocating memory for each vertex.
vertexBuffer = new VertexBuffer(graphicsDevice,
VertexPositionColor.SizeInBytes * (pointList.Length),
BufferUsage.None);
// Set the vertex buffer data to the array of vertices.
vertexBuffer.SetData<VertexPositionColor>(pointList);
}
public void Draw()
{
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.LineList,
pointList,
0, // vertex buffer offset to add to each element of the index buffer
1 // number of vertices in pointList
);
}
}
}