grid axes
[gba_blender] / src / main.c
index d5dc096..a519dc0 100644 (file)
@@ -38,6 +38,31 @@ extern unsigned char bgimg_pixels[];
 
 static int32_t cam_theta = 0x10000, cam_phi = -0x8000;
 
+static int show_obj = 1, show_del;
+
+#define AXIS0  0x10000
+#define AXIS1  0x80000
+
+static struct xvertex gridaxes[] = {
+       {AXIS0, 0, 0,   0, 0, 0, 92},
+       {AXIS1, 0, 0,   0, 0, 0, 92},
+       {-AXIS0, 0, 0,  0, 0, 0, 92},
+       {-AXIS1, 0, 0,  0, 0, 0, 92},
+       {0, 0, AXIS0,   0, 0, 0, 93},
+       {0, 0, AXIS1,   0, 0, 0, 93},
+       {0, 0, -AXIS0,  0, 0, 0, 93},
+       {0, 0, -AXIS1,  0, 0, 0, 93},
+
+       {0, 0, 0,               0, 0, 0, 92},
+       {AXIS1, 0, 0,   0, 0, 0, 92},
+       {0, 0, 0,               0, 0, 0, 92},
+       {-AXIS1, 0, 0,  0, 0, 0, 92},
+       {0, 0, 0,               0, 0, 0, 93},
+       {0, 0, AXIS1,   0, 0, 0, 93},
+       {0, 0, -0,              0, 0, 0, 93},
+       {0, 0, -AXIS1,  0, 0, 0, 93},
+};
+
 int main(void)
 {
        int i;
@@ -91,8 +116,38 @@ int main(void)
                xgl_translate(0, 0, 8 << 16);
                xgl_rotate_x(cam_phi);
                xgl_rotate_y(cam_theta);
-//             xgl_draw(XGL_QUADS, cube, sizeof cube / sizeof *cube);
-               xgl_draw(XGL_TRIANGLES, suzanne, sizeof suzanne / sizeof *suzanne);
+
+               if(show_obj) {
+                       if(cam_theta < X_PI) {
+                               xgl_draw(XGL_LINES, gridaxes + 2, 2);   /* -X */
+                       } else {
+                               xgl_draw(XGL_LINES, gridaxes, 2);               /* +X */
+                       }
+                       if(cam_theta < X_HPI || cam_theta > (3 * X_HPI)) {
+                               xgl_draw(XGL_LINES, gridaxes + 4, 2);   /* +Z */
+                       } else {
+                               xgl_draw(XGL_LINES, gridaxes + 6, 2);   /* -Z */
+                       }
+
+                       if(show_obj == 1) {
+                               xgl_draw(XGL_QUADS, cube, sizeof cube / sizeof *cube);
+                       } else {
+                               xgl_draw(XGL_TRIANGLES, suzanne, sizeof suzanne / sizeof *suzanne);
+                       }
+
+                       if(cam_theta < X_PI) {
+                               xgl_draw(XGL_LINES, gridaxes, 2);               /* +X */
+                       } else {
+                               xgl_draw(XGL_LINES, gridaxes + 2, 2);   /* -X */
+                       }
+                       if(cam_theta < X_HPI || cam_theta > (3 * X_HPI)) {
+                               xgl_draw(XGL_LINES, gridaxes + 6, 2);   /* -Z */
+                       } else {
+                               xgl_draw(XGL_LINES, gridaxes + 4, 2);   /* +Z */
+                       }
+               } else {
+                       xgl_draw(XGL_LINES, gridaxes + 8, 8);
+               }
 
                wait_vblank();
                present(backbuf);
@@ -115,8 +170,26 @@ static void handle_keys(void)
        }
        if(KEYPRESS(KEY_LEFT)) {
                cam_theta += 0x2000;
+               if(cam_theta > X_2PI) cam_theta -= X_2PI;
        }
        if(KEYPRESS(KEY_RIGHT)) {
                cam_theta -= 0x2000;
+               if(cam_theta < 0) cam_theta += X_2PI;
+       }
+       if(KEYPRESS(KEY_RT)) {
+               if(++show_obj > 2) show_obj = 0;
+       }
+       if(KEYPRESS(KEY_LT)) {
+               if(--show_obj < 0) show_obj = 2;
+       }
+
+       if(KEYPRESS(KEY_A)) {
+               show_del ^= 1;
+       }
+       if(KEYPRESS(KEY_B)) {
+               if(show_del) {
+                       show_obj = 0;
+                       show_del = 0;
+               }
        }
 }