在 Java 3D 场景中绘制清晰的生命条

发布于 2024-10-05 08:00:41 字数 656 浏览 14 评论 0原文

因此,我正在使用 Java 3D 开发一款游戏,并且正在实现悬停在单位上方的生命条。

我首先在设备位置上方的 3D 点处绘制一个四边形,并应用 Billboard 行为使其始终面向相机。

但我遇到的问题是,生命条有时会被其他风景遮挡。

因此,我正在考虑以下选项:

  1. 覆盖生命条像素的 Z/深度缓冲区值,以使渲染器认为它们比之后渲染的任何内容都更接近相机。

    我尝试了renderingAttributes.setDepthTestFunction(RenderingAttributes.ALWAYS)。虽然它使渲染器将生命条绘制在之前在同一区域绘制的任何内容的顶部,但当稍后将其他风景绘制在生命条顶部时,它没有帮助。

    在 Java 3D 中是否有更好的方法来执行此操作?

  2. 将生命条的 3D 位置投影到相机前面的 2D 平面上。听起来可行,但在我开始重新发明所需的所有数学之前,也许有人可以指出现有的解决方案。

  3. 从 Java 3D 切换到 LWJGL 或 jMonkeyEngine 之类的东西(不仅仅是因为这个问题,还有关于 Java 3D 已死的普遍抱怨等)。尽管我什至不确定它们对于这个特定问题是否更灵活。据我所知,游戏开发中最严重的错误之一是在开发中期切换引擎。

So I'm working on a game in Java 3D and I'm implementing health bars that hover above units.

I started by drawing a quad at a 3D point above the unit's location and applying a Billboard behavior to make it always face the camera.

But the problem I'm stuck with is that the health bars are sometimes obscured by other scenery.

So I'm considering the following options:

  1. Overriding the Z / depth buffer value for the health bar pixels to make the renderer think they're closer to the camera than anything it renders afterwards.

    I tried renderingAttributes.setDepthTestFunction(RenderingAttributes.ALWAYS). While it makes the renderer draw the health bar on top of anything it drew in the same area earlier, it doesn't help when the other scenery is drawn on top of the health bar later.

    Is there a better way for doing this in Java 3D?

  2. Projecting the 3D locations of the health bars onto a 2D plane in front of the camera. Sounds doable, but before I set off reinventing all the math required for this, maybe someone can point out an existing solution.

  3. Switching from Java 3D to something like LWJGL or jMonkeyEngine (not just for this issue, but general complaints about Java 3D being dead, etc). Although I'm not even sure whether they're more flexible for this particular problem. And from what I've read, one of the worst mistakes in game dev is switching the engine in mid-development.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2024-10-12 08:00:42

使用画家算法你之后绘制生命条我们已经绘制了场景的其余部分(当然,Z 测试已关闭)。

Use the painter's algorithm: draw the health bars after you've drawn the rest of the scene (and with Z testing turned off, of course).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文