在Libgdx中剪切3D模型

时间:2016-03-06 18:17:57

标签: java android libgdx

我开始在Android中使用libgdx来绘制一些3D模型。现在我有2个剪切矩阵,我想应用于我拥有的立方体。问题是我不知道我必须在哪里进行矩阵乘法。在使用纯OpeGL ES2时,我知道我在onDrawFrame中使用我的Renderer类中的modelMatrix执行所有这些操作。但是在libgdx中我有一个modelInstance和render()方法。任何人都可以告诉我如何将矩阵乘法应用于我的模型?

public class Basic3DTest implements ApplicationListener {
    public PerspectiveCamera cam;
    public ModelBatch modelBatch;
    public Model model;
    public ModelInstance instance;

    @Override
public void create () {
    modelBatch = new ModelBatch();

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    ...
    cam.update();

    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, 
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
    instance = new ModelInstance(model);
}

@Override
public void render () {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(cam);
    modelBatch.render(instance);
    modelBatch.end();
}

@Override
public void dispose () {
    modelBatch.dispose();
    model.dispose();
}

0 个答案:

没有答案