开发者

Drawing unobscured health bars in a Java 3D scene

开发者 https://www.devze.com 2023-01-28 07:00 出处:网络
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 t

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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消