Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

deryk

theory behind metaballs?

This topic is 5612 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

while waiting for a response to my metaball help post in another forum, i thought i''d confirm my ideas regarding the theories behind metaball construction. so, can anyone explain to me the theory behind their construction? in English please, heheh. a lot of other tutorials out there explain things a little too deep. i''d really like to learn the concept from the ground up so i can create my own implementation of the algorithm, since a lot of the sample programs out there are pretty complex without gaining a very firm grasp of the concept. thanks! i''m gonna use these concepts to create a liquid metal type demo.

Share this post


Link to post
Share on other sites
Advertisement
Didn´t read the links posted by the others but since you said that most tutorial are too much into detail i´ll give you a short summary of the marching cubes algorithm (what I think is what you are talking about):

what you want to do is displaying a certain isolevel r0 of a function r = f(x,y,z). This function should have a first derivative. In the case of metaballs the function will be something like the potential of a number of mass-points but it can be any other function (there are a lot of nice objects shown on Paul Bourkes homepage).

To display the isolevel (which should be a surface) you split up an area that you know to contain the whole isolevel into several uniform geometric objects. Easiest thing to explain here is splitting it up into cubes. Then, for each frame you check each cube:

A cube has 8 edges. For each edge n you check if rn = f(xn, yn, zn) is bigger or smaller than r0. Since each value can be bigger or smaller than r0 (2 possibilities, neglegt equality here) and there are 2^8 = 256 possible combinations that can occur. All values above/below r0 is trivial. Every other case indicates that your cube is intersected by the surface.
In this case you draw triangles accordingly.
This point will propably be where the articles go into detail so I´ll skip this here. I´ll just say that the triangles vertices are usually determined by using linear interpolation between the edges because it´s the fastest way of doing so.

If you got any special questions about the marching cubes feel free to ask, I like talking about that topic

Share this post


Link to post
Share on other sites
okay guys, i''ve done some research. let''s start with creating just a basic sphere using an equation.

apparently, according to http://www.dev-gallery.com/programming/opengl/water_drops/main.htm, the formula for creating a perfect isosurface sphere is:

F(x,y,z) = x^2 + y^2 + z^2 + C.

now, my question is, how do i implement this formula in an openGL program? first of all, is the formula correct?

if i create a function containing the above formula, returning its result to a drawing function defined later on, what does it return? a vertex(meaning i have to loop over and over again), or complete sphere? what i''m trying to do is generate a complete sphere model only, using the above formula. if i can get this to run first, then i''ll get on with the physics involved later.

as you can see, i''m not very much of a math wiz. in fact, it''s one of my weaker areas. but i love the graphics, so i''m willing to learn.

thanks everybody.

Share this post


Link to post
Share on other sites
I dont know much about OGL, but I know all about meta-objects and such, so I think I can help a little. What that formula tells you (your formula is correct) is whether point A is inside or outside of the surface. With OpenGL, I assume, you work with mesh structures..? So what you need to do is scan the volume (march through your cubes) and determine which discrete lattice points are on the surface (or very nearly on). After you march through your cubes, you will have a set of points that are on the surface. These points must be correctly connected. In reality, you will not produce points one by one, but faces of the object one by one. This is about where the tutorials can take over...

This is the basic idea; the tutorials do a much better job of explaining how to actually produce the faces than I can right now.

Share this post


Link to post
Share on other sites
so it''s not possible to just create a sphere via that formula?

plus i have the problem of the searching algorithm too(marching through the cubes), so i''m trying to start with basic generation of the sphere first.

can anyone tell me how to do that?

sorry, but dumb-ass math guy here..

Share this post


Link to post
Share on other sites
No offense, but you can''t just shove OGL a formula of a sphere and expect it to draw a sphere for you.
OGL expects triangles, (or quads?) so you have to create triangles to _represent_ a sphere.

kind rgds,
Nik

Share this post


Link to post
Share on other sites
yup i know

...which is why i''m asking for help on how to represent the sphere. from the research i do while waiting for responses here, i know that surfaces are generated after determining which points on a 3-dimensional grid of cubes are inside and outside a figure, thus formed by trianges and/or quads.

what bugs me though is how to tell GL, for example, that a sphere occupies this many cubes, since i have to know which vertices are inside or outside a sphere, and from there, connected the vertices on the outside to produce a surface.

as vanillacoke said, i currently have the formula to tell whether a point is inside a figure or not. my question for now is, how do i implement the formula? from where do i get the x, y, and z parameters that go in function F(x,y,z)?

thanks for the replies everyone.

Share this post


Link to post
Share on other sites

#define GRIDROOT 16
#define CELLSIZE (1/GRIDROOT)

for (x=0;x<GRIDROOT;x++)
for (y=0;y<GRIDROOT;y++)
for (z=0;z<GRIDROOT;z++)
{
//3d space here;

//evaluate some function on x,y,z


}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!