ChaseCamera: Pos, LookAt, Rotation Center

Hello,

I want follow an object with my camera. I use the ChaseCamera and everything works fine. But I can not set the Position of my camera only distance is allowed.

Next I want set the lookAt direction of my camera. The last step is the rotation center of my object.
Rotation center means this point where the node rotates around.

            chaseCam = new ChaseCamera(cam, nodeMeasurement, inputManager);
            chaseCam.setZoomSensitivity(0.1f);
            chaseCam.setMinVerticalRotation(-FastMath.HALF_PI / 2f);
            chaseCam.setInvertVerticalAxis(true);

That’s my only code. I try to set the position of my camera like this:

cam.setLocation(new Vector3f(aPosX, aPosY, aPosZ));
cam.lookAt(new Vector3f(aLookAtX, aLookAtY, aLookAtZ), Vector3f.UNIT_Y);

But this has no effect. How can set this attributes and rotation center?

As to the center that the ChaseCam follows, thats the center of the spatial you give to it. Add a node (or a hierarchy of nodes with your model to have one node at the position you deem correct.

Otherwise you have three options:

a) move the camera
b) let the ChaseCam move the camera
c) have your own control move the camera

Among these options c) can also be a control that extends ChaseCam and adds your own code to alter its behavior.

Is it posible to have different lookat position and rotation center?

As to the center that the ChaseCam follows, thats the center of the spatial you give to it. Add a node (or a hierarchy of nodes) with your model to have one node at the position you deem correct.

Ok. I have set the node in the desired position. For example “new Vector3f(0,0.5f,0)”

Now the position of my camera should be “new Vector3f(1,1,1)”.
How can I set the position of my camera. Is it possible or I have to calculate the rotation angle.

  1. remove the ChaseCam
  2. cam.setPosition(new Vector3f(1,1,1));
  3. cam.lookAt(new Vector3f(0,0.5f,0));

(do that in each frame for each new position)

I need the zooming behavior and the rotation behavior. This works great with ChaseCam.

But I need an initial view on my model. After that the user can rotate and zoom the model in front of my camera. But not the postion or rotation angle of my model should not be changed only the camera position.

There is a setLookatOffset method that offset the target of the chase cam.

In Java 3D exists a class named OrbitBehavior. I have goolged but I didn’t find an equivalent in jmonkey.

Ok. I try to write my own.
May be someone can help me with the math?

I want rotate one point around another point. Like a clock.
More details:

    private void rotateCamera(float value) {
        // the parameter value comes from the movement of my mouse. This value 
        // should be move the camera around a Vector rotationCenter  
    }

Use the scene graph. Attach some nodes… rotate the parent or the child… whatever you need to get done.

Don’t do the math yourself… that’s a sucker’s game.

The best thing I want do is:

public class TestChaseCamera extends SimpleApplication {

    @Override
    public void simpleInitApp() {
        Sphere sphereX = new Sphere(20, 50, 0.5f);
        Geometry gX = new Geometry("SX", sphereX);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Red);
        gX.setMaterial(mat);
        gX.setLocalTranslation(Vector3f.ZERO);
        rootNode.attachChild(gX);
        ChaseCamera cc = new ChaseCamera(cam,gX, inputManager);
        cam.setLocation(Vector3f.UNIT_XYZ.mult(3));
    }

    public static void main(String args[]) {
        new TestChaseCamera().start();
    }
}

But the Position of the camera is not 3,3,3, else “Camera Position: (17.320509, 10.0, 0.0)”.
If I could set the initial position of the camera, this is the best solution.