# 1st person camera

**URL:** https://discourse.processing.org/t/1st-person-camera/41106
**Category:** Coding Questions
**Created:** [March 1, 2023, 7:24pm UTC](https://discourse.processing.org/t/1st-person-camera/41106 "2023-03-01T19:24:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![09husky](https://avatars.discourse-cdn.com/v4/letter/0/4af34b/32.png) [@09husky](https://discourse.processing.org/u/09husky)
#### Post date: [March 1, 2023, 7:24pm UTC](https://discourse.processing.org/t/1st-person-camera/41106/1 "2023-03-01T19:24:02Z")

</div>

I am having some trouble with the camera function at the end. It does work to a decent extent, but I am wondering if anyone can help me solve the following problems with it:

1. sensitivity too high for looking up and down
2. is not able to look straight down, will just look down until it slows to a stop then reverses direction
3. (not entirely sure it is a problem) when looking down, the rotation speed of the camera speeds up.

```auto
int w = 600;
int h = 600;
float camX = w/2, camY = h/2, camZ = 50;
float mousex = mouseX, mousey = mouseY;

void settings(){
  size(w, h, P3D);
}

void setup(){
  background(200);
  frameRate(60);
  fill(255);
  stroke(0);
  strokeWeight(5);
}

void draw(){
  background(200);
  square(0, 0, 600);
  //move(3);
  mousex = mouseX;
  mousey = mouseY;
  camera(camX, camY, camZ, camX+cos(mousex/50)-sin(mousey/50), camY+sin(mousex/50)-sin(mousey/50), camZ+sin(mousey/100), 0, 0, -1);
}

```

---

<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 1, 2023, 10:23pm UTC](https://discourse.processing.org/t/1st-person-camera/41106/2 "2023-03-01T22:23:38Z")

</div>

Nice work!

below my version with `avoidClipping()` (no clipping). Also I suggest lights().

It’s interesting that your version is MUCH faster than it would be when you wouldn’t copy the `mouseX` and `mouseY` to your extra variables. Neat.

I think there is a library with the purpose 1st person.

**Remark**

I personally don’t like that you change the up orientation of the cam (the last 3 params).

I know it’s because you want to use square.

I think it’ll work but you always have to figure what is up when placing more object in the world.

**Sketch**

_(I kept your up orientation)_

```auto
int w = 600;
int h = 600;
float camX = w/2, camY = h/2, camZ = 50;

float mousex, mousey;

void settings() {
  size(w, h, P3D);
}

void setup() {
  background(200);
  frameRate(60);

  avoidClipping();

  fill(255, 0, 0);
  stroke(0);
  strokeWeight(5);
}

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

  mousex = mouseX;
  mousey = mouseY;
  camera(camX, camY, camZ,
    camX+cos(mousex/50)-sin(mousey/50), camY+sin(mousex/50)-sin(mousey/50), camZ+sin(mousey/100),
    0, 0, -1);

  square(0, 0, 600);
}//func draw

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

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

```
