How to use camera and camera node

Hi, i am trying to learn hot use the camera and camera node. This is my code:



public void setCamera(){

      try{

         display= DisplaySystem.getDisplaySystem();

      

         cam = display.getRenderer().createCamera(display.getWidth(),

            display.getHeight());

      } catch (JmeException e) {

         

         System.out.println("Could not create displaySystem");

         System.exit(1);

      }

      

      cam.setFrustumPerspective(45.0f, (float) display.getWidth()

            / (float) display.getHeight(), 1, 1000);

      

      camNode = new CameraNode("Camera Node", cam);

      camNode.setLocalTranslation(new Vector3f(5.0f, 8.0f, 10.0f));

      rootNode.attachChild(camNode);

      camNode.updateWorldData(0);   

}





But i want the camera to move, and what i do is in the update function change the localtranslation of the camera node, i create a new vector, for example new vector3f(4.0f, 8.0f, 10.0f) and i pass it to the setlocaltranslation of the cameranode, but the camera does not move?. What can i do?


public void setCamera(){
      try{
         display= DisplaySystem.getDisplaySystem();
      
         cam = display.getRenderer().createCamera(display.getWidth(),
            display.getHeight());
                        display.getRenderer().setCamera(cam);
      } catch (JmeException e) {
         
         System.out.println("Could not create displaySystem");
         System.exit(1);
      }
      
      cam.setFrustumPerspective(45.0f, (float) display.getWidth()
            / (float) display.getHeight(), 1, 1000);
      
      camNode = new CameraNode("Camera Node", cam);
      camNode.setLocalTranslation(new Vector3f(5.0f, 8.0f, 10.0f));
      rootNode.attachChild(camNode);
      camNode.updateWorldData(0);   
}

This is the code where i set up the camera:

public void setCamera(){
      try{
         display= DisplaySystem.getDisplaySystem();
      
         cam = display.getRenderer().createCamera(display.getWidth(),
            display.getHeight());
      } catch (JmeException e) {         
         System.out.println("Could not create displaySystem");
         System.exit(1);
      }      
      cam.setFrustumPerspective(45.0f, (float) display.getWidth()
            / (float) display.getHeight(), 1, 1000);
      loc = new Vector3f(5.0f, 8.0f, 10.0f);      
      camNode = new CameraNode("Camera Node", cam);
      camNode.setLocalTranslation(loc);
      getRootNode().attachChild(camNode);
      camNode.updateWorldData(0);            
   }



And this is the update function:

public void update(float tpf){

rootNode.updateGeometricState(tpf, true);

if (KeyBindingManager.getKeyBindingManager().isValidCommand(
"camera_forward", false)) {
camNode.setLocalTranslation(camNode.getLocalTranslation().add(0.1f, 0.1f, 0.1f));
camNode.updateWorldData(0);
System.out.println("UP");
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand(
"camera_left", true)) {
System.out.println("LEFT");
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand(
"camera_back", true)) {
System.out.println("BACK");
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand(
"camera_right", true)) {
System.out.println("RIGHT");
}

}

I only write the up function, but the other are similar to this. Well my problem is that the camera does not move anything, it stays always at the same point. What could be the problem? Did i do anything wrong? Thank you all.

Does it have a reason that you create a new camera?

You should use the one of the current displaysystem:


Camera cam = DisplaySystem.getDisplaySystem.getRenderer().getCamera()


ttrocha said:

Does it have a reason that you create a new camera?
You should use the one of the current displaysystem:

Camera cam = DisplaySystem.getDisplaySystem.getRenderer().getCamera()





I did not realize that. But now i cant see anything:

      
loc = compasBox.getLocalTranslation();
      camNode = new CameraNode("Camera Node", display.getRenderer().getCamera());
      camNode.setLocalTranslation(loc.add(0,0,15));
      getRootNode().attachChild(camNode);
      camNode.updateWorldData(0);   


Compas box is the object i want see at the beginning.

maybee your cam looks into the wrong direction?

oh my, please look more carefully, I did not just repaste your code, I added the one statement that lets the Renderer use your camera:


display.getRenderer().setCamera(cam);



If after that you don't see anything your Camera doesn't look toward the Geometry you wish to see.

Greetings,
dhdd