MCPcopy Create free account
hub / github.com/axmolengine/axmol / _drawSegment

Method _drawSegment

core/2d/DrawNode.cpp:1070–1199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1068}
1069
1070void DrawNode::_drawSegment(const Vec2& from,
1071 const Vec2& to,
1072 const Color4F& color,
1073 float thickness,
1074 DrawNode::EndType etStart,
1075 DrawNode::EndType etEnd)
1076{
1077 if (thickness < 1.0f)
1078 thickness = 1.0f;
1079
1080 if (thickness == 1.0f && !properties.drawOrder)
1081 {
1082 _drawLine(from, to, color); // fastest way to draw a line
1083 }
1084 else
1085 {
1086 Vec2 vertices[2] = {from, to};
1087 applyTransform(vertices, vertices, 2);
1088
1089 float width = thickness / (2 * properties.factor);
1090
1091 Vec2 a = vertices[0];
1092 Vec2 b = vertices[1];
1093 Vec2 n = ((b - a).getPerp()).getNormalized();
1094 Vec2 t = n.getPerp();
1095 Vec2 nw = n * width;
1096 Vec2 tw = t * width;
1097 Vec2 v0 = b - (nw + tw);
1098 Vec2 v1 = b + (nw - tw);
1099 Vec2 v2 = b - nw;
1100 Vec2 v3 = b + nw;
1101 Vec2 v4 = a - nw;
1102 Vec2 v5 = a + nw;
1103 Vec2 v6 = a - (nw - tw);
1104 Vec2 v7 = a + (nw + tw);
1105
1106 unsigned int vertex_count = 3 * ((etStart != DrawNode::EndType::Butt) ? 2 : 0) + 3 * 2 +
1107 3 * ((etEnd != DrawNode::EndType::Butt) ? 2 : 0);
1108 auto triangles = reinterpret_cast<V2F_C4B_T2F_Triangle*>(expandBufferAndGetPointer(_triangles, vertex_count));
1109 _trianglesDirty = true;
1110
1111 int ii = 0;
1112 switch (etEnd)
1113 {
1114 case DrawNode::EndType::Butt:
1115 break;
1116
1117 case DrawNode::EndType::Square:
1118 triangles[ii++] = {
1119 {v0, color, Vec2::ZERO},
1120 {v1, color, -n},
1121 {v2, color, n},
1122 };
1123
1124 triangles[ii++] = {
1125 {v3, color, n},
1126 {v1, color, Vec2::ZERO},
1127 {v2, color, -n},

Callers

nothing calls this directly

Calls 2

getNormalizedMethod · 0.45

Tested by

no test coverage detected