How do I create a second camera?

is this how I create the 2nd camera?



cam2 = display.getRenderer().createCamera(display.getWidth(),display.getHeight());



it seems that when i create it like this and change for example the position of cam2… it actually changes the position of the default camera (cam)



i am trying to have a key that toggles between two cameras.



what am I doing wrong? thanks.

This is how I did it:



    protected void initCameras() {

        cam.setLocation(new Vector3f(-4f, 5, -4f));
        cam.lookAt(new Vector3f(-0.5f, 0, -0.5f), new Vector3f(0, 1, 0));
        cam.update();

        camTop = renderer.createCamera(width, height);
        camTop.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);
        Vector3f loc = new Vector3f(0.0f, 0.0f, 0.0f);
        Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
        Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
        camTop.setFrame(loc, left, up, dir);

        camTop.setLocation(new Vector3f(-0.1f, 10.0f, -0.1f));
        camTop.lookAt(new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0, 1, 0));

        cam.update();

    }



Then to toggle:


    protected void setCamera(int camNr) {

        switch (camNr) {
            case 1:
                cam.update();
                renderer.setCamera(cam);
                break;
            case 2:
                camTop.update();
                renderer.setCamera(camTop);
                break;
            default:
                renderer.setCamera(cam);
                break;
        }
    }




Works perfect!


DKT

many thanks for taking the time to write. your code worked.

Glad I could help.





DKT

I've found one problem with your code (or maybe my own code :D). No matter what camera I'm using the scene gets culled according to what the original cam (the one from SimpleGame) can see. This of course looks very strange when you view the scene with another cam. How do I set which camera the renderer should use for frustum culling?

culling just asks the renderer for its camera, so it seems like your solution should work.  Sounds like a job for a debugging session.