使用 openAL 禁用环绕声

发布于 2024-11-13 09:14:10 字数 356 浏览 2 评论 0原文

我是法国人,很抱歉我的英语。

我目前正在使用 LWJGL 制作分屏 2D 游戏。 我正在使用 LWJGL 提供的 openAL API。一切似乎都很完美。嗯,说实话,太完美了:因为我正在制作分屏游戏,并且因为我不能让 2 个听众共享相同的上下文,所以我想摆脱左/右平移。

声音衰减效果很好。我根据最近的玩家改变声音的位置。 监听器不会改变,始终位于 (0,0,0)。声音位置是(soundPosition -closestPlayerPosition)。

那么我该如何摆脱周围的东西呢?当然,我希望保持声音随着距离的衰减。 我可以简单地将声音根据距离放在 Z 轴上,但这看起来有点愚蠢(每次更新声音位置时我都必须计算距离)。

谢谢 !

I'm french so sorry for my english.

I'm currently making a splitscreen 2D game with LWJGL.
I'm using the openAL API which is given with LWJGL. Everything seems to works perfectly. Well, too perfectly to be honest : because I'm making a splitscreen game and because I can't have 2 listener sharing the same context, I want to get rid of the left/right panning.

Sound attenuation work well. I change the position of sound depending on the closest player.
The listener doesn't change, always at (0,0,0). The sound position is (soundPosition - closestPlayerPosition).

So how do I get rid of the surround thing ? I want to keep sound attenuation over distance, of course.
I could simply put the sound on the Z-axis depending on the distance but this seem a bit silly (I have to compute the distance every time I have to update a sound position).

Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝礼 2024-11-20 09:14:10

当您计算声音的位置 (soundPosition -closestPlayerPosition) 时,获取该位置返回的向量的长度,然后将该声音直接沿着 z 轴放置到距玩家一定距离的位置。

示例:

声音位置 = (1.4,0,1.4)
closePlayerPosition = (0,0,0)

soundDirection = soundPosition -closestPlayerPosition = (1.4,0,1.4)

soundDistance = soundDirection.Length()

最后,声音的最终位置:

FinalSoundPosition = (0,0,soundDistance) = ( 0,0,2)

编辑:我没有注意到你已经建议了这个。说实话,我认为这很好,除了重写 openAL 内部的内容之外,这是解决问题的唯一方法

When you calculate the sound's position (soundPosition - closestPlayerPosition) take the length of the vector returned by that and then put that sound directly down the z axis that distance away from the player.

Example:

soundPosition = (1.4,0,1.4)
closestPlayerPosition = (0,0,0)

soundDirection = soundPosition - closestPlayerPosition = (1.4,0,1.4)

soundDistance = soundDirection.Length()

And finally, the final position of your sound:

finalSoundPosition = (0,0,soundDistance) = (0,0,2)

Edit: I didn't notice you already suggested this. To be honest I think this is fine, and its the only way to solve your problem beyond rewriting stuff internal to openAL

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文