float rY, rX;
float dim;
boolean clicked;

Cube c1 = new Cube(width/2,height/2,0,50,50,50);

void setup()
{
size(600,600,P3D);
noStroke();
}

void draw()
{
background(255);
directionalLight(255, 255, 255, -0.5, -1, -0.25);
c1.display();

if(clicked)
{
rX-=(mouseY-pmouseY)/5;
rY-=(mouseX-pmouseX)/5;
}
}

void mousePressed()
{
clicked = true;
}

void keyPressed()
{
if(key=='d')
{
c1.x+=10;
}
else if(key=='a')
{
c1.x-=10;
}
else if(key=='w')
{
c1.y-=10;
}
else if(key=='s')
{
c1.y+=10;
}
else if(key=='r')
{
c1.z-=10;
}
else if(key=='f')
{
c1.z+=10;
}
else if(key==' ')
{
println(c1.x,c1.y);
}
}

void mouseReleased()
{
clicked = false;
}

class Cube
{
float x,y,z,w,h,d;

Cube(float _x, float _y, float _z, float _w, float _h, float _d)
{
x=_x;
y=_y;
z=_z;
w=_w/2.0;
h=_h/2.0;
d=_d/2.0;
}

void display()
{
pushMatrix();
translate(x,y,z);
fill(255,255,0);
beginShape(QUAD);
//front
vertex(-w,-h,d);
vertex(-w,h,d);
vertex(w,h,d);
vertex(w,-h,d);
//right
vertex(w,-h,d);
vertex(w,-h,-d);
vertex(w,h,-d);
vertex(w,h,d);
//left
vertex(-w,-h,-d);
vertex(-w,-h,d);
vertex(-w,h,d);
vertex(-w,h,-d);
//top
vertex(-w,-h,-d);
vertex(w,-h,-d);
vertex(w,-h,d);
vertex(-w,-h,d);
//bottom
vertex(-w,h,d);
vertex(w,h,d);
vertex(w,h,-d);
vertex(-w,h,-d);
//back
vertex(-w,-h,-d);
vertex(-w,h,-d);
vertex(w,h,-d);
vertex(w,-h,-d);
endShape(CLOSE);
fill(255,0,0);
sphere(10);
popMatrix();
}
}