Parallel projection problem

Hi I have been working with a perspective camera and I would now like to move over to a camera using parallel projection since im working in a birds eye view environment.

I found the setParallelProjection method of camera and set this to true, and in doing so all nodes appeared to loose their z depth and where positioned at the camera.



Here is the code I use for a non parallel cam, which works as expected:



camera = display.getRenderer().createCamera(width, height);

...

// initialise the camera
Vector3f location = new Vector3f(0, 0, 0);
Vector3f x = new Vector3f(1, 0, 0);
Vector3f y = new Vector3f(0, 1, 0);
Vector3f direction = new Vector3f(0, 0, -1);
      
camera.setFrustumPerspective(45, ((float) width / (float) height), 1, 1000);
camera.setFrame(location, x, y, direction);
camera.update();



Then by simple adding camera.setParallelProjection(true); before the update everything goes pear shaped and im now looking at models from the inside out

I don't know how much this will help but I found this somewhere in the forums and it seems to work fine, probably the key here is the frustrum settings.



I thought as much but didnt know how to correctly configure the camera for parallel projection (lack of info in the docs).

Thanks DanK, ill give it a shot when I get home.

Good point about the docs. I've added a quick link to the User Docs with that code snippet, where the text of the page will be filled in later. My current feeling is getting these snippets into the User Manual quickly before they are lost and going back with the full on doc is a better solution then current (i.e. nothing). http://www.jmonkeyengine.com/wiki/doku.php?id=parallel_versus_perspective_projection






Good idea, I find those User Docs extremely helpful. And thanks DanK the code worked a treat.



One more question, as going from perspective to parallel appeared to zoom out slightly, I adjusted the left, right, top, and bottom distances (from the central point) to zoom back in. Is this the desired way of zooming with this type of camera?

Doing this i am able to set in orthographic mode the camera. Now I try to create a new camera, put on top of the scene and set it orthographic.

I am doing this:



this.camOrtho = new LWJGLCamera();

this.camOrtho.setParallelProjection(true);

float aspect = (float)DisplaySystem.getDisplaySystem().getWidth() / DisplaySystem.getDisplaySystem().getHeight();

camOrtho.setFrustum( -100, 1000, -50 * aspect, 50 * aspect, -100, 1000 );



camOrtho.setDirection(new Vector3f(0, -1, 0));

camOrtho.setLocation(new Vector3f(0, 50, 0));



this.setCamera(this.camOrtho);

camOrtho.update();





When i set the direction to (0, 1, 0) or (0, -1, 0) i see nothing on the viewport.

How can i set my camera on top of the scene looking down?




adamgp: Glad to be of help, of course… it really all comes from renanse, cep21, and mojomonkey when it comes down to it (and a few others too), they made the engine, and if they weren't the ones who told me how to do it, they were probably the ones who told the person who told me how to do it… or so it goes.



Can't help with ortho, I haven't had any luck with it when I tried to use it for something, I've been around a long time but my 3d skills pretty much don't exist… but now and then I'm stumbling across some realizations on how to work jME better… one of these days, I'll want to do something and it won't be a struggle, I look forward to the day when programming in jME is "tedious" (I know how to do everything, it's just a matter of putting in the work) vs frustrating (I don't know how to do anything, when I attempt to put in the work, it's actually spending time trying to figure out how to do the work). This isn't a fault in jME so much as my brain just not grasping 3D concepts like it should, I'm broken.

Well thanks anyway!



And Jordi, I use the following code to look down the Z axis



Vector3f location = new Vector3f(0, 0, 0);
Vector3f x = new Vector3f(1, 0, 0);
Vector3f y = new Vector3f(0, 1, 0);
Vector3f direction = new Vector3f(0, 0, -1);

...
camera.setFrustumPerspective(45, ((float) width / (float) height), 1, 1000); //perspective
...

camera.setFrame(location, x, y, direction);
camera.update();



Its the Vector3f direction = new Vector3f(0, 0, -1); bit that does it.

The way has gone better for me has been that:



camOrtho = new LWJGLCamera();

camOrtho.setParallelProjection(true);



DisplaySystem ds = DisplaySystem.getDisplaySystem();

float aspect = (float)ds.getWidth()/ds.getHeight();



camOrtho.setFrustum( -100, 1000, -20 * aspect, 20 * aspect, -20, 20 );

camOrtho.setFrame(  new Vector3f(0,50,0),

new Quaternion().fromAngleAxis(-90FastMath.DEG_TO_RAD, Vector3f.UNIT_X)

        .multLocal(new Quaternion().fromAngleAxis(180
FastMath.DEG_TO_RAD, Vector3f.UNIT_Y)));



getRenderer().setCamera(camOrtho);

camOrtho.update();







That works fine, but when i switch to this camera i must resize the window, doen't show nothing till I resize the window, next times i switch between the perspective camera and that parallel camera works fine, but the first time i need to resize.

How can i avoid this problem?

I assume when you say resize this means you are doing it embedded in Swing?  (If I'm wrong, ignore the next paragraph… :))



The resize code in JMECanvasImplementor calls reinit on the Renderer, which in turn calls it on the camera and forces a viewport change.  I would suggest calling onViewPortChange() on your camera.  (And perhaps call apply() on it as well.)

The onViewPortChange() helps, but the problem was i created the camera without set the width and height, i set the width and height like this:



camOrtho = getRenderer().createCamera(

(int)(this.cam.getViewPortRight() - this.cam.getViewPortLeft()),

(int)(this.cam.getViewPortBottom() - this.cam.getViewPortTop()) );



now runs fine, except my ray-picking detection has disaparead for this view, when i switch to the perspective camera the ray/picking runs again…