# Issues with defining a frustum/perspective

**URL:** <https://discourse.processing.org/t/issues-with-defining-a-frustum-perspective/38019>\
**Category:** Coding Questions\
**Created:** [July 18, 2022, 6:35pm UTC](https://discourse.processing.org/t/issues-with-defining-a-frustum-perspective/38019 "2022-07-18T18:35:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![graph100](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/graph100/32/12557_2.png) [@graph100](https://discourse.processing.org/u/graph100)\
**Post date:** [July 18, 2022, 6:35pm UTC](https://discourse.processing.org/t/issues-with-defining-a-frustum-perspective/38019/1 "2022-07-18T18:35:30Z")

</div>

I’m working on a game and I’m currently trying to extend the render distance of the camera. I tried using the frustum() and perspective() functions, but they didn’t work. I tried again, this time using the default values, and still, nothing is rendering. I’ve tried placing them in the setup() function and the draw() function.

Currently, when I use those functions, only the background color shows. Im trying to draw a 3d model as a PShape and a plane made using beginShape() and endShape(), and it all works fine without using the functions mentioned above.

Is this a glitch or is there some other code I am missing that will help? Thanks!

---

<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:** [July 18, 2022, 9:04pm UTC](https://discourse.processing.org/t/issues-with-defining-a-frustum-perspective/38019/2 "2022-07-18T21:04:19Z")

</div>

Can you please show your perspective code

---

<div class="post-metadata">

**Author:** ![graph100](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/graph100/32/12557_2.png) [@graph100](https://discourse.processing.org/u/graph100)\
**Post date:** [July 18, 2022, 10:36pm UTC](https://discourse.processing.org/t/issues-with-defining-a-frustum-perspective/38019/3 "2022-07-18T22:36:54Z")

</div>

currently I have  
`camera(0, -500, 0, pos.x, pos.y, pos.z, 0, 1, 0);`  
`frustum(-width/2, width/2, -height/2, height/2, 0, max(width, height));`  
or instead of frustum I’ve tried something like  
`perspective(PI/3.0, width/height, 0, 500);`

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [July 19, 2022, 5:54am UTC](https://discourse.processing.org/t/issues-with-defining-a-frustum-perspective/38019/4 "2022-07-19T05:54:19Z")

</div>

Hi @graph100,

the information you are giving only allows guessing (you look over the target) not helping you.  
If you want to use camera / perspective / frustum you need to imagine

- which plane configuration you are want to be the scene (ie x/z)
- where you are in space (camera eye)
- where is the ie. the object you are looking (lookingAt)

Here’s some code to play around with…

```auto
void setup() {
  size(800, 800, P3D);
}

void draw() {
  background(0);  
  if (mousePressed) {
    // draw with perspective variations
    float fov = PI/map(mouseX, 0, width, 3.0, 6.0);
    float cameraZ = (height/2.0) / tan(fov/2.0);
    perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*10.0);
  } else {
    // draw with frustum variations
    frustum(-width/8, width/8, height/8, -height/8, map(mouseX, 0, width, 10, 200), 400);
  }
  
  // camera eye at 300 towards to you and looking at the center where Y is up in a (x/z) plane
  camera(0, 0, -300, 0, 0, 0, 0, 1, 0);
  
  // draw a box at the center position
  rotateX(frameCount/100.0);
  rotateY(frameCount/150.0);
  stroke(128);
  fill(255);
  box(100);
}

```

Cheers  
— mnse
