Hello.
I still havent clear how does the camera() function work: in particular the xUp yUp zUp parameters and how do I make my camera roate along the Y-up axis in order to see how's my object.
ANYWAY:here's my program... it's pretty simple and is a very rough sketch of what I could end up with.
- It creates a series of segments in 3D
- Rotates the scene so it's posasible to understand the object drawn.
Please help me to improve the script as I will have to substitute the lines with complex polygons ! :-S
Code:
int[][] p = new int[5001][4];
int a = 0;
int[][] knot = new int[500][4];
int k = 1;
void setup() {
size(500,500,P3D);
calcP();
}
void draw()
{
//APPLY A TRANSFORMATION SUCH THAT THE SCENE IS 'CENTERED' (point[0,0,0] is at the middle of the window)
translate(width/2, height/2, 0);
//EVERYTIME THE draw() FUNCTION IS CALLED, ROTATES EVERYTHING BY AN INCREASING AMOUNT 'a'
rotateY(radians(a));
a++;
//CLEAR EVERYTHING
background(200);
/* Draw a yellow box at the center of the 'world'... useful only for debug
fill(255,255,0);
box(100);
/*
/* This part is to plot all the points present in the array p[][]
for(int i = 1; i< 4000; i++)
{
point(p[i][1], p[i][2], p[i][3]);
}
*/
//DRAWS A SHAPE MADE OF CONNECTED LINES WITH VERTICES CORRESPONDING TO THE KNOTS (knot[][])
beginShape(LINES);
for(int i = 1; i <= k-1; i++)
{
vertex(knot[i][1], knot[i][2], knot[i][3]);
vertex(knot[i+1][1], knot[i+1][2], knot[i+1][3]);
}
endShape();
}
void calcP()
{
int dirX, dirY, dirZ, sgmSteps, dirXold, dirYold, dirZold;
int posX, posY, posZ;
posX = posY = posZ = sgmSteps = dirX = dirY = dirZ = dirXold = dirYold = dirZold = 0;
for(int i = 1; i< 5000; i++) //Each loop calculates one point and puts the coordinates to an array with the points previously calculated
{
//WHEN THE SEGMENT HAS BEEN COMPLETED (sgmSteps == 0) CALCULATE A NEW KNOT WITH A DIFFERENT SET OF DIRECTIONS (X,Y,Z) AND SEGMENT LENGTH (steps)
if(sgmSteps == 0)
{
dirXold = dirX;
dirYold = dirY;
dirZold = dirZ;
sgmSteps = round(random(10,100));
while(dirX == dirXold && dirY == dirYold && dirZ == dirZold || dirX == -dirXold && dirY == -dirYold && dirZ == -dirZold)
{
dirX = round(pow(-1, round(random(1,2))));
dirY = round(pow(-1, round(random(1,2))));
dirZ = round(pow(-1, round(random(1,2))));
}
if(dirX == dirXold && dirY == dirYold && dirZ == dirZold || dirX == -dirXold && dirY == -dirYold && dirZ == -dirZold)
{
println("DUPLICATE");
}
println("-- NEW KNOT --");
println(dirX + " | " + dirY + " | " + dirZ);
knot[k][1] = posX;
knot[k][2] = posY;
knot[k][3] = posZ;
k++;
}
/////////////////////////////////////////////////////////////////////////////////
//NEW POINT POSITION
posX = posX + dirX;
posY = posY + dirY;
posZ = posZ + dirZ;
//SERIES OF CHECKINGS TO SEE IT THE NEW POINT GOES BEYOND THE SCREEN BOUNDRAIS
if(posX >= width/2 -1 | posX <= -width/2 +1)
{
dirX = -1 * dirX;
println("-- NEW KNOT --");
println(dirX + " | " + dirY + " | " + dirZ);
knot[k][1] = posX;
knot[k][2] = posY;
knot[k][3] = posZ;
k++;
}
if(posY >= height/2 -1| posY <= -height/2 +1)
{
dirY = -1 * dirY;
println("-- NEW KNOT --");
println(dirX + " | " + dirY + " | " + dirZ);
knot[k][1] = posX;
knot[k][2] = posY;
knot[k][3] = posZ;
k++;
}
if(posZ >= width/2 | posZ <= -width/2)
{
posZ = -1 * posZ;
println("-- NEW KNOT --");
println(dirX + " | " + dirY + " | " + dirZ);
knot[k][1] = posX;
knot[k][2] = posY;
knot[k][3] = posZ;
k++;
}
/////////////////////////////////////////////////////////////////////////////////
sgmSteps--; //decreases the length of the current segment because one more 'point' has been calculated
//ADDS THE POINT CALCULATED TO THE ARRAY CONTAING ALL THE POINTS (p[][])
p[i][1] = posX;
p[i][2] = posY;
p[i][3] = posZ;
}
}