Documentation for using Camera in jME3

I didn't find any reliable documentation/example of using a camera in jME3. (There's the FlyByCam in the SimpleApplication class, but I'd like to see more.



I'll be glad for a reference.



Thanks!

I think there will be doc about it in future.

but what do you want to do with camera ?

moving,rotating, zoom in,out ?

if only those four then these 2 codes is enough (+ a bit of tweaking)



cam.setLocation(new Vector3f(x,y,z));

cam.lookAt(new Vector3f(x,y,z));



that is all I know about cam.  I think you can also define the width, height of camera (from a normal screen view you will get a side screen view) and so on, but  :smiley: I dont know how to do it yet

yeah, if you use eclipse then just type "cam." then you will see a lot of option, and you might find something interesting.

good luck with conquering camera  :evil:


How do I animate the camera movement?



I want the camera to slide towards point X at a certain speed. How can I do that?

I can think of a couple ways to do this, depending on your intended feature and the input that is causing the movement in the camera.


  1. You could simply extend FlyByCamera and override onAction or onAnalog. onAnalog seems to make the most sense to me since you'll want to interpolate the movement.


  2. You could extend FirstPersonCamera and override onBinding and/or onPostUpdate and/or onPreUpdate.



    I haven't done this myself in jme3 yet, but from reading the javadocs, this is my first impression on how I'd do it. Hope it helps.

nehon made a chaseCam. Test it and give feedback.

As i understand, you want to make some kind of "traveling" without the user intervention.

Making camera goes from point A to point B in a defined amount of time.

Is that it?



If that's what you want to do, my chaseCam won't help you that much, but it could give you ideas.



If i were you i would make some kind of CameraTravelingHandler that holds the camera with a startPosition, endPosition , animationLenght (in seconds or frames…)

on each update the handler could do some linear interpolation of the camera position and move the camera accordingly.



This kind of tool would be very handy for cinematic purpose.

Hi! I hope this is the appropriate thread. Is there any way to add an alternative set of controls for flyCam? I use the wiimote and I can interact with geometry objects but I need some help for the flyCam. What should I do if wanted to replace the current set of controls of flyCam?

Well a assume the wiimote is considered as a Joystick



in flybycamera code there are those lines



// both mouse and button - rotation of cam
        inputManager.addMapping("FLYCAM_Left", new MouseAxisTrigger(0, true),
                                               new KeyTrigger(KeyInput.KEY_LEFT));

        inputManager.addMapping("FLYCAM_Right", new MouseAxisTrigger(0, false),
                                                new KeyTrigger(KeyInput.KEY_RIGHT));

        inputManager.addMapping("FLYCAM_Up", new MouseAxisTrigger(1, false),
                                             new KeyTrigger(KeyInput.KEY_UP));

        inputManager.addMapping("FLYCAM_Down", new MouseAxisTrigger(1, true),
                                               new KeyTrigger(KeyInput.KEY_DOWN));



But i don't see any JoyAxisTrigger in source code, maybe this feature is not implemented yet.

Thanks for your response!



Where is that code you showed me? When I looked at it, I saw the following code:

package com.jme3.input;

import com.jme3.collision.MotionAllowedListener;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;

public class FlyByCamera implements AnalogListener, ActionListener
{

    private Camera cam;
    private Vector3f initialUpVec;
    private float rotationSpeed;
    private float moveSpeed;
    private MotionAllowedListener motionAllowed;
    private boolean enabled;
    private boolean dragToRotate;
    private boolean canRotate;
    private InputManager inputManager;

    public FlyByCamera(Camera cam)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void setMotionAllowedListener(MotionAllowedListener listener)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void setMoveSpeed(float moveSpeed)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void setRotationSpeed(float rotationSpeed)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void setEnabled(boolean enable)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public boolean isEnabled()
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public boolean isDragToRotate()
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void setDragToRotate(boolean dragToRotate)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void registerWithInput(InputManager inputManager)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    private void rotateCamera(float value, Vector3f axis)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    private void zoomCamera(float value)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    private void riseCamera(float value)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    private void moveCamera(float value, boolean sideways)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void onAnalog(String name, float value, float tpf)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    public void onAction(String name, boolean value, float tpf)
    {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }
}



The wiimote is somehow invisible and is not considered anything. I use an independent program called OSCulator (http://www.osculator.net/)  which translates wiimote actions as OSC messages (imagine like xml - not the syntax). Then I use a Java OSC Api to interact wiimote with java programs. It is independent from Jmonkey, I mean that I cannot extend Trigger class and have similar mapping like the ones the HelloImput tutorial describes, or at least I do not know the way yet.

So if I learn how to add alternative controls or change the current ones for flycam in Jmonkey way, I know how to do it with java osc api as well.
nehon said:

As i understand, you want to make some kind of "traveling" without the user intervention.
Making camera goes from point A to point B in a defined amount of time.
Is that it?


Exactly! I want it to be treated as animation. None of the mentioned examples helped me.



If that's what you want to do, my chaseCam won't help you that much, but it could give you ideas.

If i were you i would make some kind of CameraTravelingHandler that holds the camera with a startPosition, endPosition , animationLenght (in seconds or frames...)
on each update the handler could do some linear interpolation of the camera position and move the camera accordingly.

This kind of tool would be very handy for cinematic purpose.



Yeah, but that's means implement tweening and animating myself. I was hoping for a more solid animation support, something along the line of:

neq Animation.sequence(new Animation[] {Animation.moveCameraTo(v),new Animation.parallel(new Animation[] {Animation.scaleTo(player,2f),Animation.moveCameraTo(v+u)})});

Which will be triggered when some event happens, and which I could poll and ask if the animation is done yet.

I think a custom Controller is probably your best bet. When you're ready for the animation sequence to take effect, you can simply attach the Controller (that has references to your camera) and the Controller is then able to do all sorts of things to the camera over time without any user input whatsoever. When the animation sequence is done, you can detach it.

Is there a reference about attaching a controller to a game?

I'm wondering the same as Elazarl. Were Controllers from jME2 removed from jME3? Or are they basically the same thing and need to be moved into jME3 yet? I've been starting to wonder how I'd get by without controllers or bring the old ones back, but I haven't gotten around to looking at the old jME2 implementation yet.

There are controllers in jME3, they are called Controls. Essentially its the same thing except you can also receive rendering callbacks and they are executed independently of updateGeometricState()