简体   繁体   English

在Java 3D场景中绘制不明显的健康栏

[英]Drawing unobscured health bars in a Java 3D scene

So I'm working on a game in Java 3D and I'm implementing health bars that hover above units. 所以我正在开发一个Java 3D游戏,我正在实现在单位上方悬停的健康栏。

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. 我开始在设备位置上方的3D点处绘制四边形,并应用Billboard行为使其始终面向相机。

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. 覆盖健康条像素的Z /深度缓冲区值,使渲染器认为它们比之后呈现的任何内容更接近相机。

    I tried renderingAttributes.setDepthTestFunction(RenderingAttributes.ALWAYS) . 我尝试了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? 在Java 3D中有更好的方法吗?

  2. Projecting the 3D locations of the health bars onto a 2D plane in front of the camera. 将健康条的3D位置投影到相机前面的2D平面上。 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). 从Java 3D切换到类似LWJGL或jMonkeyEngine的东西(不仅仅是针对这个问题,还有关于Java 3D死机等的一般抱怨)。 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. 从我所看到的,游戏开发中最严重的错误之一是在开发中期切换引擎。

使用画家的算法 :在绘制场景的其余部分绘制健康栏(当然,关闭Z测试)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM