summaryrefslogtreecommitdiff
path: root/graphics/asymptote/beziercurve.cc
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/asymptote/beziercurve.cc')
-rw-r--r--graphics/asymptote/beziercurve.cc32
1 files changed, 26 insertions, 6 deletions
diff --git a/graphics/asymptote/beziercurve.cc b/graphics/asymptote/beziercurve.cc
index 23f5fc6779..9a5eee79f2 100644
--- a/graphics/asymptote/beziercurve.cc
+++ b/graphics/asymptote/beziercurve.cc
@@ -20,11 +20,30 @@ void BezierCurve::init(double res)
MaterialIndex=materialIndex;
}
+inline triple normal(triple bP, triple bPP)
+{
+ return dot(bP,bP)*bPP-dot(bP,bPP)*bP;
+}
+
void BezierCurve::render(const triple *p, bool straight)
{
- GLuint i0=data.vertex1(p[0]);
- GLuint i3=data.vertex1(p[3]);
-
+ triple p0=p[0];
+ triple p3=p[3];
+ triple n0,n1;
+
+ if(straight) {
+ n0=n1=triple(0.0,0.0,1.0);
+ } else {
+ triple p1=p[1];
+ triple p2=p[2];
+
+ n0=normal(p1-p0,p0+p2-2.0*p1);
+ n1=normal(p3-p2,p3+p1-2.0*p2);
+ }
+
+ GLuint i0=data.vertex(p0,n0);
+ GLuint i3=data.vertex(p3,n1);
+
if(straight) {
std::vector<GLuint> &q=data.indices;
q.push_back(i0);
@@ -34,9 +53,9 @@ void BezierCurve::render(const triple *p, bool straight)
append();
}
-// Use a uniform partition to draw a Bezier patch.
+// Use a uniform partition to draw a Bezier curve.
// p is an array of 4 triples representing the control points.
-// Ii are the vertices indices.
+// Ii are the vertex indices.
void BezierCurve::render(const triple *p, GLuint I0, GLuint I1)
{
triple p0=p[0];
@@ -62,7 +81,8 @@ void BezierCurve::render(const triple *p, GLuint I0, GLuint I1)
triple s0[]={p0,m0,m3,m5};
triple s1[]={m5,m4,m2,p3};
- GLuint i0=data.vertex1(m5);
+ triple n0=normal(bezierPh(p0,p1,p2,p3),bezierPPh(p0,p1,p2,p3));
+ GLuint i0=data.vertex(m5,n0);
render(s0,I0,i0);
render(s1,i0,I1);