megabassjosh
2005.08.29, 01:48 PM
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 Jakobsenesque ( http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtml) simulation up and running would be a good place to start.
JJC Verlet Ragdoll Sim (http://www.joshuacender.com/download/JJC%20Verlet%20Ragdoll%20Sim.zip) ** 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:
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.
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 Jakobsenesque ( http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtml) simulation up and running would be a good place to start.
JJC Verlet Ragdoll Sim (http://www.joshuacender.com/download/JJC%20Verlet%20Ragdoll%20Sim.zip) ** 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:
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.