diff --git a/Project/Game/Game.pde b/Project/Game/Game.pde index 5240e6c..ef1af10 100644 --- a/Project/Game/Game.pde +++ b/Project/Game/Game.pde @@ -1,222 +1,222 @@ import java.text.DecimalFormat; -Mover mover; //The ball +Mover mover; //The ball Cylinder cyl; //The basis of all cylinders PImage img; PShape globe; PShape robot; //The vilain float depth = 2000; //the depth from the box //Plate size float plate_w=1000; float plate_t=plate_w/20; float x_coord, y_coord; float mX, mY; //mouse X position float xOnPlane, yOnPlane; //coordinate on 2D on the box float rz, rx; //rotate x and rotate z float cameraHeight; float speed=10; float radius=plate_t*4/5; DecimalFormat f = new DecimalFormat("#0.0"); DecimalFormat f2 = new DecimalFormat("#0"); boolean shiftMod=false; ParticleSystem partSys=null; long previousFrame=0; float timeIntervalParticle=0.5;//seconds PGraphics gameSurface; PGraphics statSurface; PGraphics topView; void settings() { size(displayWidth, displayHeight, P3D); x_coord=width/2; y_coord=height/2; } void setup() { mover = new Mover(); cyl=new Cylinder(); img = loadImage("earth.jpg"); globe = createShape(SPHERE, radius); globe.setStroke(false); globe.setTexture(img); img = loadImage("robotnik.png"); robot = loadShape("robotnik.obj"); robot.setTexture(img); gameSurface=createGraphics(width, height-300, P3D); topView=createGraphics(width, 300, P2D); statSurface=createGraphics(width, 100, P2D); } void draw() { background(200); drawGame(); image(gameSurface, 0, 0); drawTopView(); image(topView, 0, height-300); drawStat(); image(statSurface, 0, 0); } void drawTopView() { topView.beginDraw(); topView.background(200); topView.fill(0, 150, 150); topView.rect(10, 0, 300, 300); topView.fill(255, 255, 255); float topViewCylRad=map(cyl.cylinderBaseSize, 0, plate_w/2, 0, 300); if (partSys!=null) { for (PVector pv : partSys.cylinders) { float topViewCylX=map(pv.x, -plate_w/2, plate_w/2, 10, 310); float topViewCylY=map(pv.y, -plate_w/2, plate_w/2, 10, 310); topView.ellipse(topViewCylX, topViewCylY, topViewCylRad, topViewCylRad); } if (partSys.cylinders.contains(partSys.mainCyl)) { topView.fill(255, 0, 0); float topViewCylX=map(partSys.mainCyl.x, -plate_w/2, plate_w/2, 10, 310); float topViewCylY=map(partSys.mainCyl.y, -plate_w/2, plate_w/2, 10, 310); topView.ellipse(topViewCylX, topViewCylY, topViewCylRad, topViewCylRad); } } topView.fill(0,0,255); float topViewBallRad=map(radius, 0, plate_w/2, 0, 300); float topViewBallX=map(mover.location.x, -plate_w/2, plate_w/2, 10, 310); float topViewBallY=map(mover.location.y, -plate_w/2, plate_w/2, 10, 310); topView.ellipse(topViewBallX, topViewBallY, topViewBallRad, topViewBallRad); topView.endDraw(); } void drawStat() { statSurface.beginDraw(); statSurface.background(0, 0, 0, 0); statSurface.fill(0); statSurface.textSize(25); statSurface.text("Rotation X : "+f.format(rx/Math.PI*180)+"° Rotation Z : "+f.format(rz/Math.PI*180)+"° speed: "+f.format(speed/10), 5, 25); statSurface.text("Ball location : ("+f2.format(mover.location.x)+","+f2.format(mover.location.y)+")", 5, 50); statSurface.text("Ball velocity : ("+f2.format(mover.velocity.x)+","+f2.format(mover.velocity.y)+")", 5, 75); statSurface.endDraw(); } void drawGame() { gameSurface.beginDraw(); gameSurface.background(100, 0, 0); gameSurface.directionalLight(50, 100, 125, 0, 1, 0); gameSurface.ambientLight(102, 102, 102); gameSurface.pointLight(150, 150, 150, 0, -200, 0); if (!shiftMod) { mover.update(); mover.checkEdges(); if (partSys!=null) { mover.checkCylinderCollision(partSys.cylinders, radius); } rz = map(x_coord, 0, width, -PI/3, PI/3); rx = map(y_coord, 0, height, -PI/3, PI/3); cameraHeight=400; } else { rz=0; rx=-PI/2; cameraHeight=0; } gameSurface.pushMatrix(); gameSurface.camera(0, -cameraHeight, depth, 0, 0, 0, 0, 1, 0); gameSurface.rotateZ(rz); gameSurface.rotateX(rx); gameSurface.shininess(100); gameSurface.box(plate_w, plate_t, plate_w); //particles if (partSys!=null) { if (frameCount-previousFrame>=timeIntervalParticle*frameRate && !shiftMod) { timeIntervalParticle=random(0.2, 1.2); previousFrame=frameCount; partSys.addParticle(); } partSys.run(-(plate_t/2), PI/2); } if (shiftMod) { float wMappedX=2*plate_w; float wMappedY=1.1*plate_w; xOnPlane=map(mouseX, 0, width, -wMappedX, wMappedX); yOnPlane=map(mouseY, 0, height, -wMappedY, wMappedY); cyl.draw(xOnPlane, yOnPlane, -(plate_t/2), PI/2); } gameSurface.translate(mover.getX(), -(plate_t/2+radius), mover.getY()); gameSurface.fill(255, 100, 100); gameSurface.rotateX(mover.getRotX()); gameSurface.rotateZ(mover.getRotZ()); gameSurface.shape(globe); gameSurface.popMatrix(); //Draw the text gameSurface.pushMatrix(); /*gameSurface.fill(0); gameSurface.textSize(15); gameSurface.text("Rotation X : "+f.format(rx/Math.PI*180)+"° Rotation Z : "+f.format(rz/Math.PI*180)+"° speed: "+f.format(speed/10), 5, 15); */ if (shiftMod) { gameSurface.textSize(50); gameSurface.text("[EDIT MOD ON]", 50, 500); } gameSurface.fill(255); gameSurface.popMatrix(); gameSurface.endDraw(); } void mouseWheel(MouseEvent event) { float e = event.getCount(); if (e<0) { speed-=speed<=2?0:1; } else { speed+=speed>=15?0:1; } } void mouseDragged() { if (!shiftMod) { float d=-(mX-mouseX)*speed/10; x_coord=x_coord+d<=0?0:x_coord+d>=width?width:x_coord+d; mX=mouseX; d=(mY-mouseY)*speed/10; y_coord=y_coord+d<=0?0:y_coord+d>=height?height:y_coord+d; mY=mouseY; } } void mousePressed() { mX = mouseX; mY = mouseY; if (shiftMod && -plate_w/2 2*radius || Math.abs(yOnPlane-mover.location.y) > 2*radius)) { partSys=new ParticleSystem(new PVector(xOnPlane, yOnPlane), mover, radius); } } void keyPressed() { if (keyCode == SHIFT) { shiftMod=true; } } void keyReleased() { if (keyCode == SHIFT) { shiftMod=false; } } diff --git a/Project/Game/Game.pde b/Project/Game/Game7245377161224401861.autosave similarity index 75% copy from Project/Game/Game.pde copy to Project/Game/Game7245377161224401861.autosave index 5240e6c..8b21d3d 100644 --- a/Project/Game/Game.pde +++ b/Project/Game/Game7245377161224401861.autosave @@ -1,222 +1,204 @@ import java.text.DecimalFormat; Mover mover; //The ball Cylinder cyl; //The basis of all cylinders PImage img; PShape globe; PShape robot; //The vilain float depth = 2000; //the depth from the box - +int score; +int scoreMalus = -1; //Plate size float plate_w=1000; float plate_t=plate_w/20; float x_coord, y_coord; float mX, mY; //mouse X position float xOnPlane, yOnPlane; //coordinate on 2D on the box float rz, rx; //rotate x and rotate z float cameraHeight; float speed=10; float radius=plate_t*4/5; DecimalFormat f = new DecimalFormat("#0.0"); DecimalFormat f2 = new DecimalFormat("#0"); boolean shiftMod=false; ParticleSystem partSys=null; long previousFrame=0; float timeIntervalParticle=0.5;//seconds PGraphics gameSurface; PGraphics statSurface; PGraphics topView; +PGraphics scoreboard; // void settings() { size(displayWidth, displayHeight, P3D); x_coord=width/2; y_coord=height/2; } void setup() { mover = new Mover(); cyl=new Cylinder(); img = loadImage("earth.jpg"); globe = createShape(SPHERE, radius); globe.setStroke(false); globe.setTexture(img); img = loadImage("robotnik.png"); robot = loadShape("robotnik.obj"); robot.setTexture(img); gameSurface=createGraphics(width, height-300, P3D); topView=createGraphics(width, 300, P2D); statSurface=createGraphics(width, 100, P2D); + scoreboard = createGraphics(100, 100, P2D); // } void draw() { background(200); - + drawGame(); image(gameSurface, 0, 0); - + drawTopView(); image(topView, 0, height-300); - + drawStat(); image(statSurface, 0, 0); + + drawScoreboard(); + image(scoreboard,300+30, height-300+20) ; } -void drawTopView() { +void drawTopView(){ topView.beginDraw(); - topView.background(200); - topView.fill(0, 150, 150); - topView.rect(10, 0, 300, 300); - topView.fill(255, 255, 255); - float topViewCylRad=map(cyl.cylinderBaseSize, 0, plate_w/2, 0, 300); - if (partSys!=null) { - for (PVector pv : partSys.cylinders) { - float topViewCylX=map(pv.x, -plate_w/2, plate_w/2, 10, 310); - float topViewCylY=map(pv.y, -plate_w/2, plate_w/2, 10, 310); - topView.ellipse(topViewCylX, topViewCylY, topViewCylRad, topViewCylRad); - } - if (partSys.cylinders.contains(partSys.mainCyl)) { - topView.fill(255, 0, 0); - float topViewCylX=map(partSys.mainCyl.x, -plate_w/2, plate_w/2, 10, 310); - float topViewCylY=map(partSys.mainCyl.y, -plate_w/2, plate_w/2, 10, 310); - topView.ellipse(topViewCylX, topViewCylY, topViewCylRad, topViewCylRad); - } - } - - topView.fill(0,0,255); - float topViewBallRad=map(radius, 0, plate_w/2, 0, 300); - float topViewBallX=map(mover.location.x, -plate_w/2, plate_w/2, 10, 310); - float topViewBallY=map(mover.location.y, -plate_w/2, plate_w/2, 10, 310); - topView.ellipse(topViewBallX, topViewBallY, topViewBallRad, topViewBallRad); - + topView.background(0, 0, 100); topView.endDraw(); } void drawStat() { statSurface.beginDraw(); statSurface.background(0, 0, 0, 0); statSurface.fill(0); statSurface.textSize(25); statSurface.text("Rotation X : "+f.format(rx/Math.PI*180)+"° Rotation Z : "+f.format(rz/Math.PI*180)+"° speed: "+f.format(speed/10), 5, 25); statSurface.text("Ball location : ("+f2.format(mover.location.x)+","+f2.format(mover.location.y)+")", 5, 50); statSurface.text("Ball velocity : ("+f2.format(mover.velocity.x)+","+f2.format(mover.velocity.y)+")", 5, 75); statSurface.endDraw(); } void drawGame() { gameSurface.beginDraw(); gameSurface.background(100, 0, 0); gameSurface.directionalLight(50, 100, 125, 0, 1, 0); gameSurface.ambientLight(102, 102, 102); gameSurface.pointLight(150, 150, 150, 0, -200, 0); if (!shiftMod) { mover.update(); mover.checkEdges(); if (partSys!=null) { mover.checkCylinderCollision(partSys.cylinders, radius); } rz = map(x_coord, 0, width, -PI/3, PI/3); rx = map(y_coord, 0, height, -PI/3, PI/3); cameraHeight=400; } else { rz=0; rx=-PI/2; cameraHeight=0; } gameSurface.pushMatrix(); gameSurface.camera(0, -cameraHeight, depth, 0, 0, 0, 0, 1, 0); gameSurface.rotateZ(rz); gameSurface.rotateX(rx); gameSurface.shininess(100); gameSurface.box(plate_w, plate_t, plate_w); //particles if (partSys!=null) { if (frameCount-previousFrame>=timeIntervalParticle*frameRate && !shiftMod) { timeIntervalParticle=random(0.2, 1.2); previousFrame=frameCount; partSys.addParticle(); } partSys.run(-(plate_t/2), PI/2); } if (shiftMod) { float wMappedX=2*plate_w; float wMappedY=1.1*plate_w; xOnPlane=map(mouseX, 0, width, -wMappedX, wMappedX); yOnPlane=map(mouseY, 0, height, -wMappedY, wMappedY); cyl.draw(xOnPlane, yOnPlane, -(plate_t/2), PI/2); } gameSurface.translate(mover.getX(), -(plate_t/2+radius), mover.getY()); gameSurface.fill(255, 100, 100); gameSurface.rotateX(mover.getRotX()); gameSurface.rotateZ(mover.getRotZ()); gameSurface.shape(globe); gameSurface.popMatrix(); //Draw the text gameSurface.pushMatrix(); /*gameSurface.fill(0); - gameSurface.textSize(15); - gameSurface.text("Rotation X : "+f.format(rx/Math.PI*180)+"° Rotation Z : "+f.format(rz/Math.PI*180)+"° speed: "+f.format(speed/10), 5, 15); - */ + gameSurface.textSize(15); + gameSurface.text("Rotation X : "+f.format(rx/Math.PI*180)+"° Rotation Z : "+f.format(rz/Math.PI*180)+"° speed: "+f.format(speed/10), 5, 15); + */ if (shiftMod) { gameSurface.textSize(50); gameSurface.text("[EDIT MOD ON]", 50, 500); } gameSurface.fill(255); gameSurface.popMatrix(); gameSurface.endDraw(); } void mouseWheel(MouseEvent event) { float e = event.getCount(); if (e<0) { speed-=speed<=2?0:1; } else { speed+=speed>=15?0:1; } } void mouseDragged() { if (!shiftMod) { float d=-(mX-mouseX)*speed/10; x_coord=x_coord+d<=0?0:x_coord+d>=width?width:x_coord+d; mX=mouseX; d=(mY-mouseY)*speed/10; y_coord=y_coord+d<=0?0:y_coord+d>=height?height:y_coord+d; mY=mouseY; } } void mousePressed() { mX = mouseX; mY = mouseY; if (shiftMod && -plate_w/2 2*radius || Math.abs(yOnPlane-mover.location.y) > 2*radius)) { partSys=new ParticleSystem(new PVector(xOnPlane, yOnPlane), mover, radius); } } void keyPressed() { if (keyCode == SHIFT) { shiftMod=true; } } void keyReleased() { if (keyCode == SHIFT) { shiftMod=false; } } diff --git a/Project/Game/Mover.pde b/Project/Game/Mover.pde index 80fd000..a410de0 100644 --- a/Project/Game/Mover.pde +++ b/Project/Game/Mover.pde @@ -1,78 +1,79 @@ class Mover { float normalForce = 1; float gravityConstant = 1; float mu = 0.10; float eps=0.92; float frictionMagnitude; PVector location= new PVector(0, 0); PVector velocity= new PVector(0, 0); PVector friction; PVector gravity=new PVector(0, 0); Cylinder cyl=new Cylinder(); float rotX=0; float rotZ=0; Mover() { } void update() { velocity.add(gravity); gravity.x = sin(rz) * gravityConstant; gravity.y = -sin(rx) * gravityConstant; frictionMagnitude = normalForce * mu; friction = velocity.copy(); friction.mult(-1); friction.normalize(); friction.mult(frictionMagnitude); velocity.add(friction); location.add(velocity); //rotX+=velocity.x/cyl.cylinderBaseSize; rotX+=velocity.x/cyl.cylinderBaseSize; //rotZ+=velocity.y/cyl.cylinderBaseSize; rotZ+=velocity.y/cyl.cylinderBaseSize; } float getX() { return location.x; } float getY() { return location.y; } float getRotX() { return -rotZ; } float getRotY() { return 0; } float getRotZ() { return rotX; } void checkEdges() { if (location.x > plate_w/2|| location.x < -plate_w/2) { velocity.x*=-eps; } if (location.y > plate_w/2 || location.y < -plate_w/2) { velocity.y*=-eps; } location.y=Math.max(-plate_w/2, Math.min(plate_w/2, location.y)); location.x=Math.max(-plate_w/2, Math.min(plate_w/2, location.x)); } private void checkCylinderCollision(ArrayList arr, float r) { ArrayList touchingSet=new ArrayList(); for (PVector p : arr) { if (dist(p.x, p.y, location.x, location.y)<=cyl.cylinderBaseSize+r) {//if too close + //score += velocity.copy().mag(); touchingSet.add(p); PVector nRadius=location.copy().sub(p).normalize(); location=nRadius.copy().mult(cyl.cylinderBaseSize+r).add(p); velocity.sub(nRadius.mult(2*velocity.dot(nRadius))).mult(eps);//V2 = V1 − 2(V1 · n)n } } arr.removeAll(touchingSet); } } diff --git a/Project/Game/ParticleSystem2403460941017323953.autosave b/Project/Game/ParticleSystem2403460941017323953.autosave new file mode 100644 index 0000000..f4f657b --- /dev/null +++ b/Project/Game/ParticleSystem2403460941017323953.autosave @@ -0,0 +1,78 @@ +// A class to describe a group of Particles +class ParticleSystem { + ArrayList cylinders; + Cylinder cyl = new Cylinder(); + float cylinderRadius = cyl.cylinderBaseSize; + float radius; + PVector mainCyl; + PVector origin; + boolean shutdown=false; + Mover m; + + ParticleSystem(PVector origin,Mover m,float radius) { + this.m=m; + this.radius=radius; + this.origin = origin.copy(); + cylinders = new ArrayList(); + mainCyl=origin; + cylinders.add(mainCyl); + + } + void addParticle() { + PVector center; + if(!cylinders.contains(mainCyl)){ + shutdown=true; + } + int numAttempts = shutdown?0:100; + for (int i=0; i=0; --i) { + PVector p=cylinders.get(i); + cyl.draw(p.x, p.y, z, r); + } + if(cylinders.contains(mainCyl)){ + gameSurface.pushMatrix(); + gameSurface.translate(mainCyl.x,z - cyl.cylinderHeight, mainCyl.y); + gameSurface.rotateX(PI); + gameSurface.scale(50); + gameSurface.shape(robot,0,0); + gameSurface.popMatrix(); + } + } +} diff --git a/Project/Projection/Projection.pde b/Project/InteractiveProjection/InteractiveProjection.pde similarity index 95% rename from Project/Projection/Projection.pde rename to Project/InteractiveProjection/InteractiveProjection.pde index cdb2972..205c197 100644 --- a/Project/Projection/Projection.pde +++ b/Project/InteractiveProjection/InteractiveProjection.pde @@ -1,147 +1,147 @@ void settings() { - size(1000, 1000, P2D); + size(1000, 1000, P2D); } void setup() { } void draw() { background(255, 255, 255); My3DPoint eye=new My3DPoint(0, 0, -5000); My3DPoint origin=new My3DPoint(0, 0, 0); My3DBox input3DBox=new My3DBox(origin, 100, 150, 300); //rotated around x float[][]transform1= rotateXMatrix(-PI/8); input3DBox= transformBox(input3DBox, transform1); projectBox(eye, input3DBox).render(); //rotated and translated float[][]transform2= translationMatrix(200, 200, 0); input3DBox= transformBox(input3DBox, transform2); projectBox(eye, input3DBox).render(); //rotated, translated, and scaled float[][]transform3= scaleMatrix(2, 2, 2); input3DBox= transformBox(input3DBox, transform3); projectBox(eye, input3DBox).render(); } class My2DPoint { float x; float y; My2DPoint(float x, float y) { this.x = x; this.y = y; } } class My3DPoint { float x; float y; float z; My3DPoint(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } } My2DPoint projectPoint(My3DPoint e, My3DPoint p) { //e = eye return new My2DPoint((p.x-e.x)/(1-p.z/e.z), (p.y-e.y)/(1-p.z/e.z)); } My2DBox projectBox(My3DPoint eye, My3DBox box) { My2DPoint [] my2dPoint = new My2DPoint[8]; for (int i =0; i 3) - scale = 0.2; - mousey = mouseY; -} - -class My2DPoint { - float x; - float y; - My2DPoint(float x, float y) { - this.x = x; - this.y = y; - } -} - -class My3DPoint { - float x; - float y; - float z; - My3DPoint(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } -} - -My2DPoint projectPoint(My3DPoint e, My3DPoint p) { //e = eye - return new My2DPoint((p.x-e.x)/(1-p.z/e.z), (p.y-e.y)/(1-p.z/e.z)); -} -My2DBox projectBox(My3DPoint eye, My3DBox box) { - My2DPoint [] my2dPoint = new My2DPoint[8]; - for (int i =0; i