Leaving geometry from previous frames.
in
Programming Questions
•
1 year ago
Hello,
I am working on scheme that consist of:
1. a bunch of squares that move according to mouse position.
2. every new frame I am adding value to z axis, (the line shows that z axis value is changing).
The main problem I have:
1. I want to have geometry that was created in previous frames.
For example processing has just generated geometry in frame 3, but the geometry from previous frame 2 and frame 1 is deleted by creating background in draw function. I want to have geometry from frames 1 and 2.
Of course, I can just delete background function. But as long as I rotate camera images are draw on each other but it has nothing to do with geometry.
2. It would be nice to loft them, if possible. I think this is similar to extruding cellular automata, but I do not know the method...
Please heeeelp me:)
My sketch:
Main tab:
//import processing.opengl.*;
Mover[] movers = new Mover[5];
void setup() {
size(640, 360, P3D);
noStroke();
for (int i = 0; i < movers.length; i++) {
movers[i] = new Mover();
}
}
void draw() {
// rect(0,0,width,height);
background(255);
lights();
//background(204);
float cameraY = height/2.0;
float fov = mouseX/float(width) * PI/2;
float cameraZ = cameraY / tan(fov / 2.0);
float aspect = float(width)/float(height);
if (mousePressed) {
aspect = aspect / 2.0;
}
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
translate(width/2+30, height/2, 0);
rotateX(-PI/6);
rotateY(PI/3 + mouseY/float(height) * PI);
// box(45);
translate(0, 0, -50);
// box(30);
for (int i = 0; i < movers.length; i++) {
movers[i].update();
movers[i].display();
}
}
void mouse() {
if (mousePressed) {
background(255);
}
}
CLASS OF THE MOVER:
/**
* Acceleration with Vectors
* by Daniel Shiffman.
*
* Demonstration of the basics of motion with vector.
* A "Mover" object stores location, velocity, and acceleration as vectors
* The motion is controlled by affecting the acceleration (in this case towards the mouse)
*/
class Mover {
// The Mover tracks location, velocity, and acceleration
PVector location;
PVector velocity;
PVector acceleration;
// The Mover's maximum speed
float topspeed;
float a;
Mover() {
// Start in the center
location = new PVector(random(width),random(height));
velocity = new PVector(0,0);
topspeed = 5;
}
void update() {
// Compute a vector that points from location to mouse
PVector mouse = new PVector(mouseX,mouseY);
PVector acceleration = PVector.sub(mouse,location);
// Set magnitude of acceleration
//acceleration.setMag(0.2);
acceleration.normalize();
acceleration.mult(0.2);
// Velocity changes according to acceleration
velocity.add(acceleration);
// Limit the velocity by topspeed
velocity.limit(topspeed);
// Location changes by velocity
location.add(velocity);
// float z = 0;
//z = z + 10;
// translate(location.x,location.y,z);
a = a + 1;
// translate(0,0,a);
}
void display() {
stroke(0);
strokeWeight(2);
fill(127,200);
a = a + 1;
//ellipse(location.x,location.y,48,48);
stroke(0,a);
line(location.x, location.y, 0,location.x, location.y, a);
beginShape();
vertex(location.x,location.y, a);
vertex(location.x+48,location.y, a);
vertex(location.x+48,location.y+48, a);
vertex(location.x,location.y+48, a);
// line(location.x,location.y, a,location.x+48,location.y+0, a );
// line(location.x+48,location.y, a,location.x+48,location.y+48, a );
// line(location.x,location.y+48, a,location.x+48,location.y+48, a );
// line(location.x,location.y+48, a,location.x,location.y, a );
endShape(CLOSE);
}
}
1