# Using camera in processing for moving in specific area

**URL:** <https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 20, 2020, 7:00am UTC](https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080 "2020-05-20T07:00:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alkyonemis](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@alkyonemis](https://discourse.processing.org/u/alkyonemis)\
**Post date:** [May 20, 2020, 7:00am UTC](https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080/1 "2020-05-20T07:00:03Z")

</div>

Hi I’m a new coder on processing. I have long and complex code but I prepared a simple code to you for my question.

```auto
float camX = 0;
float camY = 0;
float camZ = (height/2)/tan(PI/6) - 260;

float x, y, z = 0;

float rotX = 0, rotY = 0;
float lastX, lastY;
float distX, distY;

void setup() {
  size(1600, 1000, P3D);
}

void draw() {
  background(0);

  camera(camX, camY, camZ, //default camera position without 360 degree
    x, y, z, //where it is looking to
    0, 1, 0); //eye openness

  rotateX(rotX + distY);
  rotateY(rotY + distX);

  beginShape(QUADS);
  vertex(-350, 100.1, 350); // Upper left to Corner    
  vertex(350, 100.1, 350); // Upper right to Corner
  vertex(350, 100.1, -350); // Bottom right to Corner
  vertex(-350, 100.1, -350); // Bottom left to Corner
  endShape();

  if (keyPressed)
  {
    if (key == 'w') { // FRONT
      camZ += 5;
    } else if (key == 's') { // BACK
      camZ -= 5;
    } else if (key == 'a') { // LEFT
      camX += 5;
      x += 5;
    } else if (key == 'd') { // RIGHT
      camX -=5;
      x -= 5;
    }
  }
}

public void mousePressed() {
  lastX = mouseX;
  lastY = mouseY;
}

public void mouseDragged() {
  distX = radians(mouseX - lastX);
  distY = radians(lastY - mouseY);
}

public void mouseReleased() {
  rotX += distY; 
  rotY += distX;
  distX = distY = 0;
}

```

So, I want to make a camera that can only go around the vertices of which was given.The camera won’t go outside from the white area. How to make that happened? Also there is a bug when I go further on the area. The camera changes the way when it reachs the half of the area. Can you help me about fixing that bug? Thank you.

---

<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:** [May 20, 2020, 7:47am UTC](https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080/2 "2020-05-20T07:47:49Z")

</div>

Concerning the bug:

> **[Kango/3DSketches](https://github.com/Kango/3DSketches/wiki/Avoid-Clipping)**
>
> 3D processing sketches . Contribute to Kango/3DSketches development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![alkyonemis](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@alkyonemis](https://discourse.processing.org/u/alkyonemis)\
**Post date:** [May 20, 2020, 9:22am UTC](https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080/3 "2020-05-20T09:22:23Z")

</div>

I tried the perspective but it didn’t help. It stills give a mirror effect when it reaches the half of area. I can’t go till the end of area.

---

<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:** [May 20, 2020, 1:30pm UTC](https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080/4 "2020-05-20T13:30:13Z")

</div>

> [@alkyonemis](#):
>
> I want to make a camera that can only go around the vertices of which was given.The camera won’t go outside from the white area.

Do you mean that the camera should not go into the Center of the scene where the vertices are?

Two approaches:

- Instead of the camera going left/right/forward/backwards without conditions you could check with `if()` and `dist()` whether we are close to the vertices and then not allow the change of position required by the keys.

- Another approach would be to think of the camera as being on a circle around the center and moving on the circle (different angle, together with cos and sin; see _website | tutorials | trigonometry_). Additionally to the angle you can change the radius but don’t let the radius become smaller than 99 or whatever.

Warmest regards,

Chrisir

---

<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:** [May 20, 2020, 1:31pm UTC](https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080/5 "2020-05-20T13:31:52Z")

</div>

Hey, and welcome to the forum!

Great to have you here and great that you start to program!

Chrisir

---

<div class="post-metadata">

**Author:** ![alkyonemis](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@alkyonemis](https://discourse.processing.org/u/alkyonemis)\
**Post date:** [May 20, 2020, 11:26pm UTC](https://discourse.processing.org/t/using-camera-in-processing-for-moving-in-specific-area/21080/6 "2020-05-20T23:26:14Z")

</div>

Thank you so much 🙏 🙏 🙏 🙏 🙏 🙏 🙏 🙏 🙏 🙏 🙏
