Box fixed in front of camera Processing

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

    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.

Hey, welcome to the forum!

Great to have you here!

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()


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

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
}
//