Skip to content

Commit dc969b3

Browse files
committed
Add 3D bezierVertex and curveVertex overloads
1 parent e267358 commit dc969b3

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/Processing.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,19 @@ void PApplet::quadraticVertex(float cx,float cy,float x,float y){
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
}
16581658
void PApplet::curveVertex(float x,float y){if(inShape){shapeVerts.push_back({x,y});shapeVerts3D.push_back({x,y,0.0f});}}
1659+
void PApplet::curveVertex(float x,float y,float z){if(inShape){shapeVerts.push_back({x,y});shapeVerts3D.push_back({x,y,z});}}
1660+
void PApplet::bezierVertex(float cx1,float cy1,float cz1,float cx2,float cy2,float cz2,float x,float y,float z){
1661+
if(!inShape) return;
1662+
float ax=shapeVerts3D.back()[0],ay=shapeVerts3D.back()[1],az=shapeVerts3D.back()[2];
1663+
int steps=20;
1664+
for(int i=1;i<=steps;i++){
1665+
float t=(float)i/steps,t2=t*t,t3=t2*t,mt=1-t,mt2=mt*mt,mt3=mt2*mt;
1666+
float px=mt3*ax+3*mt2*t*cx1+3*mt*t2*cx2+t3*x;
1667+
float py=mt3*ay+3*mt2*t*cy1+3*mt*t2*cy2+t3*y;
1668+
float pz=mt3*az+3*mt2*t*cz1+3*mt*t2*cz2+t3*z;
1669+
shapeVerts.push_back({px,py}); shapeVerts3D.push_back({px,py,pz});
1670+
}
1671+
}
16591672

16601673
void PApplet::bezier(float x1,float y1,float cx1,float cy1,float cx2,float cy2,float x2,float y2){
16611674
if(!doStroke)return;applyStroke();glLineWidth(strokeW);glBegin(GL_LINE_STRIP);

src/Processing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,9 @@ class PGraphics : public PImage {
974974
void bezier(float x1,float y1,float cx1,float cy1,float cx2,float cy2,float x2,float y2);
975975
void curve(float x0,float y0,float x1,float y1,float x2,float y2,float x3,float y3);
976976
void bezierVertex(float cx1,float cy1,float cx2,float cy2,float x,float y);
977+
void bezierVertex(float cx1,float cy1,float cz1,float cx2,float cy2,float cz2,float x,float y,float z);
977978
void curveVertex(float x, float y);
979+
void curveVertex(float x, float y, float z);
978980
void image(PImage* img, float x, float y);
979981
void image(PImage* img, float x, float y, float w, float h);
980982
void image(PImage* img, float dx1,float dy1,float dx2,float dy2,float sx1,float sy1,float sx2,float sy2);

0 commit comments

Comments
 (0)