この簡単なチュートリアル
blog.xoppa.com/basic-3d-using-libgdx-2/を実装
していますが、パースペクティブ カメラを正投影カメラに置き換えようとしています。
ただし、カメラの位置がどのように機能するかを理解するのにいくつか問題があります
。
cam2 = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam2.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam2.position.set(0,0,10);
cam2.lookAt(0, 0, 0);
cam2.update()
非常に小さな正方形が得られます。立場を変えれば。
cam2.position.set(0,0,100);
正投影カメラは z を無視するはずなので、何も見えません。
基本的に必要なのは、3D 形状を作成し、それを 2 つの異なるビューで同時に表示することです。1 つはパースペクティブ カメラを使用し、もう 1 つは正投影カメラを使用します。
ありがとう!
ここに完全なコードがあります
public class MyGdxGame implements ApplicationListener {
// public PerspectiveCamera cam;
public OrthographicCamera cam2;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;
@Override
public void create() {
modelBatch = new ModelBatch();
// cam = new PerspectiveCamera(67, Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
cam2 = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam2.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
// cam.position.set(10f, 10f, 10f);
// cam.lookAt(0, 0, 0);
// cam.near = 1f;
// cam.far = 300f;
// cam.update();
cam2.position.set(0, 0,0);
cam2.lookAt(0, 0, 0);
cam2.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(50f, 50f, 50f,
new Material(ColorAttribute.createDiffuse(Color.GREEN)),
Usage.Position | Usage.Normal);
instance = new ModelInstance(model);
}
@Override
public void render() {
cam2.update();
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();
//
// Gdx.gl.glViewport(Gdx.graphics.getWidth()/2, 0, Gdx.graphics.getWidth()/2,
// Gdx.graphics.getHeight()/2);
//
modelBatch.begin(cam2);
modelBatch.render(instance);
modelBatch.end();
}
@Override
public void dispose() {
modelBatch.dispose();
model.dispose();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}