## Verlet Integration + Basic Stick Constraints. Now What?

Apprentice
Posts: 18
Joined: 2005.08
Post: #1
I'll admit, I'm a bit of a beginner when it comes to game development. I've been a web developer for a number of years now, but I have never really touched C++, OpenGL or anything serious.

I got a couple of test SDL applications working last week, so this weekend I decided to sit down and give myself a little primer on C++. I figured getting a little [url= http://www.gamasutra.com/resource_guide/...obsenesque[/url] simulation up and running would be a good place to start.

JJC Verlet Ragdoll Sim ** SDL Libs required.
I've been having a lot of fun beating the crap out of this little guy.

Anyway, I followed the paper to the best of my ability, and I am pretty impressed with how it turned out. One thing I couldn't figure out was how to implement the inequality and angle constraints described in the last part of the paper.

Could anyone give me some pointers on how to proceed, or something cool to try? Can I make my figure move a little more realistically by adding constraints beyond the simple sticks I have now?

Here's my functions, nothing new to see:
Code:
```void Particle::Verlet (float dt) {   for (int i=0;i<kNumParticles;i++) {     Vector temp = position[i];     position[i] += position[i] - position_old[i] + acceleration[i] * dt * dt;     position_old[i] = temp;   } } void Particle::SatisfyConstraints(float dt)  {   for (int j=0;j<kNumIterations;j++) {     for (int i=0;i<kNumParticles;i++) {       Vector& x = position[i];       if (x.x < -512.0) { x.x = -512.0;  }    //x = vmin(vmax(x, Vector(0,0,0)), Vector(1000,1000,1000));       if (x.x > 512.0)  { x.x = 512.0;   }       if (x.y > 300.0)  { x.y = 300.0;  }       // if (x.y < -290.0) { x.y = -290.0;  }     }          // Then satisfy (C2)     for(int i=0; i<kNumConstraints; i++) {       Constraint& c = m_constraints[i];       Vector& x1 = position[c.particleA];       Vector& x2 = position[c.particleB];            Vector delta = x2-x1;       delta*=c.restlength*c.restlength/(delta*delta+c.restlength*c.restlength)-0.5;       x1 -= delta;       x2 += delta;     }          // Constrain anchors     for (int i=0;i<kNumParticles;i++) {       if (m_anchored[i])  { position[i] = position_old[i]; }     }   } }```
Justin, I was having a heck of a time trying to figure out how to do a text routine in OpenGL, so I ripped your font texture from KDC (along with the GLprint function). I hope that's OK.
Sage
Posts: 1,066
Joined: 2004.07
Post: #2

Mac OS X 10.3.9
Apprentice
Posts: 18
Joined: 2005.08
Post: #3
Strange. I built it on 10.3.9. You have the SDL Libraries installed right? I couldn't figure out how to bundle them.

You need the main SDL libs, and also SDL_image (I should have mentioned that in my post)
Sage
Posts: 1,066
Joined: 2004.07
Post: #4
I just updated my SDL libs to the newest ones earlier today. Could that ruin the compatibility? I do have SDL_image as well. Where do you have the SDL libs on your computer? Maybe yours are in a different folder than mine are. Mine are in Hard Drive:Library:Frameworks.
Apprentice
Posts: 18
Joined: 2005.08
Post: #5
I wouldn't imagine that would break the compatibility. Hmm, maybe I just don't know how to link things properly. Everything seems to be in order though... I just cleaned and rebuilt after tweaking a couple of settings. Try it once more: I uploaded it again.
Apprentice
Posts: 18
Joined: 2005.08
Post: #6
I looked at my search paths and they are only pointing to (\$HOME)/Library/Frameworks. Maybe that is the problem.
Sage
Posts: 1,066
Joined: 2004.07
Post: #7
That worked. Pretty fun stuff.
Sage
Posts: 1,487
Joined: 2002.09
Post: #8
First off, SPK is a little physics library I wrote back a year or two ago. It's really not all that good looking back at it, but you might be able to learn something from it. It's fairly well commented.

Adding min/max distance constraints is a good and really easy way to add some fancier constraints to you models. Easier to implement than angular constraints, but almost as good and much faster.

For angular constraints you find what angle two segments are at and apply a tangential (perpendicular to the stick direction) push on the two end point particles. Couple that with a pair of distance constraints and you have an arm. I had a simple example working at one point, but SPK had pretty much died by then so I never added it. I could dig around for it if you are interested at all. (no promises)

I'm also writing a newer-ish rigid body library based on this paper. Be warned, the math is really a doosey in that one though. Jakobsen physics are beautiful for their simplicity. I *hope* to have a cool-ish demo of that out soon.

There's also this paper that talks about fancier Jakobsen physics. It uses a lot of quaternion math that is useless and hard to decode if all you want is 2D though.