Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw an arrow in opengl ES

1) I know the start point of the arrow and I know the endpoint.

I have no idea how to draw the head of the arrow.. I'm assuming that the other two points of the head are 45 degree angles away from the end point...

Anyone know of the formulas needed to do this?

like image 448
Mel Avatar asked Oct 31 '25 00:10

Mel


1 Answers

Wade gives a good answer for the OpenGL portion of this question; I'll try to answer the vector math portion. Here's some pseudocode off the top of my head:

Triangle GenerateArrowHead(vec2 p1, vec2 p2)
{
    // Compute the vector along the arrow direction
    vec2 v = Normalize(p2 - p1)

    // Compute two perpendicular vectors to v
    vec2 vPerp1 = vec2(-v.y, v.x)
    vec2 vPerp2 = vec2(v.y, -v.x)

    // Compute two half-way vectors
    vec2 v1 = Normalize(v + vPerp1)
    vec2 v2 = Normalize(v + vPerp2)

    Triangle tri;
    tri.a = p2;
    tri.b = p2 + ArrowHeadSize * v1;
    tri.c = p2 + ArrowHeadSize * v2;
    return tri;
}
like image 63
prideout Avatar answered Nov 01 '25 13:11

prideout



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!