Translating Model Problem

Hi, I have a node containing an imported 3DS model and a simple Box shape attached to the same Node.

When I translate both the model and box with the same coordinates only the box moves



Here is the code for initiating the shapes



location = new Vector3f(0, 0, -15);

setLocalTranslation(location);

// test model
model = DataHandler.loadModel("plane.3ds");
model.setLocalScale(0.25f);
model.setModelBound(new BoundingBox());
model.updateModelBound();

// test box
box = new Box("Box", new Vector3f(0,0,0), 1, 1, 1);
box.setModelBound(new BoundingBox());
box.updateModelBound();

attachChild(model);
attachChild(box);



And here is the code for updating its position:


public void update(float time) {
   location = getLocalTranslation();

   location.x += (velocity.x * time);
   location.y += (velocity.y * time);

   setLocalTranslation(location);

   model.setLocalTranslation(location);
   box.setLocalTranslation(location);
}



Im probably missing something really simple but I just cant get the model to move!

did you call updateGeometricState() ?

No I didn't, told you it would be simple.

(Then why didn't the sphere move without updating its geometric state?)

The local translation and rotation of nested nodes is precalculated in what is called the world translation and rotation



jME uses the World translation and rotation vector/quaternion to render geometry.



When you alter the Local translation of a node you have to tell jME that it has to recalculate all the world translation and rotation data that hangs from that node. That way, when jME renders that geometry again it can set up the correct matrixes in the graphics card.



Hope it helps.


And the box moved because calling setLocalXXX automatically also sets the worldXXX field at that scenegraph point.