[SOLVED] How to update the position of nodes?

I feel embarrassed asking this question, but I have been playing with this for a few hours and can’t seem to figure it out. What I am trying to do is very standard and I’m going to feel really dumb when someone tells me what I’m doing wrong.

I am trying to update the positions of about 15 colored spheres. I want to have a sphere for each possible Enum that I have declared in another class. Currently, I have created a class that extends Node that contains an EnumMap<MyEnum, Node>. I initialize this map by adding a Node with an attached Sphere Geometry for every possible Enum. In my Main class I do the following:

SphereMap sphereMap = new SphereMap(assetManager);

This draws all of the spheres in their initial position to the screen just fine. The problem that I am having is moving the spheres once I have attached the SphereMap node to rootNode.

public void setSpherePosition(MyEnum myEnum, Vector3f position) {
    int i = getChildIndex(sphereNodeMap.get(myEnum));
    Node sphere = (Node)getChild(i);

Calls to this method does not change the position of the spheres and I can’t figure out why. I tried calling


and that doesn’t change anything either. The only way I can get the spheres to move is to detach the SphereMap class from rootNode and reattach it which I assume is terribly costly. What am I doing wrong? Also, is the way I am going about this crazy, or standard?

crazy :smile:

Anyway, if you call setLocalTranslation it should move without you having to call anything else.
Try to see with a debugger if that line is actually called at all.

Well, we STRONGLY discourage extending the Node/Spatial/Geometry classes. And in this case it sounds like you’ve overridden something that is screwing with you.

I suspect if you changed your SphereMap to have-a Node instead of be-a-node that it does not really complicate your code any more but will avoid lots of problems.

Other than that, as empire says, setting the local translation sets the position. If not then it is something wrong that we can’t see. Either you aren’t really setting the position of the Spatial you think or you’ve broken the node hierarchy/update stuff somehow. We’d need to see more code.

I moved Node as a member instead of extending it and that fixed my problem. I’m not sure what I was doing exactly, but that fixed my problem.

Yeah, it’s one of those things that you need to know later (a philosophy question, not a technical question). I think we should have a “jME philosophy for dummies” something (note: “dummies” means “noobs”). :chimpanzee_wink:

Anyways, marked as [SOLVED] now. :chimpanzee_smile: