Java 如何在LibGDX中获取模型实例的三维坐标?

Java 如何在LibGDX中获取模型实例的三维坐标?,java,3d,libgdx,coordinates,Java,3d,Libgdx,Coordinates,我想从模型实例中获取三维坐标(作为矢量3)。 使用下面的代码,我只能获得原始坐标,但在渲染方法中,我的模型绕Y轴旋转(同时移动),我希望获得每帧的坐标 我正在使用@Xoppa创建的一个小类: public static class GameObject extends ModelInstance { public Vector3 center = new Vector3(); public Vector3 dimensions = new Vector3(); publi

我想从模型实例中获取三维坐标(作为矢量3)。 使用下面的代码,我只能获得原始坐标,但在渲染方法中,我的模型绕Y轴旋转(同时移动),我希望获得每帧的坐标

我正在使用@Xoppa创建的一个小类:

public static class GameObject extends ModelInstance {
    public Vector3 center = new Vector3();
    public Vector3 dimensions = new Vector3();
    public float radius;

    public BoundingBox bounds = new BoundingBox();

    public GameObject (Model model, String rootNode, boolean mergeTransform) {
        super(model, rootNode, mergeTransform);
        calculateBoundingBox(bounds);
        bounds.getCenter(center);
        bounds.getDimensions(dimensions);
        radius = dimensions.len() / 2f;
    }
}
这是我的代码:

public void render(float delta) {
    super.render(delta);
    if (loading && manager.update()) {
        doneLoading();
    }

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    batch.begin();
    backgroundSprite.draw(batch);
    batch.end();

    for(GameObject instance : instances){
        instance.transform.rotate(new Vector3(0, 1, 0), 0.5f);
        float x = instance.bounds.getCenterX();
        float y = instance.bounds.getCenterY();
        float z = instance.bounds.getCenterZ();
        System.out.println(x+" "+y+" "+z);
        if(isVisible(cam, instance)){
            modelBatch.begin(cam);
            modelBatch.render(instance, environment);
            modelBatch.end();
        }
    }
}

没有函数“getPosition”或类似的东西,都是关于Matrix4的,我从来没有上过关于它的数学课程。我被卡住了。

游戏对象类:

public static class GameObject extends ModelInstance {
    public Vector3 center = new Vector3();
    public Vector3 dimensions = new Vector3();
    public float radius;
    public final Vector3 position = new Vector3();
    public final Quaternion rotation = new Quaternion();
    public final Vector3 scale = new Vector3();

    public BoundingBox bounds = new BoundingBox();

    public GameObject (Model model, String rootNode, boolean mergeTransform) {
        super(model, rootNode, mergeTransform);
        calculateBoundingBox(bounds);
        bounds.getCenter(center);
        bounds.getDimensions(dimensions);
        radius = dimensions.len() / 2f;
    }

    public void updateTransform() {
        this.transform.set(position, rotation, scale);
    }
}`     
它只返回(0,0,0),当我使用updateTransform方法时,它甚至不渲染


很抱歉有这么多答案。我不知道如何在评论部分设置格式:@Xoppa我遵循了你在教程中所做的,但似乎不起作用:这是我的渲染方法:`for(GameObject instance:instances){instance.transform.rotate(new Vector3(0,1,0),0.5f);instance.updateTransform();System.out.println(instance.position);if(isVisible(cam,instance)){modelBatch.begin(cam);modelBatch.render(instance,environment);modelBatch.end();}}}和GameObject类:我不知道如何在注释部分设置格式><很抱歉回答了这么多问题。。