我希望能够在模型之上绘制文字。
我希望能够在绿线顶部添加文字。但是,我无法使用正确的投影显示2d文本。我有一个移动的摄像头,中间的车也在移动。
spriteBatch.setProjectionMatrix(camera.combined);
这使文本出现在相机的背面(意味着较小的z值)。我把所有的车都放在了Vector3
。我有侧面代码的以下代码;
public class SideCar extends Car {
public enum Side {
LEFT, RIGHT
}
protected Side side;
protected String plate;
protected ShapeRenderer shapeRenderer;
protected Vector3 sideCarV3;
protected Texture texture;
public SideCar(AssetManager assetManager, Side side, String plate) {
super(assetManager);
this.id = "side_car";
this.side = side;
this.plate = plate;
if (side == Side.LEFT) {
instance.transform.translate(-35f, 0f, 10f);
} else { // right
instance.transform.translate(35f, 0f, 10f);
}
shapeRenderer = new ShapeRenderer();
shapeRenderer.setColor(Color.GREEN);
sideCarV3 = new Vector3();
texture = new Texture(Gdx.files.internal("data/font/avenir.png"), true); // true enables mipmaps
texture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.Linear);
}
@Override
public void renderModel(float deltaTime, Scene scene) {
super.renderModel(deltaTime, scene);
scene.modelBatch().render(instance, scene.environment());
//scene.modelBatch().render(texture, scene.environment());
// public final void line (float x, float y, float z, float x2, float y2, float z2)
sideCarV3 = instance.transform.getTranslation(sideCarV3);
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setProjectionMatrix(scene.camera().combined);
shapeRenderer.identity();
if (side == Side.LEFT) {
shapeRenderer.line(2.5f, 0f, sideCarV3.z, 2.5f, 1.5f, sideCarV3.z);
shapeRenderer.line(2.5f, 1.5f, sideCarV3.z, 2.4f, 1.5f, sideCarV3.z);
} else {
shapeRenderer.line(-2.5f, 0f, sideCarV3.z, -2.5f, 1.5f, sideCarV3.z);
shapeRenderer.line(-2.5f, 1.5f, sideCarV3.z, -2.4f, 1.5f, sideCarV3.z);
}
shapeRenderer.end();
}
@Override
public void renderSprite(float deltaTime, Scene scene) {
instance.transform.getTranslation(sideCarV3);
if (side == Side.LEFT) {
} else {
infoFont.draw(
scene.spriteBatch(),
String.format(Locale.US, "%d km/h", (int) (speed * 100)), sideCarV3.x, sideCarV3.y + 5f
);
}
}
}
任何想法将文本放在绿线顶部的想法?