简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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