int fps = 60; float depth; float scale; float courtsize; float netsize; float ballsize=10; float grav = 1; ball b; void setup(){ size(500,500,P3D); depth = width; rectMode(CENTER); frameRate(fps); scale = width/500; courtsize = 300; netsize = courtsize / 6; b = new ball(0,-netsize*2,courtsize/3); mx = 0; my = 0; background(200); } void keyPressed(){ if(key==' ')background(200); } class ball{ float x,y,z; float xs,ys,zs; ball(float px, float py, float pz){ x = px; y = py; z = pz; zs = -4; } void draw(){ mx = ((float)mouseX-(width/2.0)) / width; my = ((float)mouseY - (height/2.0)) / height; noStroke(); pushMatrix(); fill(0,0,0,50); translate(x,0,z); box(scale*ballsize,scale,scale*ballsize); popMatrix(); pushMatrix(); translate(x,y,z); if(mousePressed){ fill(200); } else { fill(128.0 + (255.0*x/courtsize),128.0 + (255.0*y/courtsize),128.0 + (255.0*z/courtsize),200); } box(scale*ballsize,scale*ballsize,scale*ballsize); popMatrix(); } void move(){ //x += xs; //y += ys; x = mx * courtsize; y = my * courtsize; //println(x+" "+y); z += zs; bounds(); //ys += grav; //println(ys); } void bounds(){ if(y > 0.0){ ys *= -1.0; y = 0; } if(z < -courtsize/2.0){ z = -courtsize/2.0 ; zs *= -1; } if(z > courtsize/2.0){ z = courtsize/2.0 ; zs *= -1; } if(x < -courtsize/2.0){ x = -courtsize/2.0 ; xs *= -1; } if(x > courtsize/2.0){ x = courtsize/2.0 ; xs *= -1; } } } void draw(){ // background(128); drawAimer(); pushMatrix(); translate(250*scale,350*scale,0); drawBase(); b.move(); b.draw(); popMatrix(); } /* void mousePressed(){ float hit = 10; if(b.z > 0){ // print("before ys is "+b.xs+" "+b.ys); b.xs += mx*hit; b.ys += my*hit; println("after "+b.xs+" "+b.ys); b.zs -= hit; } }*/ void drawBase(){ stroke(255,10); // box(scale*courtsize,scale,scale*courtsize) ; } float mx; float my; void drawAimer(){ noFill(); stroke(170); if(true)return; pushMatrix(); translate(250*scale, 400*scale, 100*scale ); rotateY(-mx/4); rotateX(my/4); rotateX(.3); box(40*scale,40*scale,40*scale); float px = scale*mx*20; float py = scale*my*20; stroke(30); line(0,scale*20,scale*20,px,scale*20,-20*scale); stroke(255); line(0,0,scale*20,px,py,-20*scale); line(px,py,-20*scale,px,py-(5*scale),-15*scale); line(px,py,-20*scale,px,py+(5*scale),-15*scale); line(px,py,-20*scale,px-(5*scale),py,-15*scale); line(px,py,-20*scale,px+(5*scale),py+(5*scale),-15*scale); popMatrix(); // line(250,250,250 + mx*30,250 + my*30); }