如何在jMonkey中在自己的轴上旋转多个节点

时间:2014-09-11 13:08:49

标签: java rotation jmonkeyengine

我正在尝试让2个圆柱体在它们自己的Y轴上旋转,但每次它们围绕rootNode轴旋转。有没有办法让它们围绕自己的轴旋转?无法在谷歌上找到一个明确的答案。

Cylinder1和Cylinder2是已经制作的节点 我还尝试将两个Cylinders连接到rootNode并使用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);
}

修正了它,我不得不将cylinderCreate中SetLocalTranslation中的f更改为0,
并添加n.move(fl,0,0);在返回n之前创建cylinderCreate。

0 个答案:

没有答案