向量到元球上最近的等值面点
我目前正在制作一款原型游戏,玩家可以沿着一组移动元球的等值面行走。我已经实现了沿着具有向前和向上向量的球体行走。为了将其扩展到元球,我需要能够查询任意点、到最近表面的方向以及到最近表面的距离,以便能够在我将玩家向前移动后将其快速拉回到表面向量。我可以通过对所有向量进行加权平均来计算方向,但如何获得距离?
我对元球使用等值面为 1 的 1 / (x*x + y*y + z*z) 函数,但我希望能有任何概括,以便我可以对其他形状使用相同的方法。
I'm currently making a prototype game where the player walks along the isosurface of a collection of moving metaballs. I've already implemented walking along a sphere with a forward and up vector. To extend this to the metaballs I need to be able to query for an arbitrary point the direction to the closest surface and the distance to the closest surface to be able to snap the player back to the surface after I've moved him along the forward vector. I can calculate the direction by taking a weighted average of all vectors but how do I get the distance?
I'm using the 1 / (x*x + y*y + z*z) function with an isosurface of 1 for my metaballs but I would appreciate any generalization so that I can use the same approach for other shapes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您只需导出函数即可获得表面的法线。 Blackpawn 在此处对如何针对您的具体情况进行了很好的解释。
一旦获得法线,就沿着其方向移动,直到到达等值面(这是通用的“根”发现)。
In general, you would just derive your function to get the normal on the surface. Blackpawn has a nice explanation how to do it with your specific case here.
Once you got the normal, move along its direction until you hit the isosurface (this is generic "root" finding).