Skip to content

Commit ab7daf3

Browse files
committed
Add 3D quadraticVertex overload
1 parent ef39d41 commit ab7daf3

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/Processing.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,15 @@ void PApplet::quadraticVertex(float cx,float cy,float x,float y){
16551655
auto[x0,y0]=shapeVerts.back();const int sg=bezierDetailVal;
16561656
for(int i=1;i<=sg;i++){float t=i/(float)sg,u=1-t;float qx=u*u*x0+2*u*t*cx+t*t*x,qy=u*u*y0+2*u*t*cy+t*t*y;shapeVerts.push_back({qx,qy});shapeVerts3D.push_back({qx,qy,0.0f});}
16571657
}
1658+
void PApplet::quadraticVertex(float cx,float cy,float cz,float x,float y,float z){
1659+
// Convert quadratic to cubic bezier
1660+
if(!inShape||shapeVerts3D.empty()) return;
1661+
float ax=shapeVerts3D.back()[0],ay=shapeVerts3D.back()[1],az=shapeVerts3D.back()[2];
1662+
float cx1=ax+(2.f/3.f)*(cx-ax), cy1=ay+(2.f/3.f)*(cy-ay), cz1=az+(2.f/3.f)*(cz-az);
1663+
float cx2=x+(2.f/3.f)*(cx-x), cy2=y+(2.f/3.f)*(cy-y), cz2=z+(2.f/3.f)*(cz-z);
1664+
bezierVertex(cx1,cy1,cz1,cx2,cy2,cz2,x,y,z);
1665+
}
1666+
16581667
void PApplet::curveVertex(float x,float y){if(inShape){shapeVerts.push_back({x,y});shapeVerts3D.push_back({x,y,0.0f});}}
16591668
void PApplet::curveVertex(float x,float y,float z){if(inShape){shapeVerts.push_back({x,y});shapeVerts3D.push_back({x,y,z});}}
16601669
void PApplet::bezierVertex(float cx1,float cy1,float cz1,float cx2,float cy2,float cz2,float x,float y,float z){

src/Processing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,6 +4152,7 @@ struct PApplet {
41524152
void bezierVertex(float cx1, float cy1, float cx2, float cy2, float x, float y);
41534153
void bezierVertex(float cx1,float cy1,float cz1,float cx2,float cy2,float cz2,float x,float y,float z);
41544154
void quadraticVertex(float cx, float cy, float x, float y);
4155+
void quadraticVertex(float cx, float cy, float cz, float x, float y, float z);
41554156
void curveVertex(float x, float y);
41564157
void curveVertex(float x, float y, float z);
41574158
void beginContour();

0 commit comments

Comments
 (0)