1

最近の質問に対するこの回答では、グラフを描画するコードがいくつかありますが、ポイントのリストをパラメーターとして受け入れるものに編集することはできません。

Drawing メソッドがこれらのパラメーターを受け入れるようにしたいと思います。

  • のリストVector2Pointまたは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
    );
}
4

1 に答える 1

6

Graph要求を実行するクラスは、ここにあります
約 200 行のコードは、ここに貼り付けるには多すぎるように思えました。

ここに画像の説明を入力

Graphfloat のリスト (オプションで色付き) をDraw(..)メソッドに渡すことで描画されます。

Graphプロパティは次のとおりです。

  • Vector2 Position-グラフの左下
  • Point Size-グラフの幅 ( .X) と高さ ( )。.Y水平方向には、幅にぴったり合うように値が分散されます。垂直方向では、すべての値が でスケーリングされSize.Y / MaxValueます。
  • float MaxValue- グラフの上部にある値。グラフ外の値 ( より大きい) はすべてMaxValue、この値に設定されます。
  • GraphType Type- 可能な値GraphType.LineGraphType.Fillを使用して、グラフを線のみで描画するか、下部を塗りつぶすかを決定します。

グラフは折れ線リスト/三角形ストリップで描画されます。

于 2012-12-21T17:32:27.960 に答える