# How to rotate entire scene instead of all objects in scene (P3D)

**URL:** https://discourse.processing.org/t/how-to-rotate-entire-scene-instead-of-all-objects-in-scene-p3d/8546
**Category:** Coding Questions
**Created:** [February 19, 2019, 10:49pm UTC](https://discourse.processing.org/t/how-to-rotate-entire-scene-instead-of-all-objects-in-scene-p3d/8546 "2019-02-19T22:49:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![TheZipCreator](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thezipcreator/32/15979_2.png) [@TheZipCreator](https://discourse.processing.org/u/TheZipCreator)
#### Post date: [February 19, 2019, 10:49pm UTC](https://discourse.processing.org/t/how-to-rotate-entire-scene-instead-of-all-objects-in-scene-p3d/8546/1 "2019-02-19T22:49:02Z")

</div>

I have some code to make a scene and then I want to rotate the entire scene (not all the objects in the scene)  
When I run this code it rotates the cube and the skysphere seperately, but I want the entire scene to rotate, not individually rotate both the skysphere and the cube

```auto
PVector pos;
PShape sky;
float x;
float y;
float xm;
float ym;
float speed = 0.01;

void settings() {
  size(800, 600, P3D);
}
void setup() {
  noStroke();
  sky = createShape(SPHERE, 2000);
  sky.setTexture(loadImage("data/img/back.png"));
}
void draw() {
  translate(width/2, height/2);
  stroke(0);
  x += xm;
  y += ym;
  if(x > 1.5) {
    x = 1.5;
  }
  if(x < -1.5) {
    x = -1.5;
  }
  println(x, y);
  rotateX(x);
  rotateY(y);
  shape(sky);
  pushMatrix();
  translate(0, height/2, 0);
  box(2000, 0, 2000);
  popMatrix();
}
void keyPressed() {
  if(key == 'w') {
    xm = 0.01;
  }
  if(key == 'a') {
    ym = -0.01;
  }
  if(key == 's') {
    xm = -0.01;
  }
  if(key == 'd') {
    ym = 0.01;
  }
}
void keyReleased() {
  if(key == 'w') {
    xm = -0;
  }
  if(key == 'a') {
    ym = -0;
  }
  if(key == 's') {
    xm = 0;
  }
  if(key == 'd') {
    ym = 0;
  }
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [February 20, 2019, 3:17am UTC](https://discourse.processing.org/t/how-to-rotate-entire-scene-instead-of-all-objects-in-scene-p3d/8546/2 "2019-02-20T03:17:57Z")

</div>

if you need the background sphere to move ( rotate ) on key operation  
but the object ( box ) not:  
you need the push pop over the rotating sphere and not the box??

if you need them all to rotate: disable all push pop,  
that looks correct to me

```auto
//PVector pos;
PShape sky;
float x,y,xm,ym;
float limit = 1.5,speed = 0.01;

void settings() {
  size(800, 600, P3D);
}
void setup() {
// noStroke();
  sky = createShape(SPHERE, 2000);
// sky.setTexture(loadImage("data/img/back.png"));
}
void draw() {
  translate(width/2, height/2);
// push(); // add
  move();
  shape(sky);
// pop(); // add
// pushMatrix();
  translate(0, height/2, 0);
  stroke(200,0,0);
  fill(0,0,200);
  box(200, 20, 200);
// popMatrix();
}

void move() {
  x += xm;
  y += ym;
  if (x > limit) x = limit;
  if (x < -limit) x = -limit;
  println("x "+nf(x, 1, 2)+" y "+nf(y, 1, 2));
  rotateX(x);
  rotateY(y);
}

void keyPressed() {
  if (key == 'w') xm = speed;
  if (key == 'a') ym = -speed;
  if (key == 's') xm = -speed;
  if (key == 'd') ym = speed;
}

void keyReleased() {
  if (key == 'w'||key == 'a'||key == 's'||key == 'd') xm= ym = 0;
}

```

but possibly you expect the box at a different position??

translate(width/2, height/2);  
translate(0, height/2, 0);

should do what?  
try disable the second translate and look again??
