[SOLVED] Moving the Scenegraph

Monkeys, I need your help again!
I’m not sure why I can’t wrap my head around the simplest things…

I have a Scenegraph that loads geometries from a file into the scene. What I want now is to fix he whole handling of the scene.
When you click (and hold) left mouse-button the scene should lock on the centre of the first geometry and you should be able to rotate the WHOLE scene (including the coordinate system; with the first geometry as the centre)!
When you click (and hold) right mouse-button you should be able to move the whole scenegraph around. Like grabbing the coordinate system and just move it e. g outside the camera view (with like only up and down as an option).

I really have no clue how to achivie this. I played around with the camera. I worked with a simple initKey. But I don’t know how I can do this.
If my explanation was a litte unclear, please ask for details…

Help would be really apriciated. I’ve been stuck on this for a few days now…

You could attach the whole scene to a node, and rotate that. But the easier way would be to re-position and rotate the camera around the center of your geometry - either way, the best solution would be to use a pivot node.

(see this intro doc for basic example on how to offset a child node and use its parent as a pivot node- you’ll also find this functionality to be useful for many other things down the line https://wiki.jmonkeyengine.org/jme3/beginner/hello_node.html#understanding-the-code)

Essentially, you will want to create two nodes: one that is at the center of your scene (the pivot point that you are looking at and rotating around) and a second node (the orbital node) that gets attached to the pivot node.
You can then offset the orbital node by a distance of your choice (often times this distance is also scaled by the mouse scroll wheel), and then when you rotate its parent, the child node will rotate with a smooth orbit around the central pivot point.

After that, all you need to do is set the camera’s location to be the same as the orbital node, and call the camera.lookAt() method to make the camera look at the center pivot point.

Edit: there is also a FocusCamera appState that you can quickly get on the JMonkeyStore if it appears to suit your needs jMonkeyEngine | Library

1 Like

This pointer is worth gold!!!
Thank you so so much! I can actually work with this!
(Sorry for not replying sooner. There was Christmas Vacation time and then I was sick for 2 weeks :D)

1 Like