I\'m trying to extrude a path in 3d. Nothing fancy yet, just following some points and using a regular polygon for \'tubing\'. I\'m using Processing for now to quickly prototype
Assuming your shape has a normal vector S. In your example S would be (0,0,1), because your shape is flat in xy. You can use the cross product between the current path vector V (normalized) and S to obtain the rotation axis vector R. You need to rotate your shape around R. The angle of rotation can be obtained from the dot product between S and V. So:
R = S x V
a = arc cos(S . V)
Now you can setup a rotation matrix with R and a and rotate the shape by it.
You can use glRotate(...) to rotate the current matrix on the stack, but this can't be done between glBegin() and glEnd(). So you have to do the matrix multiplication by yourself or with a library.
Edit: After a short look at the library you are using, you should be able to setup the rotation matrix with
PVector s = new PVector(0,0,1); // is already normalized (meaning is has length 1)
PVector cn;
current.normalize(cn);
PVector r = s.cross(cn);
float a = acos(s.dot(cn));
PMatrix rot = new PMatrix(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
rot.rotate(a, r.x, r.y, r.z);
and now multiply each element of your shape with rot and translate it by your current path vector:
PVector rotVec;
rot.mult((PVector)shape[i], rotVec);
rotVec.add(current);