Problems with getting my controls right, absolute jme3 beginner

Hello everybody,

I am quite desperate since I am not able to get my camera (mouse) controls right. I have basically a plane map (x,y) where I look upon from above (not isometric)

I am trying to make controls similar to google earth controls. So the wasd keys move the plane left right, forward backwards,

pressing the right mouse button toggles rotation, that means moving the mouse left or right rotates the plane on the Z axis, Up down rotates on the X Axis.

So I have Floor Node where all the geometries are attached. then I have a flatCamNode attached to the FloorNode the moves along the plane and rotates on its Z axis., attached to this I have a XrotationNode, that rotates along its X Axis where also the camera node is attached.

Now when I rotate on the Z Axis (the flatCamNode) it looks fine, but when I move it again it of course moves realtive to the Floornode, and not in the direction of the camera.

When I change the code and move the X rotation node instead, it moves in the direction I am looking at, but the the Z rotation is always at the flatCamNode original position, since I didn’t move it, and not at the point where I am looking at.

Here is the code: its in scala, not in java, but should be understandable nonetheless:

[java]

val floorNode = new Node(“Floor”)

rootNode.attachChild(floorNode)

val camFlatNode = new Node(“camFlat”)

camFlatNode.setLocalTranslation(mapDimX/2, mapDimY/2, 0)

floorNode.attachChild(camFlatNode)

val XrotationNode= new Node(“camAttach”)

camFlatNode.attachChild(XrotationNode)

val camNode = new CameraNode(“CamNode”, cam);

XrotationNode.attachChild(camNode)

camNode.setControlDir(ControlDirection.SpatialToCamera)

camNode.setLocalTranslation(new Vector3f(0, 0, 70));

camNode.lookAt(camFlatNode.getLocalTranslation, Vector3f.UNIT_Y)

flyCam.setEnabled(false);

def onAnalog(name: String, value: Float, tpf: Float) {

direction.set(Vector3f.ZERO).normalizeLocal

if (name==“moveForward”) {

direction.y = +10tpf

camFlatNode.move(direction)

}

if (name==“moveBackward”) {

direction.y = -10
tpf

camFlatNode.move(direction)

}

if (name==“moveRight”) {

direction.x = +10tpf

camFlatNode.move(direction)

}

if (name==“moveLeft”) {

direction.x = -10
tpf

camFlatNode.move(direction)

}

if (name==“rotateRight” && rotate) {

camFlatNode.rotate(0, 0, 1.5f * tpf)

}

if (name==“rotateLeft” && rotate) {

camFlatNode.rotate(0, 0, -1.5f * tpf)

}

if (name==“rotateUp” && rotate) {

XrotationNode.rotate(1.5f * tpf, 0 , 0)

}

if (name==“rotateDown” && rotate) {

XrotationNode.rotate(-1.5f * tpf, 0 , 0)

}

}

[/java]

How can I set it, that the camFlatNode “remembers” its Z rotation, and moves accordingly, so always relative to the direction I am looking at. It’s probably simply math, but I couldn’t find a way.

Of course I could simply rotate all my geometries on a centre Z axis, but then I get problems with picking, since I want to select single squares on the map.

Thanks for your help, I hope it is somehow clear what I meant :wink:

Dan