How can I control camera using mouse when it follows along a path?

I want to modify default example “TestCameraMotionPath” from Jme tests.
I need that the camera flies along the path with WayPoints but I control the camera rotation manually (as default flyCam). I need only rotation - no scaling. Right now in the default example I can only call:

cameraMotionControl.setLookAt(teapot.getWorldTranslation(), Vector3f.UNIT_Y);

and see on a specific coordinate in the world. But I need to create a spectacular video and I need to control the direction of the camera manually using mouse.

I think I need to modify something with the ChaseCamera but I can not understand what should I change.

Try having a node follow the path instead of the camera, then place the camera at the world translation of the node.

1 Like

Well, I’m using now this class to control the camera targets:

public class SingleViewPointController {
    
    private final Vector3f target = new Vector3f();
    private Vector3f startCamera, endCamera, startTarget, endTarget;
    private float cameraDX, cameraDY, cameraDZ;
    private float dx, dy, dz;
    
    public SingleViewPointController(Vector3f startCamera, Vector3f  endCamera, Vector3f startTarget, Vector3f endTarget) {
        init(startCamera, endCamera, startTarget, endTarget);
    }
    
    public final void init(Vector3f startCamera, Vector3f  endCamera, Vector3f startTarget, Vector3f endTarget){
        this.startCamera = startCamera;
        this.endCamera = endCamera;
        this.endTarget = endTarget;
        this.startTarget  = startTarget;
        this.cameraDX = endCamera.x-startCamera.x;
        this.cameraDY = endCamera.y-startCamera.y;
        this.cameraDZ = endCamera.z-startCamera.z;
        
        dx = endTarget.x-startTarget.x;
        dy = endTarget.y-startTarget.y;
        dz = endTarget.z-startTarget.z;
    }
    
    public Vector3f getActualTarget(Vector3f actualCameraPos){
        float relative = getRelativePos(actualCameraPos);
        target.x = getStartTarget().x+(dx*relative);
        target.y = getStartTarget().y+(dy*relative);
        target.z = getStartTarget().z+(dz*relative);
        return target;
    }
    
    private float getRelativePos(Vector3f actualCameraPos) {
        float actualX = getEndCamera().x-actualCameraPos.x;
        float actualY = getEndCamera().y-actualCameraPos.y;
        float actualZ = getEndCamera().z-actualCameraPos.z;
        float dX = 1f-(FastMath.abs(actualX/cameraDX));
        float dY = 1f-(FastMath.abs(actualY/cameraDY));
        float dZ = 1f-(FastMath.abs(actualZ/cameraDZ));
       
        float relativeValue = (dX+dY+dZ)/3f;        
        if (relativeValue < 0){
            relativeValue*=(-1f);
        }
        if (relativeValue>1f){
            relativeValue = 1f;
        }
        
        
        return (relativeValue);
    }

    /**
     * @return the startCamera
     */
    public Vector3f getStartCamera() {
        return startCamera;
    }

    /**
     * @return the endCamera
     */
    public Vector3f getEndCamera() {
        return endCamera;
    }

    /**
     * @return the startTarget
     */
    public Vector3f getStartTarget() {
        return startTarget;
    }

    /**
     * @return the endTarget
     */
    public Vector3f getEndTarget() {
        return endTarget;
    }
    
}
1 Like