// import processing.opengl.*; // library for easy manipulation of cameras // The Obsessive Camera Direction // by Kristian Linn Damkjer // !! you need to download it to run this code !! // find link at http://www.processing.org/reference/libraries/index.html import damkjer.ocd.*; // create camera from OCD library Camera camera1; // max nodes, 25*25 for example int nodeAmount = 625; // nodes array: x,y,z,force float[][] nodes = new float[int(nodeAmount)][4]; // rotationZ float[] rotationY = new float[int(nodeAmount)]; // rotationZ Target float[] rotationTargetY = new float[int(nodeAmount)]; // counter for timing int timingCounter = 0; int timingCounterSpeed = 1; // String displayAnimation = "noise"; // image loading setup PImage a; PImage b; int imageSize = 25; int[][] aPixels; int currentImage = 1; int maxImage = 20; String animation = "count"; int frameRate = 1; // perlin noise setup int noiseDepth = 1; // pong setup int pongStageX = 6*25; int pongStageZ = 6*25; float ballX = 50; // ball X coordinate float ballZ = 50; // ball Y coordinate float ballSpeed = 5; // ball Speed value float ballDirection = 145; // direction of the ball float ballSpeedX = sin(radians(ballDirection)); float ballSpeedZ = cos(radians(ballDirection)); float ballSize = 20; // racket sizes float racketSizeWidth = 30; float racketSizeDepth = 3; float racketSizeHeigth = 5; // 4 side rackets float racket1X = 60; float racket1Z = 155; float racket2X = 60; float racket2Z = -5; float racket3X = 0; float racket3Z = 150; float racket4X = 150; float racket4Z = 150; // array for pixelating pong results int pongFieldSize = 25; float pongFieldPixels[] = new float[pongFieldSize*pongFieldSize]; // setup *********************************************************************************** void setup() { size(800, 500, P3D); colorMode(HSB, 100); framerate(15); generateNodes(); // smooth(); // little buggy camera constructor from OCD library camera1 = new Camera(this, 20.0, -50.0, 170.0, 100.0, 40.0, 70.0, 0.0, 1.0, 0.0, radians(PI/3), (width/height), 1.0, 1000.0); camera1.zoom(radians(130) / 1.7); b = loadImage("background.jpg"); } // main method *********************************************************************************** void draw() { background(20,0,15); // background(b); camera1.feed(); //lights(); drawNodes(); iterateRotation(); keyboardListener(); cameraNavigation(); // pong pongBounceBall(); } // generate data *********************************************************************************** void generateNodes() { float x = 0; float y = 0; float z = 0; int j=0; for (int i=0; i24) { j = 0; x = 0; z += 6; } float humanizer = (random(10)-5)/20; x += 6+humanizer; z += humanizer; nodes[i][0] = x; nodes[i][1] = y; nodes[i][2] = z; // and force nodes[i][3] = 0; } } // Calculate forces ********************************************************************************************* void iterateRotation(){ for(int i=0; i= pongStageX || ballX <= 0){ ballSpeedX = -ballSpeedX; } else if (ballZ <= 0){ ballSpeedZ = -ballSpeedZ; } // reset game after it leaves if (ballZ >= pongStageZ+100){ ballX = 50; // ball X coordinate ballZ = 50; // ball Y coordinate ballSpeed = 5; // ball Speed value ballDirection = random(360); // direction of the ball ballSpeedX = sin(radians(ballDirection)); ballSpeedZ = cos(radians(ballDirection)); } // check for racket if (ballX >= racket1X - (racketSizeWidth*1.5) && ballX <= racket1X && ballZ >= racket1Z - (ballSize / 2) && ballZ <= racket1Z){ ballSpeedZ = -ballSpeedZ; } // move ball ballX += ballSpeedX*ballSpeed; ballZ += ballSpeedZ*ballSpeed; // place results in array for (int i = 0; i < pongFieldSize; i++){ for (int j = 0; j < pongFieldSize; j++){ int pixelPos = i + (pongFieldSize * j); float pixelSize = pongStageX / pongFieldSize; if ( abs( (i * pixelSize) - ballX) < ballSize/2 && abs(j * pixelSize - ballZ) < ballSize/2){ //pongFieldPixels[pixelPos] = 1; nodes[pixelPos][3] = 270; } else { //pongFieldPixels[pixelPos] = 0; nodes[pixelPos][3] = 0; } // draw walls // pongFieldPixels[i] = 1; } } // listen for racket moving if(keyPressed) { if(key == 'q' || key == 'Q') { racket1X -= 4; } if(key == 'w' || key == 'W') { racket1X += 4; } } // draw computer players pushMatrix(); translate(racket2X+racketSizeWidth/2, 0, racket2Z); // box(racketSizeWidth, racketSizeHeigth, racketSizeDepth); // draw guys translate(racketSizeWidth/2+2, -5, 0); for (int men=0; men<6; men++){ noStroke(); translate(-5-(random(1)-0.5)/2,0,(random(1)-0.5)/2); fill(5,50,100); sphere(1); translate(0,0.2,-0.2); fill(1,10,1); sphere(1); translate(0,-0.2,0.2); translate(0,7,0); fill(85,100,100); //stroke(0,0,0); // body box(3,10,1); // hands fill(5,50,100); translate(-2,-3,0); rotateZ(radians(10)); box(0.5,4,0.5); rotateZ(radians(-20)); translate(4,1,0); box(0.5,4,0.5); rotateZ(radians(10)); translate(-2,3,0); translate(0,-7,0); } popMatrix(); noFill(); stroke(0,0,100); pushMatrix(); translate(racket3X, 0, racket3Z-racketSizeWidth/2); box(racketSizeDepth, racketSizeHeigth, racketSizeWidth); popMatrix(); pushMatrix(); translate(racket4X, 0, racket4Z-racketSizeWidth/2); box(racketSizeDepth, racketSizeHeigth, racketSizeWidth); popMatrix(); // draw human player pushMatrix(); // fill(100,0,100); translate(racket1X-racketSizeWidth/2, 0, racket1Z); // box(racketSizeWidth, racketSizeHeigth, racketSizeDepth); // draw guys translate(racketSizeWidth/2+2, -5, 0); for (int men=0; men<6; men++){ noStroke(); translate(-5-(random(1)-0.5)/2,0,(random(1)-0.5)/2); fill(5,50,100); sphere(1); translate(0,-0.2,0.2); fill(1,10,1); sphere(1); translate(0,0.2,-0.2); translate(0,7,0); fill(65,50,70); //stroke(0,0,0); // body box(3,10,1); // hands fill(5,50,100); translate(-2,-3,0); rotateZ(radians(10)); box(0.5,4,0.5); rotateZ(radians(-20)); translate(4,1,0); box(0.5,4,0.5); rotateZ(radians(10)); translate(-2,3,0); translate(0,-7,0); } popMatrix(); } void randomForces(){ for (int i=0; i 9){ zeros = "00"; } if (currentImage > 99){ zeros = "0"; } a = loadImage(animation+zeros+currentImage+".gif"); for(int i=0; i maxImage){ currentImage = 1; if (animation == "count"){ animation = "ripple"; } else if (animation == "ripple"){ animation = "rotation"; } else if (animation == "rotation"){ animation = "hand"; frameRate = 5; maxImage = 128; } else if (animation == "hand"){ animation = "count"; frameRate = 1; maxImage = 20; } } } void displayMyImage(){ float rr, gg, bb, tt; for(int i=0; i0){ nodes[(i*imageSize)+j+fix][3] = tt-50; } } } } // perlin noise void displayPerlinNoise(){ float noiseScale=0.03; noiseDepth += 1; for(int i=0; i0){ nodes[(i*imageSize)+j][3] = noise(i*noiseScale, j*noiseScale, noiseDepth*noiseScale*2)*3000; } } } } // keyboardListener *************************************************************************************************************** void keyboardListener(){ if(keyPressed) { if(key == 'r' || key == 'R') { randomForces(); } if(key == 's' || key == 'S') { resetForces(); } if(key == 'i' || key == 'I') { loadMyImage(); displayMyImage(); } // looping content switches if(key == 'a' || key == 'A') { displayAnimation = "images"; timingCounterSpeed = 5; } if(key == 'n' || key == 'N') { displayAnimation = "noise"; timingCounterSpeed = 1; } } } // 3d navigation *************************************************************************************************************** void cameraNavigation() { if (!mousePressed){ // } else if (mouseButton == LEFT) { camera1.circle(radians(mouseX - pmouseX) / -2.0); camera1.arc(radians(mouseY - pmouseY) / -2.0); } else if (mouseButton == RIGHT) { camera1.zoom(radians(mouseY - pmouseY) / 2.0); } else if (mouseButton == CENTER) { camera1.look(radians(mouseX - pmouseX) / 6.0, radians(mouseY - pmouseY) / 2.0); } }