hello! im trying to do this en eclipse, using perspective to set the nearClip (is there any other way to set the near and far clip without the perspective() function?) in eclipse the function dont work fine, please take a look, its maybe a bug i think… o perhaps im missing something…
Reading up on Processing source code, there’s a variable g that PApplet(and your sketch since it extends PApplet) has, that simply refers to the current canvas - which, when you do size(..., P3D); is set to an object of class processing.opengl.PGraphics3D, which extends PGraphicsOpenGL.
Then, function perspective(... is simply forwarded to g.perspective(..., which does the code on that object g.
/**
* Same as glFrustum(), except that it wipes out (rather than multiplies
* against) the current perspective matrix.
* <P>
* Implementation based on the explanation in the OpenGL blue book.
*/
@Override
public void frustum(float left, float right, float bottom, float top,
float znear, float zfar) {
// Flushing geometry with a different perspective configuration.
flush();
cameraFOV = 2 * (float) Math.atan2(top, znear);
cameraAspect = left / bottom;
cameraNear = znear;
cameraFar = zfar;
float n2 = 2 * znear;
float w = right - left;
float h = top - bottom;
float d = zfar - znear;
projection.set(n2 / w, 0, (right + left) / w, 0,
0, -n2 / h, (top + bottom) / h, 0,
0, 0, -(zfar + znear) / d, -(n2 * zfar) / d,
0, 0, -1, 0);
updateProjmodelview();
}
Looks like it involves some scary maths, where everything is related and changing a thing could drastically screw everything up…
You could probably just mess with g.cameraNear and g.cameraFar, and then try doing g.updateProjmodelview();, but no promises.
.
Code snippets from above copied from Processing source code from here:
Also, just figured out why the image comes out stretched - it’s because of how you are setting the second parameter of perspective.
You are setting it to width/height, which is correct, but the problem is that both width and height are integers, so Java does integer division, which results in 1.
What you need to do instead is (float)width/height so that it would do float division and actually return 1.77777 that is needed to make the aspect ratio proper.