Need Help for clipping lane

Hallo,

when i use perspective(fovy, aspect, zNear, zFar) > favy & aspect works as it should

but zNear & zFar change nothing. I use Processing 4.4.10

setup() >P3D & PGraphics matrix... 
.
.
matrix.beginDraw();
matrix.beginCamera();
    matrix.perspective(fovy, aspect, zNear, zFar);
    matrix.camera(eye.x, eye.y, eye.z, 
                  center.x, center.y, center.z, 
                  achse.x,achse.y, achse.z);
    matrix.ambientLight(ambientLightcolor,ambientLightcolor,ambientLightcolor);
    matrix.directionalLight(dl, dl, dl,0,0,-1);
    matrix.lightFalloff(constant, linear, quadratic);
matrix.endCamera();
.
.
.

after cam() i shape different things with matrix.shape(…)

and finally

image(matrix,0,0);

and

matrix.clear();

The strange thing is that when I drive out with the camera, the clipping limit always starts right behind a certain shape.

Does anyone have a solution or idea?

thx…

Could you post a full runnable example that shows the problem you are having? Your functions all look fine, so the problem is presumably with what parameters you are using and you don’t show what any of their values are.

From a precision stand-point, it is usually safe to make your far clipping distance very large, so use a value there that is well bigger than your scene. The near clipping distance should be close enough to the camera that you won’t walk into objects which sounds like the problem you are having. If you make it too small, you can get a problem called z-fighting where distant objects don’t have enough depth precision to know which polygon should be drawn in front of which and objects can flicker. Without a specific example, we can’t see how big your world and objects are, but if you are clipping into objects, try setting your near clip distance to half of what you currently have. Or 1/4 or 1/8, etc.

Hello,

Experiment!

Use println() to print values.

Reference:

Modified code from reference to get you started:

size(400, 400, P3D);

float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(fov/2.0);
println(cameraZ); // 346

float zNear =  cameraZ/10.0;
println(zNear);
float zFar  =  cameraZ*10.0;
println(zFar);

// Change value:
zNear =  cameraZ + 200 - 140;
println(zNear);

perspective(fov, float(width)/float(height), 
            zNear, zFar);
            
translate(200, 200, -200);
rotateY(TAU/8);
rotateX(TAU/9);

strokeWeight(3);
noFill();
box(180);

With a bit of effort (not included in above) I was able to clip the front and back:

hallo glv,

thanks for the quick replay.

Yes, i allready print all the Vectors of my shapes and they are all inside the projection.

Some Years ago i prog a similar code, also with perspectiv() and in this case its work.

The only difference of my new code 2 the old is, i shaped out from an object.

//old code
class xy{
PShape xy;
.
.
update(){
.
.
}

void shape(PGraphics Buffer)
Buffer.shape(xy,0,0);
}

In my new code i shape out from an ArrayList

//new Code
setup(){
.
shapes = new ArrayList <PShape>();
zNear=1
zFar=100000
}

draw(){
.
.
matrix.background(farbeBg);
matrix.ambientLight(100,100,100);
matrix.beginCamera();
    matrix.perspective(fovy, aspect, zNear, zFar);
    matrix.camera(eye.x, eye.y, eye.z, 
                  center.x, center.y, center.z, 
                  achse.x, achse.y, achse.z);
matrix.endCamera();
matrix.shape(planet,0,0);
for(int r = 0; r < shapes.size(); r++){
  building = shapes.get(r);
  matrix.shape(building,0,0);
}
.
.

the building-shape i generate in

.
building = createShape(BOX, sizeBuilding*random(minScaleBuilding,maxScaleBuilding), sizeBuilding*random(minScaleBuilding,maxScaleBuilding), sizeBuilding*random(minScaleBuilding,maxheightBuilding));
building.setStroke(false);
building.setFill(farbeBuilding0);
//building.setTexture(wand);
building.rotateX(rotX); 
building.rotateY(rotY);
building.translate(newPos.x, newPos.y,newPos.z);
shapes.add(building);
.

and all works fine, without the zFar clipping-lane???

i tested more..

when i go out with the cam (x = 30000+ even y &z) perspective works up to the center

PVector eye = eye.x = camRadius*cos(angleY);                             
              eye.y = camRadius*sin(angleX);                                    
              eye.z = camRadius*sin(angleY);
PVector center = (0,0,0) allways

now i rotate the cam()

and it is every time the same, perspective works up to the center

every thing behind is not visible, but not directly to the center, rather about 1000 behind it

When I rotate the camera with angleX, the center also disappears.

thx 2 scudly

Hello @picar ,

This worked (some initializations omitted in the spirit of the topic and your code provided) :

PShape globe;
PShape group;

PVector eye, center, camUp;

...
...
float zNear = 1000-170;
float zFar = 1000+170; // Initial
...

void setup() 
  {
  ...
   
  aspect = (float)width/(float)height;
  eye = ...
  center = ...
  camUp = ...

  // Initialize group (may be needed later to make a grid)
  group = createShape(GROUP);

  PShape s0 = createShape(BOX, 700, 10, 700);
  group.addChild(s0);
  }

void draw() 
  {
  angle = frameCount*(TAU/360); 
  renderScene();
  }

void renderScene() 
  {
  perspective(fovy, aspect, zNear, zFar);
  background(0);
  lights();
  
  float camRadius = 1000;
  eye.x = camRadius*cos(angle);                             
  eye.y = camRadius*sin(-TAU/16);                                    
  eye.z = camRadius*sin(angle);
  
  beginCamera();
  camera(eye.x, eye.y, eye.z, 
        center.x, center.y, center.z, 
        camUp.x, camUp.y, camUp.z);
  endCamera();
  
  shape(group);
  }

Clips front and back:

I had the same strange clipping as you and this was my final working version… still a work in progress.

Creating a GROUP shape seemed to work and very cool too:

I leave the rest to you.

Have fun!

Reference:

hey glv,

@ first, many thanks 2 you for your work and time.

i use …addChild() for the Galaxy (all ini in setup) > this works

The shapes of the buildings only works for the first building (also ini in setup).
When I add new childs in draw(), it doesn’t works.

Groups only work for static shapes that don’t change anymore?

How many childs can a group have in total?

And unfortunately, it doesn’t solve the problem with the clipping.

:face_exhaling:

now i`m sure the prob is the camera funktion.

i ini only one shape in setup().

void draw(){
  camUpdate()
  matrix.beginDraw();
    shapeCam();
    matrix.shape(galaxy);
  matrix.endDraw();
  image(matrix,0,0);
  matrix.clear();
}

void shapeCam(){
  matrix.background(farbeBg);
  matrix.perspective(fovy, aspect, zNear, zFar);
  matrix.ambientLight(ambientLightcolor,ambientLightcolor,ambientLightcolor);
  matrix.directionalLight(directionalLightcolor, directionalLightcolor, 
                          directionalLightcolor,0,0,-1);
  
  matrix.beginCamera();
    matrix.camera(eye.x, eye.y, eye.z, 
                  center.x, center.y, center.z, 
                  achse.x, achse.y, achse.z);
  matrix.endCamera();
}

void camUpdate(){
  eye.x = camRadius*cos(angleY);
  eye.y = camRadius*sin(angleX);
  eye.z = camRadius*sin(angleY);
  zFar = (radiusPlanet*TWO_PI)+camRadius;
}

When I extend the radius, all is fine (on all axes, for all values, positive and negative)

When I change the angles, the object disappears in the clipping.

it looks like, the cam is flexible but the perspective is static?

and it makes no difference where the perspective funktion is on shapeCam()

:sweat_smile:

zFar = (radiusPlanet*TWO_PI)+camRadius was the bad guy !

because I skillfully overlooked it

Problem = solved!

2 Likes