MCPcopy Create free account
hub / github.com/carbonengine/trinity / AddSegment

Method AddSegment

trinity/Sprite2d/Tr2Sprite2dLineTrace.cpp:288–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286}
287
288void Tr2Sprite2dLineTrace::AddSegment(
289 Tr2Sprite2dScene* renderer,
290 const Vector2& from,
291 const Color& fromColor,
292 float capAngleFrom,
293 const Vector2& to,
294 const Color& toColor,
295 float capAngleTo )
296{
297 Vector2 d = to - from;
298 float segmentLength = Length( d );
299 d = Normalize( d );
300
301 // calculate texture offset
302 float texOffset1 = m_textureOffsetAccum / m_textureWidth - m_textureOffset;
303 m_textureOffsetAccum += segmentLength;
304 float texOffset2 = m_textureOffsetAccum / m_textureWidth - m_textureOffset;
305
306 // Anti-aliased lines are rendered with a quad that is larger. This is then
307 // compensated for in the pixel shader, using the extra pixels to fill in
308 // alpha values to do the anti-aliasing
309
310 bool isAA = m_spriteEffect == TR2_SFX_FILL_AA;
311 float pixelWidthInTexels = 1;
312
313 float halfWidth = 0.5f * m_lineWidth;
314
315 if( isAA )
316 {
317 halfWidth += 2.0f;
318 pixelWidthInTexels = 1.0f / ( m_lineWidth + 4.0f );
319 }
320
321 capAngleFrom = ClampAngle( capAngleFrom );
322 capAngleTo = ClampAngle( capAngleTo );
323
324 // Shorten lines to account for corners
325 Vector2 adjustedFrom, adjustedTo;
326 if( m_cornerType != CORNERTYPE_NONE )
327 {
328 float shorteningForCap = halfWidth * tan( std::abs( capAngleTo ) * 0.5f );
329 adjustedTo = to - shorteningForCap * d;
330
331 shorteningForCap = halfWidth * tan( std::abs( capAngleFrom ) * 0.5f );
332 adjustedFrom = from + shorteningForCap * d;
333 }
334 else
335 {
336 adjustedTo = to;
337 adjustedFrom = from;
338 }
339
340 // Rotate 90 degrees
341 Vector2 normal( d.y, -d.x );
342
343 uint32_t totalVertexCount = uint32_t( m_renderVertices.size() ) - m_drawCalls.back().vertexOffset;
344 uint32_t totalIndexCount = uint32_t( m_renderIndices.size() ) - m_drawCalls.back().indexOffset;
345 uint32_t segmentVertices = 4;

Callers

nothing calls this directly

Calls 5

LengthFunction · 0.85
sizeMethod · 0.80
PrepareTriangleVertsMethod · 0.80

Tested by

no test coverage detected