[Solved] First person camera: Camera design tips?


Looked at the previously asked questions of this kind, but couldn't manage to build my own answer.

Help requested:

The camera will be attached to a DynamicPhysicsNode:

   protected void simpleInitGame() {

      self = getPhysicsSpace().createDynamicNode();
      self.createBox("First person body");
      self.setLocalScale(new Vector3f(1, 2, 0.5f));
      self.setLocalTranslation(new Vector3f(0, 1, 0));
      self.setCenterOfMass(new Vector3f(0, -0.5f, 0));
      selfLocation = self.getWorldTranslation();
      camLocation = new Vector3f(self.getLocalTranslation().x, self.getLocalTranslation().y, self.getLocalTranslation().z);
      showPhysics = true;


I'll perhaps be wrong, but I'm tempted to say:
1) the camera position is linked to key inputs:

            new InputAction() {
               public void performAction(InputActionEvent e) {

                  if (e.getTriggerPressed()) {
                           new Vector3f(0, 0, -2));
                  } else {
                           new Vector3f(0, 0, 0));
            }, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_NUMPAD8,
            InputHandler.AXIS_NONE, false);

   protected void simpleUpdate() {
      camLocation.set(self.getLocalTranslation().x, self.getLocalTranslation().y + 1, self.getLocalTranslation().z +3);

2) the camera steering is linked to cam.getDirection()
-> ?
I feel I'm going the wrong way!
When moving the mouse how should in best practices the "self" DynamicNode be rotated? Should it be linked to the mouse input for x-z, leaving y mouse axis for the cam itself? I feel that's too messy to be right :( Moreover, I don't feel confident at making it :(

Also, can one please tell me the difference between getLocalTranslation and getWorldTranslation?
The screen flickers as the second one is used to set the cam location:

      camLocation.set(self.getLocalTranslation().x, self.getLocalTranslation().y + 1, self.getLocalTranslation().z +3);
//      camLocation.set(self.getWorldTranslation().x, self.getWorldTranslation().y + 1, self.getWorldTranslation().z +3);

Thanks for your time!

no one :frowning: ?

I am not sure what you want to do exactly.

But if you attach the camera to a PhysicNode (or any other Node), then it is enough if you move the PhysicNode.

Since the Camera is a child of the PhysicNode the Camera will be moved with the PhysicNode.

Which already explains your last Question.

Lets say you attached the Camera(Node) to a PhysicsNode.

Initially both Nodes are located at 0,0,0.

Now you translate the PhysicsNode two Units along the X Axis. with (setLocalLtranslation())

Now the PhysicsNode LocalTranslation is -2,0,0, World is too at -2,0,0.

The CameraNodes Local is at 0,0,0, because the Camera didn't move relative to the PhysicNode.

But the Camera's World Position also changed to -2,0,0.

You could say, the LocalTranslation is the relative position to the Parent Node and WorldTranslation is the absolute position.

I should perhaps have mentioned that the Camera I use is:


I've not made a custom one, so it's not a descendant from a node of some kind… is your solution still applicable? If yes, please tell me how :smiley:

Sure, you just need to use a CameraNode.

You can look at TestCameraNode for an Example too.

    DisplaySystem.getDisplaySystem().getRenderer().setCamera( cam );
    CameraNode camNode = new CameraNode( "Camera Node", cam );
    Node player = new Node("player");

Oh that's great!

Lots of new things to try. Yay!

Thanks again.