line_builder.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /**************************************************************************/
  2. /* line_builder.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "line_builder.h"
  31. #include "core/math/geometry_2d.h"
  32. // Utility method.
  33. static inline Vector2 interpolate(const Rect2 &r, const Vector2 &v) {
  34. return Vector2(
  35. Math::lerp(r.position.x, r.position.x + r.get_size().x, v.x),
  36. Math::lerp(r.position.y, r.position.y + r.get_size().y, v.y));
  37. }
  38. LineBuilder::LineBuilder() {
  39. }
  40. void LineBuilder::build() {
  41. // Need at least 2 points to draw a line, so clear the output and return.
  42. if (points.size() < 2) {
  43. vertices.clear();
  44. colors.clear();
  45. indices.clear();
  46. uvs.clear();
  47. return;
  48. }
  49. ERR_FAIL_COND(tile_aspect <= 0.f);
  50. const float hw = width / 2.f;
  51. const float hw_sq = hw * hw;
  52. const float sharp_limit_sq = sharp_limit * sharp_limit;
  53. const int point_count = points.size();
  54. const bool wrap_around = closed && point_count > 2;
  55. _interpolate_color = gradient != nullptr;
  56. const bool retrieve_curve = curve != nullptr;
  57. const bool distance_required = _interpolate_color || retrieve_curve ||
  58. texture_mode == Line2D::LINE_TEXTURE_TILE ||
  59. texture_mode == Line2D::LINE_TEXTURE_STRETCH;
  60. // Initial values
  61. Vector2 pos0 = points[0];
  62. Vector2 pos1 = points[1];
  63. Vector2 f0 = (pos1 - pos0).normalized();
  64. Vector2 u0 = f0.orthogonal();
  65. Vector2 pos_up0 = pos0;
  66. Vector2 pos_down0 = pos0;
  67. Color color0;
  68. Color color1;
  69. float current_distance0 = 0.f;
  70. float current_distance1 = 0.f;
  71. float total_distance = 0.f;
  72. float width_factor = 1.f;
  73. float modified_hw = hw;
  74. if (retrieve_curve) {
  75. width_factor = curve->sample_baked(0.f);
  76. modified_hw = hw * width_factor;
  77. }
  78. if (distance_required) {
  79. // Calculate the total distance.
  80. for (int i = 1; i < point_count; ++i) {
  81. total_distance += points[i].distance_to(points[i - 1]);
  82. }
  83. if (wrap_around) {
  84. total_distance += points[point_count - 1].distance_to(pos0);
  85. } else {
  86. // Adjust the total distance.
  87. // The line's outer length may be a little higher due to the end caps.
  88. if (begin_cap_mode == Line2D::LINE_CAP_BOX || begin_cap_mode == Line2D::LINE_CAP_ROUND) {
  89. total_distance += modified_hw;
  90. }
  91. if (end_cap_mode == Line2D::LINE_CAP_BOX || end_cap_mode == Line2D::LINE_CAP_ROUND) {
  92. if (retrieve_curve) {
  93. total_distance += hw * curve->sample_baked(1.f);
  94. } else {
  95. total_distance += hw;
  96. }
  97. }
  98. }
  99. }
  100. if (point_count < 2 || (distance_required && Math::is_zero_approx(total_distance))) {
  101. // Zero-length line, nothing to build.
  102. return;
  103. }
  104. if (_interpolate_color) {
  105. color0 = gradient->get_color(0);
  106. } else {
  107. colors.push_back(default_color);
  108. }
  109. float uvx0 = 0.f;
  110. float uvx1 = 0.f;
  111. pos_up0 += u0 * modified_hw;
  112. pos_down0 -= u0 * modified_hw;
  113. // Begin cap
  114. if (!wrap_around) {
  115. if (begin_cap_mode == Line2D::LINE_CAP_BOX) {
  116. // Push back first vertices a little bit.
  117. pos_up0 -= f0 * modified_hw;
  118. pos_down0 -= f0 * modified_hw;
  119. current_distance0 += modified_hw;
  120. current_distance1 = current_distance0;
  121. } else if (begin_cap_mode == Line2D::LINE_CAP_ROUND) {
  122. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  123. uvx0 = width_factor * 0.5f / tile_aspect;
  124. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  125. uvx0 = width * width_factor / total_distance;
  126. }
  127. new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, uvx0 * 2, 1.f));
  128. current_distance0 += modified_hw;
  129. current_distance1 = current_distance0;
  130. }
  131. strip_begin(pos_up0, pos_down0, color0, uvx0);
  132. }
  133. /*
  134. * pos_up0 ------------- pos_up1 --------------------
  135. * | |
  136. * pos0 - - - - - - - - - pos1 - - - - - - - - - pos2
  137. * | |
  138. * pos_down0 ------------ pos_down1 ------------------
  139. *
  140. * i-1 i i+1
  141. */
  142. // http://labs.hyperandroid.com/tag/opengl-lines
  143. // (not the same implementation but visuals help a lot)
  144. // If the polyline wraps around, then draw two more segments with joints:
  145. // The last one, which should normally end with an end cap, and the one that matches the end and the beginning.
  146. int segments_count = wrap_around ? point_count : (point_count - 2);
  147. // The wraparound case starts with a "fake walk" from the end of the polyline
  148. // to its beginning, so that its first joint is correct, without drawing anything.
  149. int first_point = wrap_around ? -1 : 1;
  150. // If the line wraps around, these variables will be used for the final segment.
  151. Vector2 first_pos_up, first_pos_down;
  152. bool is_first_joint_sharp = false;
  153. // For each additional segment
  154. for (int i = first_point; i <= segments_count; ++i) {
  155. pos1 = points[(i == -1) ? point_count - 1 : i % point_count]; // First point.
  156. Vector2 pos2 = points[(i + 1) % point_count]; // Second point.
  157. Vector2 f1 = (pos2 - pos1).normalized();
  158. Vector2 u1 = f1.orthogonal();
  159. // Determine joint orientation.
  160. float dp = u0.dot(f1);
  161. const Orientation orientation = (dp > 0.f ? UP : DOWN);
  162. if (distance_required && i >= 1) {
  163. current_distance1 += pos0.distance_to(pos1);
  164. }
  165. if (_interpolate_color) {
  166. color1 = gradient->get_color_at_offset(current_distance1 / total_distance);
  167. }
  168. if (retrieve_curve) {
  169. width_factor = curve->sample_baked(current_distance1 / total_distance);
  170. modified_hw = hw * width_factor;
  171. }
  172. Vector2 inner_normal0 = u0 * modified_hw;
  173. Vector2 inner_normal1 = u1 * modified_hw;
  174. if (orientation == DOWN) {
  175. inner_normal0 = -inner_normal0;
  176. inner_normal1 = -inner_normal1;
  177. }
  178. /*
  179. * ---------------------------
  180. * /
  181. * 0 / 1
  182. * / /
  183. * --------------------x------ /
  184. * / / (here shown with orientation == DOWN)
  185. * / /
  186. * / /
  187. * / /
  188. * 2 /
  189. * /
  190. */
  191. // Find inner intersection at the joint.
  192. Vector2 corner_pos_in, corner_pos_out;
  193. bool is_intersecting = Geometry2D::segment_intersects_segment(
  194. pos0 + inner_normal0, pos1 + inner_normal0,
  195. pos1 + inner_normal1, pos2 + inner_normal1,
  196. &corner_pos_in);
  197. if (is_intersecting) {
  198. // Inner parts of the segments intersect.
  199. corner_pos_out = 2.f * pos1 - corner_pos_in;
  200. } else {
  201. // No intersection, segments are too sharp or they overlap.
  202. corner_pos_in = pos1 + inner_normal0;
  203. corner_pos_out = pos1 - inner_normal0;
  204. }
  205. Vector2 corner_pos_up, corner_pos_down;
  206. if (orientation == UP) {
  207. corner_pos_up = corner_pos_in;
  208. corner_pos_down = corner_pos_out;
  209. } else {
  210. corner_pos_up = corner_pos_out;
  211. corner_pos_down = corner_pos_in;
  212. }
  213. Line2D::LineJointMode current_joint_mode = joint_mode;
  214. Vector2 pos_up1, pos_down1;
  215. if (is_intersecting) {
  216. // Fallback on bevel if sharp angle is too high (because it would produce very long miters).
  217. float width_factor_sq = width_factor * width_factor;
  218. if (current_joint_mode == Line2D::LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / (hw_sq * width_factor_sq) > sharp_limit_sq) {
  219. current_joint_mode = Line2D::LINE_JOINT_BEVEL;
  220. }
  221. if (current_joint_mode == Line2D::LINE_JOINT_SHARP) {
  222. // In this case, we won't create joint geometry,
  223. // The previous and next line quads will directly share an edge.
  224. pos_up1 = corner_pos_up;
  225. pos_down1 = corner_pos_down;
  226. } else {
  227. // Bevel or round
  228. if (orientation == UP) {
  229. pos_up1 = corner_pos_up;
  230. pos_down1 = pos1 - u0 * modified_hw;
  231. } else {
  232. pos_up1 = pos1 + u0 * modified_hw;
  233. pos_down1 = corner_pos_down;
  234. }
  235. }
  236. } else {
  237. // No intersection: fallback
  238. if (current_joint_mode == Line2D::LINE_JOINT_SHARP) {
  239. // There is no fallback implementation for LINE_JOINT_SHARP so switch to the LINE_JOINT_BEVEL.
  240. current_joint_mode = Line2D::LINE_JOINT_BEVEL;
  241. }
  242. pos_up1 = corner_pos_up;
  243. pos_down1 = corner_pos_down;
  244. }
  245. // Triangles are clockwise.
  246. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  247. uvx1 = current_distance1 / (width * tile_aspect);
  248. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  249. uvx1 = current_distance1 / total_distance;
  250. }
  251. // Swap vars for use in the next line.
  252. color0 = color1;
  253. u0 = u1;
  254. f0 = f1;
  255. pos0 = pos1;
  256. if (is_intersecting) {
  257. if (current_joint_mode == Line2D::LINE_JOINT_SHARP) {
  258. pos_up0 = pos_up1;
  259. pos_down0 = pos_down1;
  260. } else {
  261. if (orientation == UP) {
  262. pos_up0 = corner_pos_up;
  263. pos_down0 = pos1 - u1 * modified_hw;
  264. } else {
  265. pos_up0 = pos1 + u1 * modified_hw;
  266. pos_down0 = corner_pos_down;
  267. }
  268. }
  269. } else {
  270. pos_up0 = pos1 + u1 * modified_hw;
  271. pos_down0 = pos1 - u1 * modified_hw;
  272. }
  273. // End the "fake pass" in the closed line case before the drawing subroutine.
  274. if (i == -1) {
  275. continue;
  276. }
  277. // For wrap-around polylines, store some kind of start positions of the first joint for the final connection.
  278. if (wrap_around && i == 0) {
  279. Vector2 first_pos_center = (pos_up1 + pos_down1) / 2;
  280. float lerp_factor = 1.0 / width_factor;
  281. first_pos_up = first_pos_center.lerp(pos_up1, lerp_factor);
  282. first_pos_down = first_pos_center.lerp(pos_down1, lerp_factor);
  283. is_first_joint_sharp = current_joint_mode == Line2D::LINE_JOINT_SHARP;
  284. }
  285. // Add current line body quad.
  286. if (wrap_around && retrieve_curve && !is_first_joint_sharp && i == segments_count) {
  287. // If the width curve is not seamless, we might need to fetch the line's start points to use them for the final connection.
  288. Vector2 first_pos_center = (first_pos_up + first_pos_down) / 2;
  289. strip_add_quad(first_pos_center.lerp(first_pos_up, width_factor), first_pos_center.lerp(first_pos_down, width_factor), color1, uvx1);
  290. return;
  291. } else {
  292. strip_add_quad(pos_up1, pos_down1, color1, uvx1);
  293. }
  294. // From this point, bu0 and bd0 concern the next segment.
  295. // Add joint geometry.
  296. if (current_joint_mode != Line2D::LINE_JOINT_SHARP) {
  297. /* ________________ cbegin
  298. * / \
  299. * / \
  300. * ____________/_ _ _\ cend
  301. * | |
  302. * | |
  303. * | |
  304. */
  305. Vector2 cbegin, cend;
  306. if (orientation == UP) {
  307. cbegin = pos_down1;
  308. cend = pos_down0;
  309. } else {
  310. cbegin = pos_up1;
  311. cend = pos_up0;
  312. }
  313. if (current_joint_mode == Line2D::LINE_JOINT_BEVEL && !(wrap_around && i == segments_count)) {
  314. strip_add_tri(cend, orientation);
  315. } else if (current_joint_mode == Line2D::LINE_JOINT_ROUND && !(wrap_around && i == segments_count)) {
  316. Vector2 vbegin = cbegin - pos1;
  317. Vector2 vend = cend - pos1;
  318. // We want to use vbegin.angle_to(vend) below, which evaluates to
  319. // Math::atan2(vbegin.cross(vend), vbegin.dot(vend)) but we need to
  320. // calculate this ourselves as we need to check if the cross product
  321. // in that calculation ends up being -0.f and flip it if so, effectively
  322. // flipping the resulting angle_delta to not return -PI but +PI instead
  323. float cross_product = vbegin.cross(vend);
  324. float dot_product = vbegin.dot(vend);
  325. // Note that we're comparing against -0.f for clarity but 0.f would
  326. // match as well, therefore we need the explicit signbit check too.
  327. if (cross_product == -0.f && signbit(cross_product)) {
  328. cross_product = 0.f;
  329. }
  330. float angle_delta = Math::atan2(cross_product, dot_product);
  331. strip_add_arc(pos1, angle_delta, orientation);
  332. }
  333. if (!is_intersecting) {
  334. // In this case the joint is too corrupted to be reused,
  335. // start again the strip with fallback points
  336. strip_begin(pos_up0, pos_down0, color1, uvx1);
  337. }
  338. }
  339. }
  340. // Draw the last (or only) segment, with its end cap logic.
  341. if (!wrap_around) {
  342. pos1 = points[point_count - 1];
  343. if (distance_required) {
  344. current_distance1 += pos0.distance_to(pos1);
  345. }
  346. if (_interpolate_color) {
  347. color1 = gradient->get_color(gradient->get_point_count() - 1);
  348. }
  349. if (retrieve_curve) {
  350. width_factor = curve->sample_baked(1.f);
  351. modified_hw = hw * width_factor;
  352. }
  353. Vector2 pos_up1 = pos1 + u0 * modified_hw;
  354. Vector2 pos_down1 = pos1 - u0 * modified_hw;
  355. // Add extra distance for a box end cap.
  356. if (end_cap_mode == Line2D::LINE_CAP_BOX) {
  357. pos_up1 += f0 * modified_hw;
  358. pos_down1 += f0 * modified_hw;
  359. current_distance1 += modified_hw;
  360. }
  361. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  362. uvx1 = current_distance1 / (width * tile_aspect);
  363. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  364. uvx1 = current_distance1 / total_distance;
  365. }
  366. strip_add_quad(pos_up1, pos_down1, color1, uvx1);
  367. // Custom drawing for a round end cap.
  368. if (end_cap_mode == Line2D::LINE_CAP_ROUND) {
  369. // Note: color is not used in case we don't interpolate.
  370. Color color = _interpolate_color ? gradient->get_color(gradient->get_point_count() - 1) : Color(0, 0, 0);
  371. float dist = 0;
  372. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  373. dist = width_factor / tile_aspect;
  374. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  375. dist = width * width_factor / total_distance;
  376. }
  377. new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f * dist, 0.f, dist, 1.f));
  378. }
  379. }
  380. }
  381. void LineBuilder::strip_begin(Vector2 up, Vector2 down, Color color, float uvx) {
  382. int vi = vertices.size();
  383. vertices.push_back(up);
  384. vertices.push_back(down);
  385. if (_interpolate_color) {
  386. colors.push_back(color);
  387. colors.push_back(color);
  388. }
  389. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  390. uvs.push_back(Vector2(uvx, 0.f));
  391. uvs.push_back(Vector2(uvx, 1.f));
  392. }
  393. _last_index[UP] = vi;
  394. _last_index[DOWN] = vi + 1;
  395. }
  396. void LineBuilder::strip_add_quad(Vector2 up, Vector2 down, Color color, float uvx) {
  397. int vi = vertices.size();
  398. vertices.push_back(up);
  399. vertices.push_back(down);
  400. if (_interpolate_color) {
  401. colors.push_back(color);
  402. colors.push_back(color);
  403. }
  404. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  405. uvs.push_back(Vector2(uvx, 0.f));
  406. uvs.push_back(Vector2(uvx, 1.f));
  407. }
  408. indices.push_back(_last_index[UP]);
  409. indices.push_back(vi + 1);
  410. indices.push_back(_last_index[DOWN]);
  411. indices.push_back(_last_index[UP]);
  412. indices.push_back(vi);
  413. indices.push_back(vi + 1);
  414. _last_index[UP] = vi;
  415. _last_index[DOWN] = vi + 1;
  416. }
  417. void LineBuilder::strip_add_tri(Vector2 up, Orientation orientation) {
  418. int vi = vertices.size();
  419. vertices.push_back(up);
  420. if (_interpolate_color) {
  421. colors.push_back(colors[colors.size() - 1]);
  422. }
  423. Orientation opposite_orientation = orientation == UP ? DOWN : UP;
  424. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  425. // UVs are just one slice of the texture all along
  426. // (otherwise we can't share the bottom vertex)
  427. uvs.push_back(uvs[_last_index[opposite_orientation]]);
  428. }
  429. indices.push_back(_last_index[opposite_orientation]);
  430. indices.push_back(vi);
  431. indices.push_back(_last_index[orientation]);
  432. _last_index[opposite_orientation] = vi;
  433. }
  434. void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation orientation) {
  435. // Take the two last vertices and extrude an arc made of triangles
  436. // that all share one of the initial vertices
  437. Orientation opposite_orientation = orientation == UP ? DOWN : UP;
  438. Vector2 vbegin = vertices[_last_index[opposite_orientation]] - center;
  439. float radius = vbegin.length();
  440. float angle_step = Math_PI / static_cast<float>(round_precision);
  441. float steps = Math::abs(angle_delta) / angle_step;
  442. if (angle_delta < 0.f) {
  443. angle_step = -angle_step;
  444. }
  445. float t = Vector2(1, 0).angle_to(vbegin);
  446. float end_angle = t + angle_delta;
  447. Vector2 rpos(0, 0);
  448. // Arc vertices
  449. for (int ti = 0; ti < steps; ++ti, t += angle_step) {
  450. rpos = center + Vector2(Math::cos(t), Math::sin(t)) * radius;
  451. strip_add_tri(rpos, orientation);
  452. }
  453. // Last arc vertex
  454. rpos = center + Vector2(Math::cos(end_angle), Math::sin(end_angle)) * radius;
  455. strip_add_tri(rpos, orientation);
  456. }
  457. void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Color color, Rect2 uv_rect) {
  458. // Make a standalone arc that doesn't use existing vertices,
  459. // with undistorted UVs from within a square section
  460. float radius = vbegin.length();
  461. float angle_step = Math_PI / static_cast<float>(round_precision);
  462. float steps = Math::abs(angle_delta) / angle_step;
  463. if (angle_delta < 0.f) {
  464. angle_step = -angle_step;
  465. }
  466. float t = Vector2(1, 0).angle_to(vbegin);
  467. float end_angle = t + angle_delta;
  468. Vector2 rpos(0, 0);
  469. float tt_begin = -Math_PI / 2.0f;
  470. float tt = tt_begin;
  471. // Center vertice
  472. int vi = vertices.size();
  473. vertices.push_back(center);
  474. if (_interpolate_color) {
  475. colors.push_back(color);
  476. }
  477. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  478. uvs.push_back(interpolate(uv_rect, Vector2(0.5f, 0.5f)));
  479. }
  480. // Arc vertices
  481. for (int ti = 0; ti < steps; ++ti, t += angle_step) {
  482. Vector2 sc = Vector2(Math::cos(t), Math::sin(t));
  483. rpos = center + sc * radius;
  484. vertices.push_back(rpos);
  485. if (_interpolate_color) {
  486. colors.push_back(color);
  487. }
  488. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  489. Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
  490. uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f))));
  491. tt += angle_step;
  492. }
  493. }
  494. // Last arc vertex
  495. Vector2 sc = Vector2(Math::cos(end_angle), Math::sin(end_angle));
  496. rpos = center + sc * radius;
  497. vertices.push_back(rpos);
  498. if (_interpolate_color) {
  499. colors.push_back(color);
  500. }
  501. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  502. tt = tt_begin + angle_delta;
  503. Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
  504. uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f))));
  505. }
  506. // Make up triangles
  507. int vi0 = vi;
  508. for (int ti = 0; ti < steps; ++ti) {
  509. indices.push_back(vi0);
  510. indices.push_back(++vi);
  511. indices.push_back(vi + 1);
  512. }
  513. }