Camera woes

It’s probably just me…



The galaxy that I’m generating is rotating on the y axis at a slow pace.

I added a box that I could use as a “ship” so I could move it around to test a little something I have in mind but something is weird.



#1 - The galaxy rotate, the ship rotates with the galaxy, the camera moves with the ship when a key is pressed to move the ship, but if left alone, the ship will rotate but the camera will remain still. So the ship moves off the center. I’m not entirely sure if and how I could fix that. I tried many different things but nothing has succeeded. Help would be much appreciated.



#2 - Is it possible to have movement continuously registered as I hold A/S/W/D instead of having to type and type and type using ActionListener? Or is it an obligation to use KeyInputEvent?



As I said, it’s probably me.



Thanks.

1# What are you using for your cam the ChaseCamera? if not you should, if yes…there is a bug :stuck_out_tongue:

the chase camera is a control on the spatial target, every time the spatial updates, the camera updates.



2#Yes it is, you have to use AnalogListener instead of ActionListener. Look at this tutorial, https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_input_system and see how the “Right” and “Left” input are moving the player

Thanks for your answer nehon!



#1 - Yes. I am using a ChaseCam. Here’s the bits. I have commented / uncommented lots of things I have tried so hopefully I didn’t screw up and made that problem myself.



Class-scoped declarations.

[java] protected ChaseCamera shipCam;[/java]



Later in code

[java]

private void setCamera() {

cam.setLocation(shipLocation);

cam.lookAt(playerShip.getLocalTranslation(), Vector3f.UNIT_Y);

shipCam = new ChaseCamera(cam, playerShip,inputManager);

if (!shipCam.isEnabled())

shipCam.setEnabled(true);

cam.update();

cam.updateViewProjection();

shipCam.setMaxDistance(2f);



}

[/java]

What I find odd though is that shipCam (ChaseCam) has to be tied to a Camera object, but it only wants to use the default com.jme3.app.Application “protected Camera cam” object. If I use a custom Camera I initialized myself, the ship doesn’t appear when everything is tied together and moving around is not moving the camera.



#2 - Fixed! :smiley: Thank you. Now I can zip around very easily. :slight_smile: Only speed need to be adjusted.



@normen: sorry for posting in the wrong forum. I thought the jME3 area was for exclusively jME3 problems.

So anyone can confirm about #1 or it’s just me?

The ChaseCamera is a control over the viewport camera, it’s not really a camera. It just allow to constraint camera movement around a Spatial target.

I realize it can be confusing… maybe we should call it ChaseCameraHandler or something like that.

If you make your own cam object, it must be attached to a viewport in order you can see through it.

The application class construct the main viewport with the cam object, that’s why we usually use the cam object as the view camera.



you can set the main viewport yourself like that



Camera myCam=…init your cameara…

viewPort = renderManager.createMainView(“Default”, myCam);

shipCam = new ChaseCamera(myCam, playerShip,inputManager);



This will work, but…i don’t really recommend it, because you can just modify the existing cam object according to your needs and it will end in the same result.



About the initialization of your camera

  • Setting the camera location to the exact location of the target spatial should end up in an initial “inside” view of your target model…it can be weird.
  • the cam.lookAt line has no effect, because the chaseCamera constructor sets the lookAt to the spatial target.
  • the cam.update() and cam.updateViewProjection() are not necessary.



    What i would need too to reproduce the issue is the code you use to make the target rotate with the galaxy. Normally, the camera should “follow” the spatial.

    I didn’t test that, but if the ship rotates with the galaxy, and if the camera follow the ship…the result might be that you won’t perceive the rotation anymore on screen. Making this rotation useless.



    Anyway i need to test this to figure out what is wrong.
nehon said:
The ChaseCamera is a control over the viewport camera, it's not really a camera. It just allow to constraint camera movement around a Spatial target.
I realize it can be confusing... maybe we should call it ChaseCameraHandler or something like that.
If you make your own cam object, it must be attached to a viewport in order you can see through it.
The application class construct the main viewport with the cam object, that's why we usually use the cam object as the view camera.

you can set the main viewport yourself like that
`
Camera myCam=...init your cameara...
viewPort = renderManager.createMainView("Default", myCam);
shipCam = new ChaseCamera(myCam, playerShip,inputManager);
`
This will work, but...i don't really recommend it, because you can just modify the existing cam object according to your needs and it will end in the same result.

Noted. One way or the other, it's fine with me really. As long as it works. *shrug*

About the initialization of your camera
- Setting the camera location to the exact location of the target spatial should end up in an initial "inside" view of your target model...it can be weird.
- the cam.lookAt line has no effect, because the chaseCamera constructor sets the lookAt to the spatial target.
- the cam.update() and cam.updateViewProjection() are not necessary.

Those (cam.update(), updateView, etc) were main tests to see if I wasn't forgetting something. Unfortunately, it didn't fix anything. I should've removed them. I had also put those in the update() to see if that would trigger the camera to rotate (on the slim chance it would), but alas that also didn't work. It's just that I commented those out.


What i would need too to reproduce the issue is the code you use to make the target rotate with the galaxy. Normally, the camera should "follow" the spatial.
I didn't test that, but if the ship rotates with the galaxy, and if the camera follow the ship...the result might be that you won't perceive the rotation anymore on screen. Making this rotation useless.

Anyway i need to test this to figure out what is wrong.

I augmented the rotational speed of the galaxy so it would be evident but the result is the same. As you suggested above, I cleaned out what I had, commented out the rotation, but the ChaseCam still sits there as everything rotates around the rootNode.

Anyway. Here's the update() method where the rotation is done. If you have questions, just ask.
[java] @Override
public void update() {
super.update();
// render the viewports
float tpf = timer.getTimePerFrame();
state.getRootNode().rotate(0, .000001f, 0);
stateManager.update(tpf);
stateManager.render(renderManager);
renderManager.render(tpf);
}
[/java]

Rant: I wish there was a "Preview". :(
1 Like

Ok there is a bug indeed.

I’m on it i’ll keep you informed.

Excellent! :slight_smile:

Ok the ChaseCamera now updates regarding the worldTranslation of the target



You can update from last SVN, it should work now.



Thank you for your feed back

Cool! :slight_smile:



Just tested it and although I’m not sure if it was your intention but now not only the camera follows the target it is pointing at (as it rotates) around the rootNode, but the camera also rotates around the geometry as well.

yeah it’s some kind of side effect, the camera moves along a circle around the target so when the distance increase the camera is relocated on this circle…

Is that a problem?



Note that the ChaseCamera movement is likely to change in future releases, I plan to implement some smooth trailing.

1 Like

Don’t worry, it’s not a problem.



As I said earlier, I augmented the rotation speed so it’ll be much slower, thus barely noticeable. It’s all good.



Smoother is good. As long as the chase camera doesn’t simply stop, future changes shouldn’t matter to me.



Great work! :slight_smile: