{"id":879,"date":"2009-10-08T13:50:00","date_gmt":"2009-10-08T12:50:00","guid":{"rendered":"http:\/\/it4bus.vn\/itersdesktop\/2009\/10\/08\/drawing-arrow-in-opengl\/"},"modified":"2009-10-08T13:50:00","modified_gmt":"2009-10-08T12:50:00","slug":"drawing-arrow-in-opengl","status":"publish","type":"post","link":"https:\/\/www.itersdesktop.com\/fr\/2009\/10\/08\/drawing-arrow-in-opengl\/","title":{"rendered":"Drawing arrow in OpenGL"},"content":{"rendered":"<p>We have two points A and B in 3D. The problem is to find the way to draw a line that the started point is A and the later is B. We also want to have a little arrow at B.<\/p>\n<p>One guy posted the guide in <a href=\"http:\/\/www.gamedev.net\/community\/forums\/topic.asp?topic_id=63176\" target=\"_blank\">gamedev.net<\/a><br \/>Say: A = [x1, y1, z1] (start)<br \/>and B = [x2, y2, z2] (end)<br \/>and C = [x3, y3, z3] (arrow tip at one side)<br \/>and D = [x4, y4, z4] (tip at the other side)<\/p>\n<p>if((z1-z2) != 0) {<br \/>  first we make a normal vector:<br \/>  x3 = 1<br \/>  y3 = 1<br \/>  z3 = (-(x1-x2)-(y1-y2))\/(z1-z2)<\/p>\n<p>  adjusting the distance from the arrow axis to one fourth of the arrows lenght:<br \/>  adj = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)) \/ (4 * sqrt((x3^2)+(y3^2)+(z3^2)));<br \/>  x3 *= adj<br \/>  y3 *= adj<br \/>  z3 *= adj<\/p>\n<p>  setting the other side:<br \/>  x4 = -x3<br \/>  y4 = -y3<br \/>  z4 = -z3<\/p>\n<p>  gettin the point:<br \/>  x3 = x1 + (3\/4)*(x1-x2) + x3<br \/>  y3 = y1 + (3\/4)*(y1-y2) + y3<br \/>  z3 = z1 + (3\/4)*(z1-z2) + z3<\/p>\n<p>  x4 = x1 + (3\/4)*(x1-x2) + x4<br \/>  y4 = y1 + (3\/4)*(y1-y2) + y4<br \/>  z4 = z1 + (3\/4)*(z1-z2) + z4<br \/>}<\/p>\n<p>OK, I didn&rsquo;t double check this, but the clue is the \u00ab\u00a0first we make a normal vector:\u00a0\u00bb -section, the rest is fairly straight out. Oh and if you use float or double values, they rarely become zero, but if (z1-z2) should happen to be zero, then find the normal setting z3 = 1, y3 = 1, and x3 = (-(y1-y2)-(z1-z2))\/(x1-x2), that should work work as well, and if (x1-x2) also is zero, just base it on y the same way.<br \/>Well, as I said, I didn&rsquo;t double check this, but I know it works, there might be simpler ways also, be sure to tell me if I made some stupid mistakes here.<\/p>\n<hr size=\"1\"\/>\n<br \/>I appreciate this explanation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have two points A and B in 3D. The problem is to find the way to draw a line that the started point is A and the later is&hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-879","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/comments?post=879"}],"version-history":[{"count":0,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/879\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/media?parent=879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/categories?post=879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/tags?post=879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}