Draw an arrow in opengl ES
1) I know the starting point of the arrow and I know the ending point.
I have no idea how to draw an arrow head. I am assuming the other two points of the head are at an angle of 45 degrees from the end point ...
Does anyone know the formulas required for this?
+2
Mel
source
to share
2 answers
Wade gives a good answer for the OpenGL part of this question; I'll try to answer the vector math part. Here's some pseudo code from above:
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;
}
+6
prideout
source
to share
Why doesn't it work?
1) Draw a triangle for the head (this means drawing with GL_TRIANGLES, not drawing three line segments that form a triangle)
2) Draw a line segment extending from the midpoint of the base of the triangle.
+1
wadesworld
source
to share