X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fmain.c;h=51faaa0b915662481cd559b68eca957f1f966bb0;hb=92fb08c674a95e1b14de3dc21c718444be91aac5;hp=d2240e01f22d513991aa2ef92cd288e101584814;hpb=ee39e383f97259441df726c76cf26dcef7e9c054;p=cyberay diff --git a/src/main.c b/src/main.c index d2240e0..51faaa0 100644 --- a/src/main.c +++ b/src/main.c @@ -49,7 +49,7 @@ static unsigned int nextpow2(unsigned int x); static long start_time; static float cam_theta, cam_phi; -static cgm_vec3 cam_pos = {0, -1.6, 0}; +static cgm_vec3 cam_pos = {0, 1.6, 0}; static int mouse_x, mouse_y; static int bnstate[8]; @@ -73,8 +73,13 @@ static float tex_xform[16]; int main(int argc, char **argv) { glutInit(&argc, argv); - glutInitWindowSize(1280, 800); - glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + if(init_options(argc, argv) == -1) { + return 1; + } + + glutInitWindowSize(opt.width, opt.height); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("cyberay"); glutDisplayFunc(display); @@ -106,11 +111,6 @@ static int init(void) glEnable(GL_CULL_FACE); - /* - glEnable(GL_DEPTH_TEST); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - */ glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); @@ -156,19 +156,19 @@ static void update(void) vfwd += WALK_SPEED * dt; } if(inpstate[INP_RIGHT]) { - vright -= WALK_SPEED * dt; + vright += WALK_SPEED * dt; } if(inpstate[INP_LEFT]) { - vright += WALK_SPEED * dt; + vright -= WALK_SPEED * dt; } cam_pos.x += cos(cam_theta) * vright + sin(cam_theta) * vfwd; - cam_pos.z += sin(cam_theta) * vright - cos(cam_theta) * vfwd; + cam_pos.z += -sin(cam_theta) * vright + cos(cam_theta) * vfwd; cgm_midentity(view_xform); - cgm_mtranslate(view_xform, cam_pos.x, cam_pos.y, cam_pos.z); - cgm_mrotate_y(view_xform, cam_theta); cgm_mrotate_x(view_xform, cam_phi); + cgm_mrotate_y(view_xform, cam_theta); + cgm_mtranslate(view_xform, cam_pos.x, cam_pos.y, cam_pos.z); } static void display(void) @@ -181,25 +181,16 @@ static void display(void) glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); - glTexCoord2f(0, 0); + glTexCoord2f(0, 1); glVertex2f(-1, -1); - glTexCoord2f(1, 0); - glVertex2f(1, -1); glTexCoord2f(1, 1); + glVertex2f(1, -1); + glTexCoord2f(1, 0); glVertex2f(1, 1); - glTexCoord2f(0, 1); + glTexCoord2f(0, 0); glVertex2f(-1, 1); glEnd(); - /* - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(view_xform); - - draw_level(&lvl); - */ - glutSwapBuffers(); assert(glGetError() == GL_NO_ERROR); } @@ -212,14 +203,6 @@ static void idle(void) static void reshape(int x, int y) { glViewport(0, 0, x, y); - /* - float proj[16]; - - cgm_mperspective(proj, cgm_deg_to_rad(50.0f), (float)x / (float)y, 0.5, 500.0); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(proj); - */ if(x > tex_width || y > tex_height) { tex_width = nextpow2(x); @@ -284,8 +267,8 @@ static void motion(int x, int y) if(!(dx | dy)) return; if(bnstate[0]) { - cam_theta += dx * 0.01; - cam_phi += dy * 0.01; + cam_theta -= dx * 0.01; + cam_phi -= dy * 0.01; if(cam_phi < -M_PI) cam_phi = -M_PI; if(cam_phi > M_PI) cam_phi = M_PI;