0

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.

Freerk92
  • 55
  • 1
  • 9
  • Can you give some code you used to do the rotation? – J. Rahmati Sep 12 '14 at 19:06
  • I haven't tested this yet, but have you tried using setLocalRotation instead? Also if you are importing a blender file, then make sure the cylinder is centered inside blender before importing. – J. Rahmati Sep 17 '14 at 18:28
  • It often makes it easier to think about if you put several nodes inbetween the rootnode and the object. I often like to do rootnode--translationNode--localRotationNode--translationFromLocalCentreNode(optional)--object. That way its obvious what happens first – Richard Tingle Sep 20 '14 at 17:10

0 Answers0