我有一个绘制贴花的工作代码:
Init:
Decal decal = Decal.newDecal(1, 1,
new TextureRegion(new Texture(Gdx.files.internal("2d/gui/badlogic.jpg"))) );
decal.setPosition(10, 10, 10);
decal.setScale(3);
decals.add(decal);绘制方法:
for (int i = 0; i < decals.size; i++) {
Decal decal = decals.get(i);
decal.lookAt(stage3d.getCamera().position, stage3d.getCamera().up);
batch.add(decal);
}
batch.flush();我有一个用3D编写文本的工作代码:
绘制方法:
spriteBatch.setProjectionMatrix(tmpMat4.set(camera.combined).mul(textTransform));
spriteBatch.begin();
font.draw(spriteBatch, "Testing 1 2 3", 0, 0);
spriteBatch.end();但我很难做一篇直白的文章。
谢谢
发布于 2015-01-31 03:19:38
我不会尝试Decal方法,因为它不是为文本设置的。SpriteBatch已经设置为文本。
( Decal方法理论上可以执行得更好,因为您不需要对每个文本字符串进行单独的抽签调用。但是,您必须提交与Decals兼容的自己版本的BitmapFont和BitmapFontCache。当然,如果这样做,您可以提交一个拉请求并将其添加到libgdx中。)
SpriteBatch代码看起来很熟悉。)基本上,您需要做的是修改textTransform矩阵,使其旋转一个对象来面对摄像机。SpriteBatch被设置为绘制面向Z方向的平面材料。所以你需要旋转一个Z矢量来面对摄像机。
首先,您需要一个可以重用的Vector3。
private static Vector3 tmpVec3 = new Vector3();然后你想要找到从文本中心指向摄像机的矢量。我假设您将文本的位置存储在一个名为Vector3 textPosition的3D空间中:
tmpVec3.set(camera.position).sub(textPosition);
//tmpVec3 is now a vector pointing from the text to the camera.现在你可以定位物体的矩阵,然后旋转它,像这样面对摄像机:
textTransform.setToTranslation(textPosition).rotate(Vector3.Z, tmpVec3);现在,您可以使用textTransform,如您发布的代码中所示。确保将BitmapFont的对齐设置为HAlignment.center,否则文本将围绕文本字符串的左侧旋转,而不是中心。您还可能希望将integer参数设置为false,以便在3D中绘制。
https://stackoverflow.com/questions/28245030
复制相似问题