X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Fropesim%2Fsrc%2Fmain.c;h=6037509d2b779307b2d87d8cf19027129bc72e21;hb=900d333da3db0d117e815dc181b5d73c31efa455;hp=6345e45d25b2fd1f3b12f7de59f92453841ba239;hpb=42675cece161caf9c65b1c944df2df4b1aacec81;p=dosdemo diff --git a/tools/ropesim/src/main.c b/tools/ropesim/src/main.c index 6345e45..6037509 100644 --- a/tools/ropesim/src/main.c +++ b/tools/ropesim/src/main.c @@ -31,7 +31,7 @@ cgm_vec3 gmove; /*cgm_quat grot = {0, 0, 0, 1};*/ float grot_theta, grot_phi; float ginner_xform[16], gouter_xform[16]; -cgm_vec3 ganchor[4]; +cgm_vec3 ganchor[4], manchor[4]; cgm_vec3 dbgvec[4]; @@ -64,11 +64,11 @@ int main(int argc, char **argv) return 0; } -#define ROPE_MASSES 4 +#define ROPE_MASSES 10 #define ROPE_SPRINGS (ROPE_MASSES - 1) -#define ROPE_LEN 1.0f -#define ROPE_MASSES_MASS 0.1f -#define ROPE_K 80.0f +#define ROPE_LEN 0.8f +#define ROPE_MASSES_MASS 0.01f +#define ROPE_K 180.0f int init(void) { @@ -76,7 +76,7 @@ int init(void) static struct cmesh **meshes[] = {&mesh_suz, &mesh_gout, &mesh_gin}; static const float amb[] = {0.05, 0.05, 0.08, 1}; int i, j; - struct rsim_rope *rope, *ropes_tail; + struct rsim_rope *rope; glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); @@ -106,7 +106,13 @@ int init(void) } rsim_init(&rsim); - ropes_tail = 0; + rsim.damping = 0.3; + + if(!(rope = rsim_alloc_rope(ROPE_MASSES * 4))) { + fprintf(stderr, "failed to allocate rope\n"); + return -1; + } + rsim_add_rope(&rsim, rope); /* anchor points on the inner gimbal */ for(i=0; i<4; i++) { @@ -114,32 +120,27 @@ int init(void) ganchor[i].y = (float)((i & 2) - 1) * 1.5f; ganchor[i].z = 0; - /* create a rope hanging from the anchor point */ - if(!(rope = rsim_alloc_rope(ROPE_MASSES, ROPE_SPRINGS))) { - fprintf(stderr, "failed to allocate rope\n"); - return -1; - } + manchor[i] = ganchor[i]; + cgm_vscale(manchor + i, 0.32); + + + + manchor[i].y += 0.15; + for(j=0; jmasses[j].p = ganchor[i]; - rope->masses[j].p.y = ganchor[i].y - j * ROPE_LEN / ROPE_SPRINGS; - rope->masses[j].m = 0.1f; - - if(j < ROPE_SPRINGS) { - rope->springs[j].rest_len = ROPE_LEN / ROPE_SPRINGS; - rope->springs[j].k = ROPE_K; - rope->springs[j].mass[0] = rope->masses + j; - rope->springs[j].mass[1] = rope->masses + j + 1; - } - } - rsim_freeze_rope_mass(rope, rope->masses); /* freeze first mass */ + int midx = i * ROPE_MASSES + j; + struct rsim_mass *mass = rope->masses + midx; - if(!ropes_tail) { - rsim.ropes = ropes_tail = rope; - } else { - ropes_tail->next = rope; - ropes_tail = rope; + float t = (float)j / (float)(ROPE_MASSES - 1.0f); + cgm_vlerp(&mass->p, ganchor + i, manchor + i, t); + mass->m = ROPE_MASSES_MASS; + + if(j == 0) { + rsim_freeze_rope_mass(rope, rope->masses + i * ROPE_MASSES); /* freeze first mass */ + } else { + rsim_set_rope_spring(rope, midx, midx - 1, ROPE_K, RSIM_RLEN_DEFAULT); + } } - rope->next = 0; } return 0; @@ -179,9 +180,7 @@ void update(long tmsec, float dt) cgm_vmul_m4v3(&apt0, ginner_xform); dbgvec[i] = apt0; - rope->masses[0].p = apt0; - - rope = rope->next; + rope->masses[i * ROPE_MASSES].p = apt0; } rsim_step(&rsim, dt); @@ -199,7 +198,7 @@ void display(void) {0.5, 0.3, 0.2, 1}, {0.2, 0.3, 0.2, 1} }; - int i, count; + int i, j, count; long tmsec = glutGet(GLUT_ELAPSED_TIME) - start_msec; static long prev_tmsec; struct rsim_rope *rope; @@ -235,7 +234,7 @@ void display(void) cmesh_draw(mesh_gin); glPopMatrix(); - cmesh_draw(mesh_suz); + /*cmesh_draw(mesh_suz);*/ glPointSize(7); glBegin(GL_POINTS); @@ -251,10 +250,15 @@ void display(void) rope = rsim.ropes; while(rope) { - glBegin(GL_LINE_STRIP); + glBegin(GL_LINES); glColor3f(0.2, 1, 0.2); for(i=0; inum_masses; i++) { - glVertex3f(rope->masses[i].p.x, rope->masses[i].p.y, rope->masses[i].p.z); + for(j=i+1; jnum_masses; j++) { + if(rsim_have_spring(rope, i, j)) { + glVertex3f(rope->masses[i].p.x, rope->masses[i].p.y, rope->masses[i].p.z); + glVertex3f(rope->masses[j].p.x, rope->masses[j].p.y, rope->masses[j].p.z); + } + } } glEnd();