added optcfg and fixed camera xform
[cyberay] / src / main.c
index d2240e0..51faaa0 100644 (file)
@@ -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;