X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fmain.cc;h=ef26c3c4eaa117b91fbd0535952679dd6858e15b;hb=96407860f68887a2a4911c99095f54198da97549;hp=a23fcb54186a01118040a25894151672651f28ee;hpb=2c4aeaa83ca06d604c084f1fe146ee7f51e30f90;p=hair diff --git a/src/main.cc b/src/main.cc index a23fcb5..ef26c3c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -6,6 +6,8 @@ #include #include +#include + #include "mesh.h" #include "hair.h" @@ -17,8 +19,10 @@ static void cleanup(); static void display(); static void reshape(int x, int y); static void keydown(unsigned char key, int x, int y); +static void keyup(unsigned char key, int x, int y); static void mouse(int bn, int st, int x, int y); static void motion(int x, int y); +static void idle(); static std::vector meshes; static Mesh *mesh_head; @@ -26,6 +30,8 @@ static Hair hair; static int win_width, win_height; static float cam_theta, cam_phi = 25, cam_dist = 8; +static float head_rz, head_rx; /* rot angles x, z axis */ +static Mat4 head_xform; int main(int argc, char **argv) { @@ -34,11 +40,16 @@ int main(int argc, char **argv) glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("hair test"); + /* for the keydown, keyup functions to work */ + glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF); + glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keydown); + glutKeyboardUpFunc(keyup); glutMouseFunc(mouse); glutMotionFunc(motion); + glutIdleFunc(idle); if(!init()) { return 1; @@ -111,12 +122,18 @@ static void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + head_xform = Mat4::identity; + head_xform.rotate_x(gph::deg_to_rad(head_rx)); + head_xform.rotate_z(-gph::deg_to_rad(head_rz)); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -cam_dist); glRotatef(cam_phi, 1, 0, 0); glRotatef(cam_theta, 0, 1, 0); + glMultMatrixf(head_xform[0]); + for(size_t i=0; idraw(); } @@ -138,11 +155,30 @@ static void reshape(int x, int y) gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0); } +static bool hpressed; static void keydown(unsigned char key, int /*x*/, int /*y*/) { switch(key) { + case 'h': + case 'H': + hpressed = true; + break; case 27: exit(0); + default: + break; + } +} + +static void keyup(unsigned char key, int /*x*/, int /*y*/) +{ + switch(key) { + case 'h': + case 'H': + hpressed = false; + break; + default: + break; } } @@ -165,17 +201,34 @@ static void motion(int x, int y) if(!dx && !dy) return; - if(bnstate[0]) { - cam_theta += dx * 0.5; - cam_phi += dy * 0.5; + if(hpressed) { + if(bnstate[0]) { + head_rz += dx * 0.5; + head_rx += dy * 0.5; - if(cam_phi < -90) cam_phi = -90; - if(cam_phi > 90) cam_phi = 90; - glutPostRedisplay(); + if(head_rx < -45) head_rx = -45; + if(head_rx > 45) head_rx = 45; + + if(head_rz < -90) head_rz = -90; + if(head_rz > 90) head_rx = 90; + } } - if(bnstate[2]) { - cam_dist += dy * 0.1; - if(cam_dist < 0) cam_dist = 0; - glutPostRedisplay(); + 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) cam_dist = 0; + } } } + +static void idle() +{ + glutPostRedisplay(); +}