在 Java 3D 场景中绘制清晰的生命条
因此,我正在使用 Java 3D 开发一款游戏,并且正在实现悬停在单位上方的生命条。
我首先在设备位置上方的 3D 点处绘制一个四边形,并应用 Billboard 行为使其始终面向相机。
但我遇到的问题是,生命条有时会被其他风景遮挡。
因此,我正在考虑以下选项:
覆盖生命条像素的 Z/深度缓冲区值,以使渲染器认为它们比之后渲染的任何内容都更接近相机。
我尝试了
renderingAttributes.setDepthTestFunction(RenderingAttributes.ALWAYS)
。虽然它使渲染器将生命条绘制在之前在同一区域绘制的任何内容的顶部,但当稍后将其他风景绘制在生命条顶部时,它没有帮助。在 Java 3D 中是否有更好的方法来执行此操作?
将生命条的 3D 位置投影到相机前面的 2D 平面上。听起来可行,但在我开始重新发明所需的所有数学之前,也许有人可以指出现有的解决方案。
从 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:
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?
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用画家算法:在你之后绘制生命条我们已经绘制了场景的其余部分(当然,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).