|
Author |
Topic: count forwards then backwards then... (Read 1941 times) |
|
st33d
|
count forwards then backwards then...
« on: Mar 28th, 2005, 11:55pm » |
|
I've been picking apart Fry's code for a hypercube. http://acg.media.mit.edu/people/fry/atmosphere/ndim/ I'm having a lot of trouble sifting out the extraneous functions that I don't understand so I've decided to work from scratch but I've grasped the value of setting up a corner seed array and that's made the job very easy. I've also figured out the rotation for the individual axis of each cube (just push() and pop()). I'm now working on linking multiple cubes with lines and so on but there remains the matter of hyperspace rotation. All that really is is distancing the two cubes apart. But here's what I can't figure out: How do I apply a scale that counts up to a value then back down to zero, then back up again? Modulo won't work because they'll slide apart and snap shut. Any ideas? Code: float seedCorn[][] ={{-1, 1,-1},{ 1, 1,-1}, { 1, 1, 1},{-1, 1, 1}, {-1,-1,-1},{ 1,-1,-1}, { 1,-1, 1},{-1,-1, 1}}; int mag = 50; float w,h,theta; float [][] corn; boolean rotation = false; void setup(){ size(400,400); w = PI/width; h = PI/height; theta = 0; corn = new float[seedCorn.length][3]; for(int i = 0; i < seedCorn.length; i++){ for(int ii = 0; ii < 3; ii++){ corn[i][ii] = seedCorn[i][ii]*mag; } } } void loop(){ background(255); translate(200,200); rotateX(-mouseY*w); rotateY(mouseX*h); slapCube(-25,-25,-25); slapCube(25,25,25); linkCube(25,25,25,-25,-25,-25); if(rotation){ //how do I change this individual axis spin into a sliding apart and together function? theta = (theta+0.01)%TWO_PI; } } void mousePressed(){ rotation = !rotation; } void slapCube(float x, float y, float z){ push(); translate(x,y,z); rotateZ(theta); for(int i = 0; i < corn.length; i++){ strokeWeight(4); point(corn[i][0],corn[i][1],corn[i][2]); } for(int i = 0; i < 4; i++){ strokeWeight(1); /* line(corn[i][0]+x,corn[i][1]+y,corn[i][2]+z,corn[(i+1)%4][0]+x,corn[(i+1)%4][1]+y,corn[(i+1)%4][2]+z); line(corn[i+4][0]+x,corn[i+4][1]+y,corn[i+4][2]+z,corn[((i+1)%4)+4][0]+x,corn[((i+1)%4)+4][1]+y,corn[((i+1)%4)+4][2]+z); line(corn[i][0]+x,corn[i][1]+y,corn[i][2]+z,corn[i+4][0]+x,corn[i+4][1]+y,corn[i+4][2]+z); */ line(corn[i][0],corn[i][1],corn[i][2],corn[(i+1)%4][0],corn[(i+1)%4][1],corn[(i+1)%4][2]); line(corn[i+4][0],corn[i+4][1],corn[i+4][2],corn[((i+1)%4)+4][0],corn[((i+1)%4)+4][1],corn[((i+1)%4)+4][2]); line(corn[i][0],corn[i][1],corn[i][2],corn[i+4][0],corn[i+4][1],corn[i+4][2]); } pop(); } void linkCube(float x1, float y1, float z1, float x2, float y2, float z2){ push(); rotateZ(theta); for(int i = 0; i < corn.length; i++){ line(corn[i][0]+x1,corn[i][1]+y1,corn[i][2]+z1,corn[i][0]+x2,corn[i][1]+y2,corn[i][2]+z2); } pop(); } void rotatumX(float trans){ for(int i = 0; i < corn.length; i++){ corn[i][0] *= cos(trans); } } |
| Okay. I can't seem to get the two cubes linked and spin them either. It doesn't look like I can get away with using rotateX,Y,Z.
|
« Last Edit: Mar 29th, 2005, 12:16am by st33d » |
|
I could murder a pint.
|
|
|
st33d
|
Re: count forwards then backwards then...
« Reply #1 on: Apr 15th, 2005, 9:30am » |
|
Still haven't got a clue how quarternions work (had my dad trying to explain it to me, almost there but won't be able to understand it without applying it). I understand that I need to use them for this type of rotation. I did however find a count backwards and forwards solution, so in case anyone else asks: Code: int s = 0; void setup(){ noStroke(); ellipseMode(CENTER_DIAMETER); } void loop(){ background(150); s = (s+1)%100; int ns = abs(s-50); ellipse(50,50,ns,ns); } |
|
|
I could murder a pint.
|
|
|
|