I need some help with finding a good way to do the following:
I’m doing a project in which I want to simulate sort of a timelapse of a drug tablet dissolving.
It doesn’t have to take any chemical reactions into account, the tablet just needs to grow smaller over time and pieces falling off shouldn’t necessarily be visible.
The drug tablet is made out of 3 cylinders stacked on top of each other. The first and the last cylinder dissolve the fastest and should get a rounder and rougher surface overtime.

I’ve made the cylinders using Quadrics but now I’m kind off stuck with trying to create a changing surface and the cylinder getting rounder (on the top) at the same time. What would be a good way to do that?

For the shape changing to look smooth you need a highly tesselated model (ie lots of triangles). You could look at a shader that morphs from one shape to another.This is most easily done if the 2 models have the same number of vertices.
The harder part is having it disappear altogether. If the second (or last if you do a couple of morph steps) is small enough you may be able to fade the texture alpha value to 0.

You can get a feel if this approach would work using a 3d package - they all support morphing over time and most support texture chaning over time.

Once you get it to work you could add some fluff with a partical shader showing the bits breaking off as it dissolves:)

Well it’s not that I’m not a programmer, it’s just that I’m fairly new to opengl and haven’t made use of shaders yet. I’m still learning, but that was part of the assignment.

Okay, so the first problem is: how would I create/calculate a cylinder made out of vertices? I can’t morph from a gluCylinder which doesn’t have any vertices right?

gluCylinder does have vertices but there isn’t an easy way to get the vertices.

You could get the source code (mesa3d.org has it along with the mesa opengl implementation)

Use a 3rd party library

Calculate it yourself. It is rather simple and looks something like this
x = cos(angle);
y = sin(angle);
z = whatever you want.
because that is used to generate a circle.

If you can’t even create your own cylinder, how are you going to simulate a tablet dissolving in water?
I don’t mean to discourage you but you have a long road ahead of you.

[QUOTE=V-man;1249195]
If you can’t even create your own cylinder, how are you going to simulate a tablet dissolving in water?
I don’t mean to discourage you but you have a long road ahead of you.[/QUOTE]

You are right, this will be a long project and I still have some months, but I might have been getting ahead of myself by getting straight to what was needed to get some results without having a solid base of OpenGL. I did some tutorials but clearly that wasn’t enough, I have started reading some books hopefully this will get me further.

Your help is greatly appreciated anyways!
I will post back when I have some decent results.

I wasn’t but have started reading, seems like a good book, thanks!

So in the mean time I’ve started on the cylinders, by making 2 triangles (and trianglefans for the top and bottom) as you said, but encountered some problems with my normal values which I’ve calculated like this (it’s in ruby but that doesn’t really matter I think):

def ReduceToUnit(vector)
# Calculate the length of the vector
length = Math.sqrt((vector[0]*vector[0]) + (vector[1]*vector[1]) + (vector[2]*vector[2]))
if(length == 0.0)
length = 1.0
end
vector[0] /= length
vector[1] /= length
vector[2] /= length
return (vector)
end

[QUOTE=tonyo_au;1249345]The normal at point p(x,y,z) on the outside of the cylinder is

normal(xyz) = normalize(p(x,y,z)-center(0,y,0)) // assume cylinder is vertical along the y-axis

[/QUOTE]

Thanks!

Okay so I’ve been reading alot lately but I think I don’t have enough information to calculate the vertices of the highly tesselated (in between) objects to morph too. I do have a gradient which tells me how fast the particles (= molecules) inside the cylinder dissolve (the outer particles of the cylinder dissolve slower than the ones in the center of the cylinder). Would it be possible to calculate where the vertices move too over time out of gradient information?

I was thinking that if I’d fill up the cylinder with cubes, or different polygons, I could make the outer ones fade into the background color over a certain amount of time (gradient) and work my way into the cylinder like this until the whole cylinder has disappeared. Would that still look somewhat smooth?

Which one of these two solutions to the problem would be the easiest?