I'm trying to make 2 Cylinders rotate on their own Y-axis, but everytime they rotate around the rootNode axis. Is there a way to get them to rotate around their own axis? Couldn't find a clear answer on the googles.
Cylinder1 and Cylinder2 are the Nodes that have been made
I also tried attaching both Cylinders to the rootNode and using rootNode.rotate();
public class Main extends SimpleApplication {
Node cylinder1;
Node cylinder2;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
cylinder1 = new Node();
cylinder2 = new Node();
cylinder1 = cylinderCreate(-3, fles1, false);
cylinder2 = cylinderCreate(3, fles2, true);
rootNode.attachChild(cylinder1);
rootNode.attachChild(cylinder2);
}
public Node cylinderCreate(float f, Node n, boolean b)
{
Cylinder cyl = new Cylinder(32, 32, 1.0f, 4, true); // closed body
Geometry geomcyl = new Geometry("Cylinder", cyl);
Material matcyl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
geomcyl.setLocalTranslation(f, 0f, 0f);
matcyl.setTexture("ColorMap", assetManager.loadTexture("Interface/sdfg.jpg"));
geomcyl.setMaterial(matcyl);
float pi = FastMath.HALF_PI;
geomcyl.rotate(pi*3, 0, 0);
n.attachChild(geomcyl);
return n;
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
cylinder1.rotate(0, 2*tpf, 0);
cylinder2.rotate(0, 2*tpf, 0);
}
Fixed it, i had to change the f in SetLocalTranslation in cylinderCreate to 0,
and add n.move(fl, 0, 0); to cylinderCreate just before returning n.