g.endShape();
}
public static void flatCylinder(float r1, float r2, float len, Transform myTransform, PGraphics g) {
PMatrix3D worldMatrix = new PMatrix3D();
float matrixWorldScale = (float) (GLOBAL.getZOOM()*70.0f);//Where does this come from?
List points = new ArrayList();
//g.beginShape();
g.pushMatrix();
g.translate(0, -len/2.0f, 0);
float screenX1 = g.screenX(0,0,0);
float screenY1 = g.screenY(0,0,0);
float screenZ1 = g.screenZ(0,0,0);
g.popMatrix();
g.pushMatrix();
g.translate(0, len/2.0f, 0);
float screenX2 = g.screenX(0,0,0);
float screenY2 = g.screenY(0,0,0);
float screenZ2 = g.screenZ(0,0,0);
g.popMatrix();
float atan = (float)Math.atan((screenY1-screenY2)/(screenX1-screenX2));
g.pushMatrix();
g.translate(0, -len/2.0f-0.1f, 0);
worldMatrix = new PMatrix3D();
g.getMatrix(worldMatrix);
worldMatrix.m00 = matrixWorldScale;worldMatrix.m01 = 0;worldMatrix.m02 = 0;
worldMatrix.m10 = 0;worldMatrix.m11 = matrixWorldScale;worldMatrix.m12 = 0;
g.setMatrix(worldMatrix);
g.rotate(atan);
float worldX1 = g.screenX(0,0,0);
float worldY1 = g.screenY(0,0,0);
float worldZ1 = g.screenZ(0,0,0);
g.popMatrix();
g.pushMatrix();
g.translate(0, len/2.0f+0.1f, 0);
worldMatrix = new PMatrix3D();
g.getMatrix(worldMatrix);
worldMatrix.m00 = matrixWorldScale;worldMatrix.m01 = 0;worldMatrix.m02 = 0;
worldMatrix.m10 = 0;worldMatrix.m11 = matrixWorldScale;worldMatrix.m12 = 0;
g.setMatrix(worldMatrix);
g.rotate(atan);
float worldX2 = g.screenX(0,0,0);
float worldY2 = g.screenY(0,0,0);
float worldZ2 = g.screenZ(0,0,0);
g.popMatrix();
float worldDist =(float) Math.sqrt(Math.pow(worldX2-worldX1,2) + Math.pow(worldY2-worldY1,2)+ Math.pow(worldZ2-worldZ1,2) )/matrixWorldScale;
if(screenX1 < screenX2)
atan -= (float)(Math.PI/2);
else
atan += (float)(Math.PI/2);
//side curve
g.pushMatrix();
g.translate(0, -len/2.0f-0.1f, 0);
worldMatrix = new PMatrix3D();
g.getMatrix(worldMatrix);
//billboard matrix
worldMatrix.m00 = matrixWorldScale;worldMatrix.m01 = 0;worldMatrix.m02 = 0;
worldMatrix.m10 = 0;worldMatrix.m11 = matrixWorldScale;worldMatrix.m12 = 0;
g.setMatrix(worldMatrix);
g.rotate(atan);
g.noStroke();
g.fill(228);
g.beginShape();
g.vertex(-r1/2, 0,-0.1f);
g.vertex( -r2/2, worldDist,-0.1f);
g.vertex(r2/2, worldDist,-0.1f);
g.vertex(r1/2, 0,-0.1f);
g.endShape(PApplet.CLOSE);
g.noFill();
g.stroke(0);
g.strokeWeight(2);
g.line(-r1/2, 0, -r2/2, worldDist);
g.line(r1/2,0, r2/2, worldDist);
g.popMatrix();
//Top curve
g.pushMatrix();
g.translate(0, -len/2.0f, 0);
worldMatrix = new PMatrix3D();
g.getMatrix(worldMatrix);
//billboard matrix
worldMatrix.m00 = matrixWorldScale;worldMatrix.m01 = 0;worldMatrix.m02 = 0;
worldMatrix.m10 = 0;worldMatrix.m11 = matrixWorldScale;worldMatrix.m12 = 0;
//worldMatrix.m20 = 0;worldMatrix.m21 = 0;worldMatrix.m22 = worldMatrix.m22;
g.setMatrix(worldMatrix);
g.rotate(atan);
g.noStroke();
g.fill(228);
g.beginShape();
for(float a=(float)(float) (Math.PI+(Math.PI/2)) ; a >= (float) (Math.PI/2); a -=0.1f) {
g.vertex((float)(Math.sin(a)*(r1/2))+0,(float)(Math.cos(a)*(r1/2))+0,-0.1f);
}
g.endShape();
g.noFill();
g.stroke(0);
g.strokeWeight(2);//top curve weight
g.beginShape();
for(float a=(float)(float) (Math.PI+(Math.PI/2)) ; a >= (float) (Math.PI/2); a -=0.1f) {
g.vertex((float)(Math.sin(a)*(r1/2))+0,(float)(Math.cos(a)*(r1/2))+0);
points.add(new PVector(g.modelX((float)(Math.sin(a)*(r1/2))+0,(float)(Math.cos(a)*(r1/2))+0,0),
g.modelY((float)(Math.sin(a)*(r1/2))+0,(float)(Math.cos(a)*(r1/2))+0,0),
g.modelZ((float)(Math.sin(a)*(r1/2))+0,(float)(Math.cos(a)*(r1/2))+0,0)));
}
g.endShape();
g.strokeWeight(1);
g.stroke(255,0,0);
//g.ellipse(0, 0, r1,r1);
g.popMatrix();
//bottom curve
g.pushMatrix();
g.translate(0, len/2.0f, 0);
worldMatrix = new PMatrix3D();
g.getMatrix(worldMatrix);
//billboard matrix
worldMatrix.m00 = matrixWorldScale;worldMatrix.m01 = 0;worldMatrix.m02 = 0;
worldMatrix.m10 = 0;worldMatrix.m11 = matrixWorldScale;worldMatrix.m12 = 0;
//worldMatrix.m20 = 0;worldMatrix.m21 = 0;worldMatrix.m22 = worldMatrix.m22;