@@ -456,6 +456,86 @@ void DrawNode::drawPolygon(Point *verts, int count, const Color4F &fillColor, fl
456456 free (extrude);
457457}
458458
459+ void DrawNode::drawTriangle (const Point &p1, const Point &p2, const Point &p3, const Color4F &color)
460+ {
461+ unsigned int vertex_count = 2 *3 ;
462+ ensureCapacity (vertex_count);
463+
464+ Color4B col = Color4B (color);
465+ V2F_C4B_T2F a = {Vertex2F (p1.x , p1.y ), col, Tex2F (0.0 , 0.0 ) };
466+ V2F_C4B_T2F b = {Vertex2F (p2.x , p2.y ), col, Tex2F (0.0 , 0.0 ) };
467+ V2F_C4B_T2F c = {Vertex2F (p3.x , p3.y ), col, Tex2F (0.0 , 0.0 ) };
468+
469+ V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
470+ V2F_C4B_T2F_Triangle triangle = {a, b, c};
471+ triangles[0 ] = triangle;
472+
473+ _bufferCount += vertex_count;
474+ _dirty = true ;
475+ }
476+
477+ void DrawNode::drawCubicBezier (const Point& from, const Point& control1, const Point& control2, const Point& to, unsigned int segments, const Color4F &color)
478+ {
479+ unsigned int vertex_count = (segments + 1 ) * 3 ;
480+ ensureCapacity (vertex_count);
481+
482+ Tex2F texCoord = Tex2F (0.0 , 0.0 );
483+ Color4B col = Color4B (color);
484+ Vertex2F vertex;
485+ Vertex2F firstVertex = Vertex2F (from.x , from.y );
486+ Vertex2F lastVertex = Vertex2F (to.x , to.y );
487+
488+ float t = 0 ;
489+ for (unsigned int i = segments + 1 ; i > 0 ; i--)
490+ {
491+ float x = powf (1 - t, 3 ) * from.x + 3 .0f * powf (1 - t, 2 ) * t * control1.x + 3 .0f * (1 - t) * t * t * control2.x + t * t * t * to.x ;
492+ float y = powf (1 - t, 3 ) * from.y + 3 .0f * powf (1 - t, 2 ) * t * control1.y + 3 .0f * (1 - t) * t * t * control2.y + t * t * t * to.y ;
493+ vertex = Vertex2F (x, y);
494+
495+ V2F_C4B_T2F a = {firstVertex, col, texCoord };
496+ V2F_C4B_T2F b = {lastVertex, col, texCoord };
497+ V2F_C4B_T2F c = {vertex, col, texCoord };
498+ V2F_C4B_T2F_Triangle triangle = {a, b, c};
499+ ((V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount))[0 ] = triangle;
500+
501+ lastVertex = vertex;
502+ t += 1 .0f / segments;
503+ _bufferCount += 3 ;
504+ }
505+ _dirty = true ;
506+ }
507+
508+ void DrawNode::drawQuadraticBezier (const Point& from, const Point& control, const Point& to, unsigned int segments, const Color4F &color)
509+ {
510+ unsigned int vertex_count = (segments + 1 ) * 3 ;
511+ ensureCapacity (vertex_count);
512+
513+ Tex2F texCoord = Tex2F (0.0 , 0.0 );
514+ Color4B col = Color4B (color);
515+ Vertex2F vertex;
516+ Vertex2F firstVertex = Vertex2F (from.x , from.y );
517+ Vertex2F lastVertex = Vertex2F (to.x , to.y );
518+
519+ float t = 0 ;
520+ for (unsigned int i = segments + 1 ; i > 0 ; i--)
521+ {
522+ float x = powf (1 - t, 2 ) * from.x + 2 .0f * (1 - t) * t * control.x + t * t * to.x ;
523+ float y = powf (1 - t, 2 ) * from.y + 2 .0f * (1 - t) * t * control.y + t * t * to.y ;
524+ vertex = Vertex2F (x, y);
525+
526+ V2F_C4B_T2F a = {firstVertex, col, texCoord };
527+ V2F_C4B_T2F b = {lastVertex, col, texCoord };
528+ V2F_C4B_T2F c = {vertex, col, texCoord };
529+ V2F_C4B_T2F_Triangle triangle = {a, b, c};
530+ ((V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount))[0 ] = triangle;
531+
532+ lastVertex = vertex;
533+ t += 1 .0f / segments;
534+ _bufferCount += 3 ;
535+ }
536+ _dirty = true ;
537+ }
538+
459539void DrawNode::clear ()
460540{
461541 _bufferCount = 0 ;
0 commit comments