and just for you code, when you post it at the forum
please use in processing IDE [ctrl][t] and in forum editor header menu </> looks like
void setup() {
size(600, 600, P3D);
}
void draw() {
background (0,0,100);
lights();
drawFloor();
drawSun(width/10+60, 100, 40);
drawWall();
}
void drawSun(float x, float y, float z) {
fill(255, 201, 34);
circle(x, y, z);
}
void drawFloor() {
push();
noStroke();
fill(65, 152, 10);
translate(width/2, height/2, -500);
float factor=5.0; // dist between boxes 80
for (int x=-55; x<55; x+=factor) {
for (int z=-55; z<55; z+=factor) {
pushMatrix();
float posx = x*factor + (4*factor/2);
float posy = height/2+100;
float posz = z*factor + (4*factor/2);
translate(posx, posy , posz );
box(20); //80
popMatrix();
}
}
pop();
}
void drawWall() {
fill(250, 0, 0);
rotateY(PI/6);
rect(150, 350, 600, 200);
}
with this small changes i see
if you draw 3D better also see 3D ( PTZ mouse keyboard operation )
void setup() {
size(600, 600, P3D);
info_print();
}
void draw() {
background (0, 0, 100);
lights();
PTZ();
}
void draw_object() { //_________________called by / from inside PTZ
drawSun(width/10+60, 100, 40);
drawFloor();
drawWall();
}
void drawSun(float x, float y, float z) {
push();
noStroke();
translate(x,y,z);
fill(255, 201, 34);
sphere(20);
pop();
}
void drawFloor() {
push();
noStroke();
fill(65, 152, 10);
translate(width/2, height/2, -500);
float factor=5.0; // dist between boxes 80
for (int x=-55; x<55; x+=factor) {
for (int z=-55; z<55; z+=factor) {
pushMatrix();
float posx = x*factor + (4*factor/2);
float posy = height/2+100;
float posz = z*factor + (4*factor/2);
translate(posx, posy, posz );
box(20); //80
popMatrix();
}
}
pop();
}
void drawWall() {
push();
fill(250, 0, 0);
rotateY(PI/6);
rect(150, 350, 600, 200);
pop();
}
//___________________________________________PTZ ( other TAB )
int mode = 0;
float Zmag = 1;
int Zaxis=-100;
float Xmag, Ymag = 0;
float newXmag, newYmag = 0;
int newZmag = 0;
int zoomf = 3;
float newxpos, newypos = 0; // for PAN
float xposd, yposd = 0; // for PAN
boolean diag = false;
//_________________________________________________________________ ROTATE / TILDE and MOVE / PAN
void mousePressed() {
if (mouseButton == LEFT) mode=1; // ORBIT
else if (mouseButton == RIGHT) mode=2; // PAN
// else if (mouseButton == CENTER) { mode=3; } // zoom mouse wheel
}
//_________________________________________________________________ mouse PT end
void mouseReleased() {
mode = 0;
}
//_________________________________________________________________ mouseWheel ZOOM
void mouseWheel(MouseEvent event) {
int newZmag = event.getCount(); // +- 1
Zmag += newZmag*0.05;
}
void keyPressed() {
if ( keyCode == UP ) Ymag -= 0.1 ;
if ( keyCode == DOWN ) Ymag += 0.1 ;
if ( keyCode == RIGHT) Xmag -= 0.1 ;
if ( keyCode == LEFT ) Xmag += 0.1 ;
if ( keyCode == 16 ) Zmag -= 0.05 ;
if ( keyCode == 11 ) Zmag += 0.05 ;
//println("key: "+key+" keyCode: "+keyCode);
}
//_________________________________________________________________ Pan Tilde Zoom
void PTZ() {
pushMatrix();
translate(width/2, height/2, Zaxis);
// get new mouse operation
if ( mode == 2 ) { // PAN ( right mouse button pressed)
xposd = (mouseX-float(width/2));
yposd = (mouseY-float(height/2));
}
newxpos = xposd;// xposd=0;
newypos = yposd;// yposd = 0;
translate(newxpos, newypos, 0); // move object
if ( mode == 1 ) { // ORBIT ( left mouse button pressed)
newXmag = mouseX/float(width) * TWO_PI;
newYmag = mouseY/float(height) * TWO_PI;
float diff = Xmag-newXmag;
if (abs(diff) > 0.01) {
Xmag -= diff/4.0;
}
diff = Ymag-newYmag;
if (abs(diff) > 0.01) {
Ymag -= diff/4.0;
}
}
rotateX(-Ymag);
rotateY(-Xmag);
scale(Zmag);
draw_object(); // THE OBJECT
if (diag) println(" Xmag "+nf(Xmag,0,1)+" Ymag "+nf(Ymag,0,1)+" Zmag "+nf(Zmag,0,1));
popMatrix();
}
//_______________________________________________ SETUP PRINT INFO
void info_print() {
println("PTZ info:");
println("key UP DOWN RIGHT LEFT -> rotate // key PAGE UP DOWN -> zoom");
println("mouse LEFT press drag up down right left -> rotate");
println("mouse RIGHT press -> move ");
println("mouse WHEEL turn -> zoom");
}