X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=tools%2Fropesim%2Fsrc%2Fmain.c;h=90bccdfad8ac9a90685742e54e21f4c49f42ec2c;hp=dcabef5a2e5b8f69b861e4490b1aa238eb8cf796;hb=91571f90a9120404bc40a868a66d91ce4ce29580;hpb=be72aee3c4a0a5516bdccf06c5419efe3e026ee4 diff --git a/tools/ropesim/src/main.c b/tools/ropesim/src/main.c index dcabef5..90bccdf 100644 --- a/tools/ropesim/src/main.c +++ b/tools/ropesim/src/main.c @@ -2,6 +2,7 @@ #include #include #include "cmesh.h" +#include "cgmath/cgmath.h" int init(void); void cleanup(void); @@ -18,13 +19,25 @@ void sball_button(int bn, int st); float cam_theta, cam_phi, cam_dist = 10; int prev_mx, prev_my; int bnstate[8]; +int modkeys; + +long start_msec; struct cmesh *scn; +struct cmesh *mesh_gout, *mesh_gin, *mesh_suz; + +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 dbgvec[4]; int main(int argc, char **argv) { glutInit(&argc, argv); - glutInitWindowSize(800, 600); + glutInitWindowSize(1280, 800); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("ropesim"); @@ -43,6 +56,7 @@ int main(int argc, char **argv) } atexit(cleanup); + start_msec = glutGet(GLUT_ELAPSED_TIME); glutMainLoop(); return 0; } @@ -50,7 +64,10 @@ int main(int argc, char **argv) int init(void) { - float amb[] = {0.05, 0.05, 0.08, 1}; + static const char *meshnames[] = {"suzanne", "gimbal_outer", "gimbal_inner"}; + static struct cmesh **meshes[] = {&mesh_suz, &mesh_gout, &mesh_gin}; + static const float amb[] = {0.05, 0.05, 0.08, 1}; + int i; glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); @@ -65,14 +82,63 @@ int init(void) fprintf(stderr, "failed to load scene file\n"); return -1; } + + for(i=0; i 90) cam_phi = 90; - } + if(modkeys) { + if(bnstate[0]) { + grot_theta += dx * 0.5; + grot_phi += dy * 0.5; + } + } else { + if(bnstate[0]) { + cam_theta += dx * 0.5; + cam_phi += dy * 0.5; + if(cam_phi < -90) cam_phi = -90; + if(cam_phi > 90) cam_phi = 90; + } - if(bnstate[2]) { - cam_dist += dy * 0.1; - if(cam_dist < 0.0f) cam_dist = 0.0f; + if(bnstate[2]) { + cam_dist += dy * 0.1; + if(cam_dist < 0.0f) cam_dist = 0.0f; + } } } void sball_motion(int x, int y, int z) { + gmove.x += x * 0.001f; + gmove.y += y * 0.001f; + gmove.z -= z * 0.001f; } -void sball_rotate(int rx, int ry, int rz) +void sball_rotate(int x, int y, int z) { + /* + float axis_len, s; + axis_len = (float)sqrt(x * x + y * y + z * z); + s = axis_len == 0.0f ? 1.0f : 1.0f / axis_len; + cgm_qrotate(&grot, axis_len * 0.001f, -x * s, -y * s, z * s); + */ + + grot_theta += y * 0.03f; + grot_phi += x * 0.03f; } void sball_button(int bn, int st) { + if(st == GLUT_DOWN) { + /*cgm_qcons(&grot, 0, 0, 0, 1);*/ + grot_theta = grot_phi = 0.0f; + cgm_vcons(&gmove, 0, 0, 0); + } }