# Box fixed in front of camera Processing

**URL:** <https://discourse.processing.org/t/box-fixed-in-front-of-camera-processing/24562>\
**Category:** Coding Questions\
**Created:** [October 13, 2020, 7:45am UTC](https://discourse.processing.org/t/box-fixed-in-front-of-camera-processing/24562 "2020-10-13T07:45:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faceless](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@Faceless](https://discourse.processing.org/u/Faceless)\
**Post date:** [October 13, 2020, 7:45am UTC](https://discourse.processing.org/t/box-fixed-in-front-of-camera-processing/24562/1 "2020-10-13T07:45:17Z")

</div>

Hey, is there any way to fix a box in front of the camera? Im using this to move the camera with the mouse:

```auto
    rotationAngle = map(mouseX, 0, width, 0, TWO_PI);
    elevationAngle = map(mouseY, 0, height, 0, PI);
  
    centerX = cos(rotationAngle) * sin(elevationAngle);
    centerY = sin(rotationAngle) * sin(elevationAngle);
    centerZ = cos(elevationAngle);
    camera(0, 0, 0, -centerX, centerY, -centerZ, 0, 0, 1);

```

Any help would be appreciated.

---

<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:** [October 13, 2020, 2:23pm UTC](https://discourse.processing.org/t/box-fixed-in-front-of-camera-processing/24562/2 "2020-10-13T14:23:45Z")

</div>

Hey, welcome to the forum!

Great to have you here!

> [@Faceless](#):
>
> Im using this to move the camera with the mouse:

actually, you don’t move the camera you just rotate it to different lookAt’s iirc

also, you changed the UP vector

here is a solution with lerp()

```auto

// ------------------------------------------------------------

void setup() {
  size(1400, 900, P3D);
}

void draw() {
  background(0);
  lights();

  //translate(width/2, 200, 0);
  //rotateY(map(mouseX, 0, width, 0, TWO_PI)); 
  //rotateX(map(mouseY, 0, height, 0, TWO_PI)); 

  float rotationAngle = map(mouseX, 0, width, 0, TWO_PI);
  float elevationAngle = map(mouseY, 0, height, 0, PI);

  float centerX = -cos(rotationAngle) * sin(elevationAngle);
  float centerY = sin(rotationAngle) * sin(elevationAngle);
  float centerZ = - cos(elevationAngle);
  camera(0, 0, 0, 
    centerX, centerY, centerZ, 
    0, 0, 1 );

  for (int i = 0; i < 100; i++) {
    dottedLine(new PVector(i*44, 0, 0), 
      new PVector(10+i*44, 210, -510));
  }

  PVector newPV = PVector.lerp( new PVector(0, 0, 0), 
    new PVector(centerX, centerY, centerZ), 
    188.53199640007 );

  pushMatrix();
  translate(newPV.x, newPV.y, newPV.z);
  fill(0, 255, 0);
  box(18); 
  popMatrix();
}

// ------------------------------------------------------------------

void dottedLine(PVector from, PVector to) { 
  stroke(255, 0, 0);
  strokeWeight(2); 

  for (int i = 0; i < 100-5; i+=10) {

    // if (i%10==0) {
    PVector step = PVector.lerp( from, to, i / 100.0 ); 
    PVector step2 = PVector.lerp( from, to, (i+5) / 100.0 );

    //point(step.x, step.y, step.z);
    line(step.x, step.y, step.z, 
      step2.x, step2.y, step2.z);
    // }
  }
  strokeWeight(1); // reset
}
//

```
