# How to keep the camera stable while rotating a 3D model?

**URL:** https://discourse.processing.org/t/how-to-keep-the-camera-stable-while-rotating-a-3d-model/28729
**Category:** Coding Questions
**Created:** [March 22, 2021, 3:04pm UTC](https://discourse.processing.org/t/how-to-keep-the-camera-stable-while-rotating-a-3d-model/28729 "2021-03-22T15:04:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Neilly](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@Neilly](https://discourse.processing.org/u/Neilly)
#### Post date: [March 22, 2021, 3:04pm UTC](https://discourse.processing.org/t/how-to-keep-the-camera-stable-while-rotating-a-3d-model/28729/1 "2021-03-22T15:04:46Z")

</div>

I have a 3D model (of a skateboard) in processing which is rotating based on the movement of an external device. I have also placed 3 arrows in my Processing scene as reference axes in the X,Y,Z directions. My problem is that when the device rotates, my entire Processing scene (axes and model) all rotates.

I’m trying to keep the ‘camera’ stable, as well as the axes, so that they don’t move, and instead the skateboard moves within the axes. So instead of the whole view rotating with the skateboard, it stays in one position, facing the X axis. But the skateboard model is still free to rotate as it needs.

Can anyone help me create this effect?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 22, 2021, 3:42pm UTC](https://discourse.processing.org/t/how-to-keep-the-camera-stable-while-rotating-a-3d-model/28729/2 "2021-03-22T15:42:48Z")

</div>

please show your code

in general use pushMatrix(); and popMatrix(); to isolate the skateboard rotation from the rest (axes in the X,Y,Z directions):

pseudo-code:

```auto
pushMatrix(); 
translate(x,y,z); 
rotate(a); 
shape(skate, 0,0); 
popMatrix(); 
a+=0.0412; 

// draw axes in the X,Y,Z directions

```

**Example with full mouse rotation**

```auto

void setup() {
  size(1640, 860, P3D);
}

void draw() {
  avoidClipping(); 
  background(152);
  lights(); 

  pushMatrix(); 
  translate (width/2, height/2, 400);

  rotateX(map(mouseY, 0, height, -TWO_PI, TWO_PI));
  rotateY(map(mouseX, 0, width, -TWO_PI, TWO_PI));

  textMode(SHAPE);
  textAlign(CENTER, CENTER);
  fill(255); 
  text("Hello", 0, 0);

  translate(60, 0);
  box(18);

  translate(-120, 0);
  box(18);
  popMatrix();

  drawFloor();
}

// ---------------------------------------------------------------------------
// Tools

void avoidClipping() {
  // avoid clipping (at camera): 
  // https : // 
  // forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
  perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func 

void drawFloor() {

  pushMatrix();

  //stroke(111); // gray 
  noStroke(); 
  fill(0, 2, 255); // blue
  float factor1=80.0; // dist between boxes

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

  for (int x=-55; x<55; x++) {
    for (int z=-55; z<55; z++) {

      pushMatrix(); 
      translate(x*factor1 - (4*factor1/2), 
        height-111, 
        z*factor1 - (4*factor1/2) );
      fill(map(z, -55, 55, 100, 255), 0, 0);
      box(40); // size of 40 (width, height and depth) 
      popMatrix();
    }
  }
  popMatrix();
}
//

```

---

<div class="post-metadata">

### Author: ![Neilly](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@Neilly](https://discourse.processing.org/u/Neilly)
#### Post date: [March 22, 2021, 6:04pm UTC](https://discourse.processing.org/t/how-to-keep-the-camera-stable-while-rotating-a-3d-model/28729/3 "2021-03-22T18:04:28Z")

</div>

Thanks that worked great! Apologies for not showing my code in the original post, I just wasn’t sure about sharing it since its for my dissertation
