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.
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).
精彩评论