• Create Account

RubyNL

Member Since 13 Jun 2007
Offline Last Active Jul 07 2012 05:40 PM

Rope/cloth simulation problems

23 June 2012 - 02:06 PM

Hello, for a course in 3-dimensional modelling, I have to program a rope simulation, and, extending that code, a cloth simulation.
I'm having some troubles though. First I had a shot at an Eulerian sping mass-model, like described on Hugo Elias' site. It was either way too elastic, or way too 'jumpy' (numerically instable, everything exploded after a few seconds, especially if I attached a node to the mouse so I could test the reaction on mouse movements).
Then I read some more articles about rope simulation, the most important being Advanced Character Physics (html | pdf) by Thomas Jakobsen. He suggested using Verlet Integration. I use a fixed timestep (I use dt = 1 in my code), so the Verlet Integration basically comes down to storing the last position of each node/particle instead of storing it's speed (at least, that's what I think, I could be missing something), so initially this had no effect on the instability.
But then I read about constraint relaxation. Constraint relaxation basically means you 'satisfy' each constraint, one at a time, while not caring about the effect this has on the other constraints. Then you repeat this process a few times, and you end up with an approximation of a system where all constraints would be satisfied.

I have 75 nodes/particles, and I have set the 'sticks' between them to be of a length of 3 pixels (this is the only constaint I'm using, but since I'm doing this for 75 particles, it are in fact 74 constraints which all invalidate each other to some degree). For example, if you have three nodes on a horizontal line with each 100 pixels between them, we have two constraints (the first being that node 1 and node 2 must be 3 pixels apart, and the second that node 2 and node 3 must be 3 pixels apart). Satisfying the first constraint (node 1 and node 2 must be 3 pixels apart) will move node 1 48.5 (=(100-3)/2) to the right and node 2 48.5 pixels to the left. The distance from node 2 to node 3 will then increase to 148.5, but my code uses the old position (which is in memory because I use Verlet Integration) to calculate the distance between two nodes, so the distance between node 2 and node 3 can be regarded as 100 pixels. Then the satisfaction of the second constraint will increase the horizontal position of the second node with 48.5 pixels again, (basically undo-ing the displacement what we did to satisfy the first constraint) and move the third node 48.5 pixels to the left.

In practice, this method should converge to a 'solution', satisfying all the constraints, but I fear it might converge too slow.

Here is what I have so far:

It looks pretty good (especially when you consider that I don't use any 'flexion' springs, which connect nodes that are separated by another node between them), but in this example I have 75 particles, each attached to 1 or 2 'springs'. I run the part of the code where I satisfy each constraint 500 times, and I'm fairly sure this is way too much to be of practical use in a cloth simulation. Further, I still have some 'springyness', even when I use 500 iterations. I'm afraid this springyness will be a much bigger problem in a cloth simulation (because there are many more points, so the mass is much higher). If I use 100 iterations, the rope is much more elastic already.

So, I'm confused about the spring-mass model, I couldn't get it working in a satisfying way. Am I on the right track to go on with cloth simulation or am I doing something structurally wrong?

Also, in the practicum description it states that you should use Hooke's law (F=-kx where x is the displacement from the rest length of the spring, and k is some positive spring constant). I am not using this equation explicitly, but the constraint relaxation has the same behaviour, so I guess that's fine. But the description also states that you should use a maximum length for the distance between the nodes, which really confuses me, because this is exactly what I'm doing with the constraint relaxation, but this results in spring-like behaviour where the rope still is elastic (the distance between ). I don't know how to set a 'hard' maximum for the distance between two nodes.
Suppose I could get an Eulerian system working nicely, I wouldn't know how this implement such a hard border either...

Sorry for the long post, it thought it was kind of hard to explain clearly what I'm doing and what's the problem!

ball-curve intersections

01 September 2010 - 10:20 AM

I plan on writing a simple bouncing-ball-engine where multiple balls bounce off the environment and each other. No problem if the environment is made of lines. But I want something smoother. Bezier curves for example. I looked up on bezier curves and found that it isn't possible - or at least not easy enough to implement - to calculate the intersection between a moving ball and a bezier curve.
Then I figured out that if I could find intersection between a moving ball and a parabola I could 'add' a coordinate system for each parabola and in that way rotate and scale the parabola. It turned out too hard for me too...
Is there any type of curve that is commonly used in this kind of engines?
Btw, I have some kind of fetisj for exact calculations so if there is any exact solution I would prefer it.
But all help and every comment is welcome of course.

3d rotations

29 July 2010 - 01:10 AM

I am trying to make a simple program where the use can change the orientation of a sphere (the source is in qbasic and uncommented, I am learning java but I still prefer qbasic for these small graphical kind of things, if somebody wants it I can post it). This is done by clicking in a circle.
The program tries to rotate the sphere, so that the center of the texture of the sphere is at the point the user clicked.
First I calculate where the point in 3d should be, by making a vector that points to it:
vx = (clickedx - centerx) / radius
vy = (clickedx - centerx) / radius
vz = sqrt(1 - vx * vx - vy * vy)

then I resolved the yaw and roll of the vector and then applied that as a xyz rotation matrix. That worked if you only rotated the sphere on the horizontal axis or only on the vertical, but if you clicked off both axes, the center of the texture and the vector don't lock together.

Can somebody help me with this? I want to use Euler angles, maybe they are the problem. But I'm using only two axes, that shouldn't be a problem right?

Raytracing algorithm optimization

19 February 2010 - 11:43 PM

I am interested in raytracing, and I'm currently trying to do some raytracing on a low resolution. I know that most realtime raytracers use subsampling and possibly other tricks to speed things up. I also read an article in hugi nr 23, by lycium, thats says that the raytracing algorithm can be speeded up with: First hit optimization Shadow check optimization Pre-calculate per-frame constants And it says that you must not use a general quadratic intersector to intersect a sphere. Can somebody explain these concepts to me, because I don't understand them and there is no source code attached.

Software accelerated sphere mapping

13 November 2007 - 07:44 AM

I want to map a texture onto a sphere. I used to do this by dividing the x and y coordinates by the depth of the sphere(I calculated that with: x ^ 2 + y ^ 2 + z ^ 2 = r ^ 2), so I did: (rewrite formula to get formula for z)
```x ^ 2 + y ^ 2 + z ^ 2 = r ^ 2
- r ^ 2
x ^ 2 + y ^ 2 + z ^ 2 - r ^ 2 = 0
- z ^ 2
x ^ 2 + y ^ 2 - r ^ 2 = -(z ^ 2)
* -1
-(x ^ 2 + y ^ 2 - r ^ 2) = z ^ 2
Squareroot
z = SQR(-(x ^ 2 + y ^ 2 - r ^ 2))
```
Qbasic code (not the full prog, though I could give that too if you want it):
```square = -(x ^ 2 + y ^ 2 - r ^ 2)
IF square >= 0 THEN
z = SQR(square)
u = x / (z / r)
v = y / (z / r)
END IF
```
And that gave me reasonable results. But, I can't render the inside of a sphere, and I would like to do that. BTW, sorry if you don't understand what I'm doing or why I don't use OpenGL etc. I'm just a very oldskool coder I guess :P. I do everything sofware accelerated. Anyway, I would like a manner to map a texture onto a sphere so that you can see the inside of a sphere too. Thanks, RubyNL

PARTNERS