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

Method AddRoundJoint

trinity/Sprite2d/Tr2Sprite2dLineTrace.cpp:527–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525}
526
527void Tr2Sprite2dLineTrace::AddRoundJoint(
528 Tr2Sprite2dScene* renderer,
529 float capAngleTo,
530 Tr2Sprite2dVertexBase v2,
531 Tr2Sprite2dVertexBase v3,
532 Vector2 normal,
533 Color color,
534 bool isAA,
535 float pixelWidthInTexels,
536 float halfWidth )
537{
538 uint16_t fanBase;
539 Vector2 fanBaseTranslation( 0, 0 );
540 auto fanVertexBase = m_renderVertices.size();
541 float sign = 1.0f;
542 float jointWidth = halfWidth * 2.0f;
543
544 // Determine fan base point
545 if( capAngleTo < 0.0f )
546 {
547 fanBase = 2 + (uint16_t)fanVertexBase - 4;
548 fanBaseTranslation = v2.position.GetXY();
549 sign = -1.0f;
550 }
551 else if( capAngleTo > 0.0f )
552 {
553 fanBase = 3 + (uint16_t)fanVertexBase - 4;
554 fanBaseTranslation = v3.position.GetXY();
555 }
556
557 // calculate joint angle
558 float startAngle = atan2( normal.y, normal.x );
559 float endAngle = startAngle + capAngleTo;
560 float angleDiff = endAngle - startAngle;
561
562 // calculate arc length and number of steps
563 float arcLength = angleDiff * m_lineWidth;
564 unsigned int numSteps = (unsigned int)std::abs( arcLength ) / 4;
565
566 if( numSteps < 2 )
567 numSteps = 2;
568 float stepSize = angleDiff / (float)numSteps;
569 ++numSteps;
570
571 if( numSteps > jointWidth )
572 {
573 numSteps = (unsigned int)m_lineWidth;
574 stepSize = angleDiff / (float)( numSteps - 1 );
575 }
576
577 // Create verticies
578 Tr2Sprite2dVertexBase* fanVerts = static_cast<Tr2Sprite2dVertexBase*>( CCP_MALLOC(
579 "Tr2Sprite2dLineTrace/fanVerts",
580 numSteps * sizeof( Tr2Sprite2dVertexBase ) ) );
581 Tr2Sprite2dVertexBase* currentVertex = fanVerts;
582
583 // Construct outer joint vertexes
584 float a = startAngle;

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.80
PrepareTriangleVertsMethod · 0.80

Tested by

no test coverage detected