Bézier curves now render in 3D

Sun, 04 Oct 2015 06:59:09 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 04 Oct 2015 06:59:09 +0300
changeset 1004
ba4200437179
parent 1003
31873c3cbdbc
child 1005
a88cf5a32246

Bézier curves now render in 3D

src/glCompiler.cpp file | annotate | diff | comparison | revisions
src/ldObject.cpp file | annotate | diff | comparison | revisions
src/ldObject.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
--- a/src/glCompiler.cpp	Sun Oct 04 06:43:02 2015 +0300
+++ b/src/glCompiler.cpp	Sun Oct 04 06:59:09 2015 +0300
@@ -337,6 +337,17 @@
 			break;
 		}
 
+	case OBJ_BezierCurve:
+		{
+			LDBezierCurve* curve = static_cast<LDBezierCurve*> (obj);
+			for (LDPolygon& poly : curve->rasterizePolygons (24))
+			{
+				poly.id = obj->id();
+				compilePolygon (poly, obj, &info);
+			}
+		}
+		break;
+
 		default:
 			break;
 	}
--- a/src/ldObject.cpp	Sun Oct 04 06:43:02 2015 +0300
+++ b/src/ldObject.cpp	Sun Oct 04 06:59:09 2015 +0300
@@ -1087,7 +1087,22 @@
 
 LDObjectList LDBezierCurve::rasterize (int segments)
 {
+	QVector<LDPolygon> polygons = rasterizePolygons (segments);
 	LDObjectList result;
+
+	for (LDPolygon& poly : polygons)
+	{
+		LDLine* line = LDSpawn<LDLine> (poly.vertices[0], poly.vertices[1]);
+		line->setColor (poly.color);
+		result << line;
+	}
+
+	return result;
+}
+
+QVector<LDPolygon> LDBezierCurve::rasterizePolygons (int segments)
+{
+	QVector<LDPolygon> result;
 	QVector<Vertex> parms;
 	parms.append (pointAt (0.0));
 
@@ -1095,12 +1110,16 @@
 		parms.append (pointAt (double (i) / segments));
 
 	parms.append (pointAt (1.0));
+	LDPolygon poly;
+	poly.color = color().index();
+	poly.id = id();
+	poly.num = 2;
 
 	for (int i = 0; i < segments; ++i)
 	{
-		LDLine* line = LDSpawn<LDLine> (parms[i], parms[i + 1]);
-		line->setColor (color());
-		result << line;
+		poly.vertices[0] = parms[i];
+		poly.vertices[1] = parms[i + 1];
+		result << poly;
 	}
 
 	return result;
--- a/src/ldObject.h	Sun Oct 04 06:43:02 2015 +0300
+++ b/src/ldObject.h	Sun Oct 04 06:59:09 2015 +0300
@@ -464,6 +464,7 @@
 		const Vertex& v2, const Vertex& v3, LDDocument* document = nullptr);
 	Vertex pointAt (qreal t) const;
 	LDObjectList rasterize (int segments);
+	QVector<LDPolygon> rasterizePolygons (int segments);
 };
 
 // Other common LDraw stuff
--- a/src/mainwindow.cpp	Sun Oct 04 06:43:02 2015 +0300
+++ b/src/mainwindow.cpp	Sun Oct 04 06:59:09 2015 +0300
@@ -407,6 +407,7 @@
 			case OBJ_Triangle:
 			case OBJ_Quad:
 			case OBJ_CondLine:
+			case OBJ_BezierCurve:
 			{
 				for (int i = 0; i < obj->numVertices(); ++i)
 				{

mercurial