Verlet Integration + Basic Stick Constraints. Now What?
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:
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.
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 = x2x1;
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]; }
}
}
}
The download doesn't work on my computer.
Mac OS X 10.3.9
Mac OS X 10.3.9
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)
You need the main SDL libs, and also SDL_image (I should have mentioned that in my post)
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.
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.
I looked at my search paths and they are only pointing to ($HOME)/Library/Frameworks. Maybe that is the problem.
That worked. Pretty fun stuff.
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 newerish 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 coolish 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.
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 newerish 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 coolish 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.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Verlet integration  Collision Handling  C++  utdiscant  2  3,983 
Dec 21, 2007 09:02 PM Last Post: utdiscant 

My craptacular interpretation of Jakobsen's verlet paper  Leisure Suit Lurie  6  4,301 
Aug 8, 2005 02:20 PM Last Post: reubert 

Quaternion constraints  Jesse  11  7,087 
Aug 17, 2004 06:56 AM Last Post: Byron 

Verlet Integration Demo  Jake  15  7,584 
Aug 11, 2004 08:15 AM Last Post: aarku 