# Camera clip problem

**URL:** <https://discourse.processing.org/t/camera-clip-problem/4110>\
**Category:** Coding Questions\
**Created:** [October 4, 2018, 5:42am UTC](https://discourse.processing.org/t/camera-clip-problem/4110 "2018-10-04T05:42:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vjjv](https://avatars.discourse-cdn.com/v4/letter/v/df705f/32.png) [@vjjv](https://discourse.processing.org/u/vjjv)\
**Post date:** [October 4, 2018, 5:42am UTC](https://discourse.processing.org/t/camera-clip-problem/4110/1 "2018-10-04T05:42:28Z")

</div>

hello! this is my camera class, i`ve a problem when rotating at rx axes, it seems that clipping problem at 180 degrees in that axes. i want to be free to rotating full 360ª . what im doing wrong?

```auto
class Player {
  PVector position;
  PVector center;
  PVector up;
  PVector right;
  PVector forward;
  float pan;
  float tilt;
  PVector velocity;
  float angle;
  PVector vel2D;

  Player() {
    center = new PVector(0, 0, 1000);
    position = new PVector(0, 0, 0);
    up = new PVector(0f, 1f, 0f);  
    right = new PVector(0f, 0f, 0f);
    forward = new PVector(0f, 0f, 1f);
    velocity = new PVector(0f, 0f, 0f);
    pan = HALF_PI;
    tilt = 0;
  }

  void update(PGraphics a) {

    float xx = (Float)spaceNavigator.get("x");
    float yy = (Float)spaceNavigator.get("y");
    float zz = (Float)spaceNavigator.get("z");
    float rx = (Float)spaceNavigator.get("rx");
    float ry = (Float)spaceNavigator.get("ry");
    float rz = (Float)spaceNavigator.get("rz");
    float b0 = (Float)spaceNavigator.get("b0");
    float b1 = (Float)spaceNavigator.get("b1");

    pan -= ry*0.5;
    tilt -= -rx*0.5;

    forward = new PVector(cos(pan), tan(tilt), sin(pan));
    right = new PVector(cos(pan - PI/2), 0, sin(pan - PI/2));

    forward.normalize();

    velocity.add(PVector.mult(forward, (-zz*50.0)));
    velocity.add(PVector.mult(right, (-xx*50.0)));
    velocity.add(PVector.mult(up, (yy*50.0)));

    position.add(velocity);
    velocity.limit(0.5);

    center = PVector.add(position, forward);

    float fov = PI/2;
    float cameraZ = (height/2) / tan(fov); // when i multiple this fov * 4, 8, the camera clips in different degrees up 180. maybe here is the problem

    a.perspective(fov, float(width)/float(height), 0.1, cameraZ*20);
    a.camera(position.x, position.y, position.z, center.x, center.y, center.z, up.x, up.y, up.z);
    velocity.mult(0);
  }
}

```

thanks!

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [October 4, 2018, 5:52am UTC](https://discourse.processing.org/t/camera-clip-problem/4110/2 "2018-10-04T05:52:47Z")

</div>

hi @vjjv, if you don’t mind, can you post your setup() and draw() functions? What have you tried so far to fix the issue?

---

<div class="post-metadata">

**Author:** ![vjjv](https://avatars.discourse-cdn.com/v4/letter/v/df705f/32.png) [@vjjv](https://discourse.processing.org/u/vjjv)\
**Post date:** [October 5, 2018, 3:54am UTC](https://discourse.processing.org/t/camera-clip-problem/4110/3 "2018-10-05T03:54:12Z")

</div>

thanks for reply. i dont think is any system problem. (setup and draw dont do so much, i dont post becouse is a very big and segment program, theres no information there) but basically this camera is render in a Pgraphics scene. i think that is a perspective problem, but i dont really know which

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 13, 2018, 9:05pm UTC](https://discourse.processing.org/t/camera-clip-problem/4110/4 "2018-10-13T21:05:52Z")

</div>

> [@vjjv](#):
>
> when rotating at rx axes, it seems that clipping problem at 180 degrees in that axes.

Without a very simple test sketch to see you using the class it is hard to know exactly what your problem is. It _might_ be gimbal lock? If so, a good solution is to use PeasyCam.

> **[GitHub - jdf/peasycam: Dead-simple mouse-driven camera for Processing](https://github.com/jdf/peasycam/)**
>
> Dead-simple mouse-driven camera for Processing. Contribute to jdf/peasycam development by creating an account on GitHub.

Or, depending on how you are using the camera, a another full interactive camera library implementation (dollying, not centered) is QueasyCam.

> **[GitHub - jrc03c/queasycam: (!!! NOTE: INACTIVE PROJECT !!!) A super-simple...](https://github.com/jrc03c/queasycam)**
>
> (!!! NOTE: INACTIVE PROJECT !!!) A super-simple FPS camera library for Processing. - GitHub - jrc03c/queasycam: (!!! NOTE: INACTIVE PROJECT !!!) A super-simple FPS camera library for Processing.
