Issues with defining a frustum/perspective

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!

1 Like

Can you please show your perspective code

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

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…

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

1 Like