Hi, this is my problem:
I have n nodes, node i is child of node i-1 and node 0 is child of rootNode. Any node maybe has also another Spatial for child.
target is the point where I want that all the node look at.
When i call node(i).lookAt(target) for the first time everything seems to work properly but then, when i call node(i+k).lookAt(target) the Zaxis of node(i+k) don't point to target.
Do you understand the question? Sorry for my English, Thanks a lot!
Here is the code for 3 nodes:
public class LookAtCanvas extends SimpleGame{
@Override
protected void simpleInitGame() {
//the target to lookAt
Sphere target = new Sphere("target",10,20,1);
target.setLocalTranslation(new Vector3f(10,20,10));
Node n = new Node("nodeS");
rootNode.attachChild(target);
rootNode.updateGeometricState(0, true);
//setup the nodes with their object and debug axis
Sphere s1 = new Sphere("theSphere1",10,20,1);
Sphere s2 = new Sphere("theSphere2",10,20,1);
Sphere s3 = new Sphere("theSphere3",10,20,1);
Node n1 = new Node("theNode1");
Node n2 = new Node("theNode2");
Node n3 = new Node("theNode3");
n1.attachChild(s1);
n2.attachChild(s2);
n3.attachChild(s3);
n1.setLocalTranslation(new Vector3f(0,3,0));
n2.setLocalTranslation(new Vector3f(0,6,0));
n3.setLocalTranslation(new Vector3f(0,9,0));
AxisRods arA = new AxisRods("TheRodsA");
arA.setLocalScale(1);
n1.attachChild(arA);
AxisRods arB = new AxisRods("TheRodsB");
arA.setLocalScale(1);
n2.attachChild(arB);
AxisRods arC = new AxisRods("TheRodsC");
arA.setLocalScale(1);
n3.attachChild(arC);
n1.attachChild(n2);
n2.attachChild(n3);
rootNode.attachChild(n1);
rootNode.updateGeometricState(0, true);
// The first lookAt... correct
n2.lookAt(target.getWorldTranslation(), new Vector3f(0,1,0));
rootNode.updateGeometricState(0, true);
// The second lookAt... there's a problem, wrong orientation...
n3.lookAt(target.getWorldTranslation(), new Vector3f(0,1,0));
rootNode.updateGeometricState(0, true);
}
public static void main(String[] args) {
Logger.getLogger("").setLevel(Level.WARNING);
LookAtCanvas game = new LookAtCanvas();
game.setConfigShowMode(ConfigShowMode.ShowIfNoConfig);
game.start();
}
}
and a screenshoot:
