Example #1
0
    void DrawArrow(V2 from, V2 to, float w, Color color)
    {
        V2    dp    = to - from;
        float dpLen = dp.Len();
        V2    dir   = dp / dpLen;
        V2    perp  = new V2 {
            x = dir.y, y = -dir.x
        };
        V2 cornerHorDp = perp * w;

        const float HEAD_LEN_RATIO = 0.3f;

        V2 corner00      = from + cornerHorDp;
        V2 corner01      = from - cornerHorDp;
        V2 corner1Center = from + (dp * (1f - HEAD_LEN_RATIO));
        V2 corner10      = corner1Center + cornerHorDp;
        V2 corner11      = corner1Center - cornerHorDp;

        const float HEAD_WITH_RATIO = 2f;

        V2 headTop     = to;
        V2 headBottom0 = corner1Center + cornerHorDp * HEAD_WITH_RATIO;
        V2 headBottom1 = corner1Center - cornerHorDp * HEAD_WITH_RATIO;

        renderVerts.Add(Convert(corner00));
        renderVerts.Add(Convert(corner01));
        renderVerts.Add(Convert(corner10));
        renderVerts.Add(Convert(corner11));
        renderVerts.Add(Convert(headTop));
        renderVerts.Add(Convert(headBottom0));
        renderVerts.Add(Convert(headBottom1));

        int atVert = renderVerts.Count - 1;

        renderTris.Add(atVert--);
        renderTris.Add(atVert--);
        renderTris.Add(atVert--);

        renderTris.Add(atVert);
        renderTris.Add(atVert - 1);
        renderTris.Add(atVert - 2);

        renderTris.Add(atVert - 1);
        renderTris.Add(atVert - 2);
        renderTris.Add(atVert - 3);

        for (int i = 0; i < 7; i++)
        {
            renderColors.Add(color);
        }
    }