4

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.

mjomble
  • 521
  • 3
  • 9
  • 20

1 Answers1

3

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

Gareth Rees
  • 64,967
  • 9
  • 133
  • 163
  • Looks like there is a way to do this in Java 3D using an OrderedGroup. However, this would introduce a maintenance problem. Currently, the easiest way to position the health bar above the unit is by putting it in the same TransformGroup as the unit. But if I need to separate all health bars from all other scenery, I'd need to split them at a higher level and then attempt to apply the same series of transformations to the health bars that are applied to the units. It's doable, but perhaps there's a more elegant solution. – mjomble Dec 03 '10 at 09:38