Hello,
I'm a bit of a noob with 3d so any tip will be helpful.
I'm trying to make extrude a path.
So far I started with the Vertices examples that comes with Processing: 3D > Form > Vertices.
My code looks like this:
Code:CShape test;
void setup() {
size(500, 500, P3D);
Vector points = new Vector();
points.add(new PVector(0,0,0));
points.add(new PVector(-50,50,0));
points.add(new PVector(50,100,0));
points.add(new PVector(100,150,0));
points.add(new PVector(120,170,0));
points.add(new PVector(110,180,0));
test = new CShape(30,30,points,3);
}
void draw() {
background(0);
lights();
translate(width / 2, height / 2);
rotateY(map(mouseX, 0, width, 0, PI));
rotateX(map(mouseY, 0, height, 0, PI));
noStroke();
fill(255, 255, 255);
translate(0, -40, 0);
test.draw();
}
import java.util.Vector;
class CShape{
float topRadius,bottomRadius,tall,sides;
int pointsNum;
Vector points;
CShape(){}
CShape(float topRadius, float bottomRadius, Vector points, int sides) {
this.topRadius = topRadius;
this.bottomRadius = bottomRadius;
this.points = points;
this.pointsNum = points.size();
this.sides = sides;
}
void draw() {
if(pointsNum >= 2){
float angle = 0;
float angleIncrement = TWO_PI / sides;
// If it is not a cone, draw the circular top cap
if (topRadius != 0) {
angle = 0;
beginShape(TRIANGLE_FAN);
PVector v0 = PVector.add((PVector)(points.get(0)),new PVector(0,0,0));
PVector v1 = PVector.add((PVector)(points.get(1)),new PVector(0,0,0));
//PVector v0 = new PVector(((PVector)points.get(0)).x,((PVector)points.get(0)).y,((PVector)points.get(0)).z);
//PVector v1 = new PVector(((PVector)points.get(1)).x,((PVector)points.get(1)).y,((PVector)points.get(1)).z);
PVector v0Diff = new PVector(v1.x - v0.x,v1.y - v0.y,v1.z - v0.z);
v0Diff.normalize();
// Center point
PVector v0AngleX = new PVector(v0Diff.z,v0Diff.y,-v0Diff.x);
PVector v0AngleZ = new PVector(v0Diff.x,v0Diff.y,v0Diff.z);
PVector V0AngleY = v0AngleX.cross(v0AngleZ);
vertex(v0.x, v0.y, v0.z);
for (int i = 0; i < sides + 1; i++) {
vertex(v0.x + v0Diff.x + topRadius * cos(angle), v0.y, v0.z +topRadius * sin(angle));
angle += angleIncrement;
}
endShape();
}
for(int p = 1; p < pointsNum ; p++){
beginShape(TRIANGLE_STRIP);
for (int i = 0; i < sides + 1; ++i) {
PVector previous = PVector.add((PVector)(points.get(p-1)),new PVector(0,0,0));
PVector current = PVector.add((PVector)(points.get(p)),new PVector(0,0,0));
vertex(previous.x + topRadius*cos(angle), previous.y,previous.z + topRadius*sin(angle));
vertex(current.x + bottomRadius*cos(angle), current.y,current.z + bottomRadius*sin(angle));
angle += angleIncrement;
}
endShape();
}
// If it is not a cone, draw the circular bottom cap
if (bottomRadius != 0) {
angle = 0;
PVector last = PVector.add((PVector)(points.get(pointsNum-1)),new PVector(0,0,0));
beginShape(TRIANGLE_FAN);
// Center point
vertex(last.x, last.y, last.z);
for (int i = 0; i < sides + 1; i++) {
vertex(last.x + bottomRadius * cos(angle), last.y, last.z + bottomRadius * sin(angle));
angle += angleIncrement;
}
endShape();
}
}else{
println("Not enough points " + points.size());
}
}
}
How do I make the joints turn at the right angle ?