Sunday 25 April 2010

The Visual Element is Complete - Part 2

Continuing on from the last post here is some more code from our Processing Sketch and what it all does.

for (int r= 0; r < count; r++){
if((Fdetect[r] < metricTime)&&(metricTime < Fdetect[r]+3000)){
active[r] = "true";
}else{
active[r] = "false";
}

This checks to see if a particular device had been detected yet.

for(int z = 0; z < count;z++){
if(active[z] == "true"){
//BALL - WALL COLLISIONS
if((posX[z] < rad)||(posX[z] > width -rad)){
speedX[z] = -speedX[z] *loss;
}
if((posY[z] < rad)||(posY[z] > height)){
speedY[z] = -speedY[z] *loss;
}
if(posZ[z] < -10000 +rad){
speedZ[z] = -speedZ[z] *loss;
}
//balls that go beyond the camera are deactivated
if(posZ[z] > 1000){
active[z] = "false";
}

//BALL - BALL COLLISIONS
for(int others = 0; others < count;others++){
if(others != z){
if(ballSize > dist(posX[z],posY[z],posZ[z],posX[others],posY[others],posZ[others])){
TspeedX = speedY[z] *loss;
TspeedY = speedX[z] *loss;
TspeedZ = speedZ[z] *loss;
speedY[z] = speedY[others];
speedX[z] = speedX[others];
speedZ[z] = speedZ[others];
speedY[others] = TspeedY *loss;
speedX[others] = TspeedX *loss;
speedZ[others] = TspeedZ *loss;
}
}
}

//BALL - FLOOR COLLISIONS

speedY[z] = speedY[z] - gravity; //gravity

speedZ[z] = speedZ[z] - 0.2;

posX[z] = posX[z] - speedX[z] *drag;
posY[z] = posY[z] - speedY[z] *drag;
posZ[z] = posZ[z] - speedZ[z] *drag;


pushMatrix();
noStroke();
translate(posX[z],posY[z],posZ[z]);
fill(50,50,200);
sphere(ballSize);
sphereDetail(10);
popMatrix();
}
}


And all of this code controls the bouncing balls. It detects if they bounce of the sides, the ground or eachother and then acts accordingly.

PImage a = loadImage("stonehouse.jpg");
beginShape();
texture(a);
translate(500+width/2.0,650+height/2.0, -100);
fill(255);
scale(300);
vertex(-20, -20, -30, 0, 0);
vertex( 20, -20, -30, 1, 0);
vertex( 20, 20, -30, 1, 1);
vertex(-20, 20, -30, 0, 1);
endShape();
}


And finally this code is just to display the image of the street behind it all. Thats all folks the sketch has been complete.

No comments:

Post a Comment