How to use camera node!

Hi everyone!



I want to create a fixed camera for my project (a poker game, the camera is the "eyes" of the player) , but i don't understand how it works :



i create an give a position to my camera :



 cn=new CameraNode("camera node",display.getRenderer().getCamera());
 cn.setLocalTranslation(new Vector3f(X_PLAYER1,Y_PLAYER1-20,40));



But this just don't display anything, so to test, i copy the code of the Beginner's Guide by Cep21 :



Vector3f up = new Vector3f(0, 1, 0);
Vector3f left = new Vector3f(1, 0, 0);
      
private static Vector3f tempVb = new Vector3f();
private static Vector3f tempVc = new Vector3f();
private static Vector3f tempVd = new Vector3f();
private static Matrix3f tempMa = new Matrix3f();
   
       @Override
       protected void simpleUpdate() {

           Vector3f objectCenter =  new Vector3f(X_TABLE_CENTER ,0,0); // rootNode.getWorldBound().getCenter(tempVa);

           Vector3f lookAtObject = tempVb.set(objectCenter).subtractLocal(cam.getLocation()).normalizeLocal();

           tempMa.setColumn(0, up.cross(lookAtObject, tempVc).normalizeLocal());

           tempMa.setColumn(1, left.cross(lookAtObject, tempVd).normalizeLocal());

           tempMa.setColumn(2, lookAtObject);

           cn.setLocalRotation(tempMa);
       }



It works , but the camera is leaning  :x  : how do i have to do to make my camera?

(and do i have to really use simpleUpdate for a fixed camera?)

thanks!
Chevreuil said:


 cn=new CameraNode("camera node",display.getRenderer().getCamera());
 cn.setLocalTranslation(new Vector3f(X_PLAYER1,Y_PLAYER1-20,40));



(and do i have to really use simpleUpdate for a fixed camera?)


No you definitely dont have to set the cameranode rot and trans every frame, just once for a fixed camera.

the code above just sets the camera to the place you want it. it doesnt set any rotations. do smth like that:


       cn.lookAt(whatToLookAt.getWorldTranslation(), new Vector3f(0, 1, 0));



and after all is done just call cn.updateGeometricState(0.0f, true); or have it attached in the scenegraph you update every frame.

dhdd --> thanks guy! your code works.



But i still have this problem : the camera is leaning.  :expressionless:



I want a camera parallel to the surface of the table (like a FPS camera is parallel to the surface of the floor : in DOOM for example  :D).



How can i do it?



(i join a jpeg showing my camera see, so that you can understand)

well, this "leaning" is just how things look from the perspective of the camera. If you sit at the left side of your desk and look at the center of the desk this is what you get  :wink:



if you want to change that you have to set the localTranslation correctly (e.g. exactly N units above the point you want to look at).



or if you want a perspective in Z direction e.g.:

if the point you lookAt(…) is at (13, 0, 0) your camera has to be at (13, theHightYouWant, theDistanceYouWant);

then call lookAt(13, 0, 0) and it should be parallel



this example is assuming you didnt switch the axes of your view.

your solution works only for the player in front of the 5 common card because yes i switch the axes of my view (eg the schema i add).



I assume i have to do a rotation of the camera but i don't see how!

I think it's just a problem of rotation around x and y axis! Nobody can help? It's really important!  :expressionless:



Thanks!