Java3d:如何在 Java 3d 场景上编辑绘制的 2d 叠加层?
我使用的技术回答了这个问题:Java3D:在 Canvas3D 上绘制 2D HUD
我的代码是这样的:
...
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config){
public void postRender()
{
this.getGraphics2D().setColor(Color.white);
this.getGraphics2D().drawString("Heads Up Display (HUD) Works!",100,100);
this.getGraphics2D().flush(false);
}
};
...
我以后如何删除这个 2D HUD 或编辑这个 2D HUD?
I used the technique answered this question: Java3D: Painting 2D HUD over a Canvas3D
And my code is something like this:
...
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config){
public void postRender()
{
this.getGraphics2D().setColor(Color.white);
this.getGraphics2D().drawString("Heads Up Display (HUD) Works!",100,100);
this.getGraphics2D().flush(false);
}
};
...
How could I later remove this 2D HUD or edit this 2D HUD?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果渲染完全从头开始渲染每个帧,您可以在与 postRender() 方法相同的类中添加静态布尔值。然后在方法内部使用 if 语句检查布尔值是否为 true,否则不执行任何操作,如果您通过
HUD 不应显示将布尔值设置为 false。至于更改它,这是可能的,并且实际上取决于您想要显示的信息类型。这是我用于游戏的示例,但它可以适合多个主题。
我想要存储 FPS、x、y 和 z 位置如果我正在开发游戏,那么我要做的就是在类中为我需要显示的每个属性创建一个变量,然后是这样的:
另外,如果您请注意,我将 G2D 设置为等于 this.getGraphics2D(),这样我每次想使用 Graphics2D 对象时都不需要调用外部方法,每次调用 getGraphics2D() 时它都必须转到该类,调用那方法,并返回值,与仅获取一次并使用它相比,更快的类型类型,从长远来看会产生更快的速度。
毕竟我要做的是我可以将每个变量设置为正确的值,它会显示,这是更新它的一种方法,你可以做类似的为每一行创建一个变量,然后去:
If the render renders each frame completely from scratch, you can add, for example, a static boolean in the same class with your postRender() method. Then inside the method use an if statment to check if the boolean if true, otherwise don't do anything, if you then set the boolean to false via
The HUD should not show. As for changing it, that's possible, and would really depend on what type of information you want to show. Here is an example I'd use for games, but it can fit several subjects.
I would want to store FPS, x, y, and z positions If I was working on a game, so what I would do is create a variable inside the class for each attribute I needed to display, then something like this:
Also if you notice I set G2D equal to this.getGraphics2D(), that way I didn't need to call an external method each time I wanted to use the Graphics2D object, each time you call getGraphics2D() it has to go to that class, call that method, and return the value, as compared to just getting it once, and using it, faster type type, and in the long run creates faster speeds.
What I would do after all this is I could just set each variable to the correct value, and it would display, that's one way of updating it, you could do similar make a variable for each line, and go: