Issue with rotation?

Hi…

I want to arrange several objects along a circle, centred at 0,0,0.

So I make a temporary node, place it at 0,0,0 and then attach the object to thise node.

Then I call rotate on temp node, then I detach the object and then attach next object again call rotate on temp node and so on.



But objects are not showing any effect…they are still at their initial positions.

What wrong I am doing?



Manish

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

The question is why do you do that, you most probably can better use a vector that you rotate using a quaternion to determine the location of the spatials.

//here is my code



private void initCoinsSetUp(){

Node temp_node = new Node();

rootNode.attachChild(temp_node);

temp_node.move(0,0,0);

Material whitecoin_mat = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);

whitecoin_mat.setColor(“Color”, new ColorRGBA(204/255f,179/255f,51/255f,0f));

for(int i=0;i<6;i++){

Geometry white_coin = new Geometry(“WhiteCoin_”+i, coin_shape);

white_coin.setMaterial(whitecoin_mat);

white_coin.move(.1f,.052f, 0);//to bring it on a platform, workign OK

white_coin.rotate(-FastMath.HALF_PI,0,0);//to bring coin parallel to platform,working OK

temp_node.attachChild(white_coin);

rootNode.attachChild(temp_node);

temp_node.rotate(0f,FastMath.HALF_PI/3i,0f);

temp_node.detachChild(white_coin);

temp_node.rotate(0f,-FastMath.HALF_PI/3
i,0f);//so that next rotation is wrt base line

rootNode.attachChild(white_coin);

white_coins.add(white_coin);

}

}

Why do you attach temp_node over and over again?

He wants the nodes to do math for him I suppose. If he would read “math for dummies” and do what I say it would make his life much easier ^^ @mghildiy: math is not like in school in jME3, its as easy as moving around nodes really, if not easier when I look at your code xD

I will be generous this morning and recomment your code for you. I’ll also add the java blocks so it actually looks like code…


@mghildiy said:
//here is my code
[java]
private void initCoinsSetUp(){
Node temp_node = new Node();
// Make temp_node a part of the scene graph
rootNode.attachChild(temp_node);

// Move temp node 0 distance
temp_node.move(0,0,0);

Material whitecoin_mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
whitecoin_mat.setColor("Color", new ColorRGBA(204/255f,179/255f,51/255f,0f));
for(int i=0;i<6;i++){
// Create one of six coins
Geometry white_coin = new Geometry("WhiteCoin_"+i, coin_shape);
white_coin.setMaterial(whitecoin_mat);
// Move the coin 10 centemeters right and 5.2 centemeters up
white_coin.move(.1f,.052f, 0);//to bring it on a platform, workign OK
// Rotate the coin around its own X axis
white_coin.rotate(-FastMath.HALF_PI,0,0);//to bring coin parallel to platform,working OK
// Make the coin part of the scene graph
temp_node.attachChild(white_coin);
// Remove temp_node from the scene graph and make it a part of the scene graph again (a no-op)
rootNode.attachChild(temp_node);
// Rotate temp_node around its own Y axis relative to its current rotation
temp_node.rotate(0f,FastMath.HALF_PI/3*i,0f);
// Remove the coin from the scene graph so that it NO LONGER HAS THE TRANSFORM OF ITS PARENT
temp_node.detachChild(white_coin);
// Rotate the childless temp_node back to its starting rotation
temp_node.rotate(0f,-FastMath.HALF_PI/3*i,0f);//so that next rotation is wrt base line
// Make the coin part of the scene graph again WITH ONLY ITS LOCAL ROTATION
rootNode.attachChild(white_coin);
white_coins.add(white_coin);
}
}
[/java]


Read them, live them, learn them:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

Hi Normen, I now got what u want me to do with vector rotation. Thanks for putting me on right track.



I have a question though. If I detach a child node from its parent node and add it to rootNode of scenegraph(which I am doing in above code, though this code is now no more valid) then why does the node comes back to its original position.Should not it preserve its positional information?

Read the comments paul made in your code again. The local translation of the spatial never changes.

Yeah, my last comment would be more accurate:

// Make the coin part of the scene graph again WITH ONLY ITS LOCAL TRANSFORMATION