nee*_*eKo 11
您可以使用VertexPositionColor数组存储单个图形值,然后GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>与定义的线列表(索引)一起使用以使用正交投影绘制它们.
由于文件大小,.gif的大小调整为50%.
我正在以60fps绘制这些样本(4个图表,每个值为300个值点/像素).

如果需要填充线下方的图形,则可以绘制三角形条(在图形底部有点).

以下是上面呈现的第一张图的相关代码:
Matrix worldMatrix;
Matrix viewMatrix;
Matrix projectionMatrix;
BasicEffect basicEffect;
VertexPositionColor[] pointList;
short[] lineListIndices;
protected override void Initialize()
{
int n = 300;
//GeneratePoints generates a random graph, implementation irrelevant
pointList = new VertexPositionColor[n];
for (int i = 0; i < n; i++)
pointList[i] = new VertexPositionColor() { Position = new Vector3(i, (float)(Math.Sin((i / 15.0)) * height / 2.0 + height / 2.0 + minY), 0), Color = Color.Blue };
//links the points into a list
lineListIndices = new short[(n * 2) - 2];
for (int i = 0; i < n - 1; i++)
{
lineListIndices[i * 2] = (short)(i);
lineListIndices[(i * 2) + 1] = (short)(i + 1);
}
worldMatrix = Matrix.Identity;
viewMatrix = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up);
projectionMatrix = Matrix.CreateOrthographicOffCenter(0, (float)GraphicsDevice.Viewport.Width, (float)GraphicsDevice.Viewport.Height, 0, 1.0f, 1000.0f);
basicEffect = new BasicEffect(graphics.GraphicsDevice);
basicEffect.World = worldMatrix;
basicEffect.View = viewMatrix;
basicEffect.Projection = projectionMatrix;
basicEffect.VertexColorEnabled = true; //important for color
base.Initialize();
}
Run Code Online (Sandbox Code Playgroud)
绘制它:
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineList,
pointList,
0,
pointList.Length,
lineListIndices,
0,
pointList.Length - 1
);
}
Run Code Online (Sandbox Code Playgroud)
对于三角形条形图,修改代码以显示三角形条带,并且对于图形曲线中的每个点,将一个放在图形的底部.
| 归档时间: |
|
| 查看次数: |
1372 次 |
| 最近记录: |