使用3D

时间:2017-06-09 14:43:02

标签: java libgdx

让我解释一下我在这里尝试的内容: 我的应用程序大部分都会使用3d渲染,但是对于开发和调试,我尝试使用ShapeRenderer来绘制路径,调试碰撞等。

但我无法在屏幕上显示任何内容,而且我输了。我怀疑相机问题,但请建议并提出解决方案。这就是我正在做的事情:

public void create () {
  assets = new AssetManager();
  assets.load("button.g3db", Model.class);

  camera = new PerspectiveCamera(75, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
  camera.position.set(0f, 0f, 5f);
  camera.lookAt(0f,0f,0f);
  camera.near = 1f;
  camera.far = 100.0f;

  shapeRenderer = new ShapeRenderer();
  shapeRenderer.setProjectionMatrix(camera.combined);

  modelBatch = new ModelBatch();

  //some Bezier curve to draw for debuging
  Bezier<Vector3> points = ButtonUtils.getButtonEscapePath();
  int k = 100;
  pointsArray = new Vector3[k];
  for(int i = 0; i < k; ++i)
  {
    pointsArray[i] = new Vector3();
    points.valueAt(pointsArray[i], ((float)i)/((float)k-1));
  }

  environment = new Environment();
  DirectionalLight light = new DirectionalLight();
  light.set(0.8f, 0.8f, 0.8f, new Vector3(-1f, -0.8f, -0.2f));
  environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
  environment.add(light);
}

public void render () {
  Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  Gdx.gl.glClearColor(0, 0, 0, 1);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
  camera.update();

  modelBatch.begin(camera);
  modelBatch.render(button, environment);
  modelBatch.end();

  //drawing debug circles around 3D object
  shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
  shapeRenderer.setColor(Color.WHITE);
  shapeRenderer.circle(button.getPosition().x, button.getPosition().y, 50f, 50);
  shapeRenderer.end();

  //drawing Bezier curve
  int k = 100;
  shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
  for(int i = 0; i < k-1; ++i)
  {
    shapeRenderer.line(pointsArray[i], pointsArray[i+1]);
  }
  shapeRenderer.end();
}

编辑:微小的修正,我可以在屏幕上得到一些东西,我的意思是3D模型显示得很好,它的ShapeRenderer东西不会显示。

0 个答案:

没有答案