最近の質問に対するこの回答では、グラフを描画するコードがいくつかありますが、ポイントのリストをパラメーターとして受け入れるものに編集することはできません。
Drawing メソッドがこれらのパラメーターを受け入れるようにしたいと思います。
- のリスト
Vector2
、Point
またはVertexPositionColor
、どちらでも作業できます。 - グラフ全体のオフセット
これらのオプションの要件は高く評価されます。
- の色をオーバーライド
VertexPositionColor
してすべてのポイントに適用できる色。 Vector2
グラフのサイズ。乗数またはPoint
目標サイズとして縮小または拡大できます。これを のオフセットと組み合わせることもできRectangle
ます。
可能であれば、すべてをクラスに入れたいので、グラフを互いに別々に使用したり、それぞれ独自のEffect.world
マトリックスなどを使用したりできます.
これがそのコードです(Niko Draškovićによる):
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();
}
そして描画方法:
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineList,
pointList,
0,
pointList.Length,
lineListIndices,
0,
pointList.Length - 1
);
}